Deep Learning 是基于一个数据的分析模型或是数据的分析方法。数据在足够大时,其分析或事更佳,数据更佳能分析出结果。如果收集的数据过于小或是数据收集小,这样训练出来的结果会让其出乎意料。我在此是针对于CNN模型,其实该模型不是说一定需要大量数据才可以得到结果,其涉及到您训练的模型-fine-tune,采集的数据是否够优质或是数据之间的区分度等。方法1:其实我们如果涉及到一个大类中的数据进行在此的分类时,我们可以进行拆解不一样区域而进行多模型的输出,最后进行一个综合判定,该方法自己在阅读RCNN、Faster-RCNN等论文的后感,具体自己会在MIT的bird数据集上进行测试和验证,具体后面来续写。方法2:还有一种方法是迁移学习模型,主要迁移imageNet数据集上的训练。该方法目前表现不错,自己也用于测试过在Category101上,基于ResNet50,基本在15epoch上其表现已经很好了。方法3:细小颗粒区分模型训练,其实也是正对其少量数据训练非常不错的,关注过近年来的论文,在细小颗粒上区分模型也是可以进行区分的,该方法目前还是需要完善。方法4: 适用Data Augment方法进行,图片的翻转等,实际我们都知道,图片实际是一个矩阵,我们实际就是将矩阵里数据部分变换了(所谓的翻转等)。自己在学习过程中需要扩充数据写了一个数据扩充的类:

def floatrange(start,stop,steps):return [start+float(i)*(stop-start)/(float(steps)-1) for i in range(steps)]class DataAugment:def __init__(self,path,shape,count=0,num1=150,num2=100,num3=100,num4=150,num5=100,num6=50,num7=200,num8=150):get_tensor=tf.gfile.FastGFile(path,'rb').read()self.image_data=tf.image.decode_jpeg(get_tensor)self.shape=shapeself.count=countself.num1 = num1self.num2 = num2self.num3 = num3self.num4 = num4self.num5 = num5self.num6 = num6self.num7 = num7self.num8 = num8def Save_image(self,name,x):x=tf.image.encode_jpeg(x)with tf.Session() as sess :sess.run(tf.global_variables_initializer())with tf.gfile.FastGFile(name,'wb') as save:save.write(x.eval())
#150 1def get_image_central(self):for i in floatrange(0.4,1.0,self.num1):self.count=self.count+1t=self.countname=dir+str(t)+'.jpg'contest=tf.image.central_crop(self.image_data,i)contest.set_shape(self.shape)with tf.Session() as sess:sess.run(tf.global_variables_initializer())self.Save_image(name,contest)#print ('1')
#100 2def get_image_random_tranpose(self):for i in range(self.num2):self.count=self.count+1t=self.countname=dir+str(t)+'.jpg'contest=tf.image.transpose_image(self.image_data)contest.set_shape(self.shape)with tf.Session() as sess:sess.run(tf.global_variables_initializer())self.Save_image(name,contest)#print ('2')
#100 3def get_image_up_down(self):for i in range(self.num3):self.count=self.count+1t=self.countname=dir+str(t)+'.jpg'contest=tf.image.random_flip_up_down(self.image_data)contest.set_shape(self.shape)with tf.Session() as sess:sess.run(tf.global_variables_initializer())self.Save_image(name,contest)#print('3')
#150 4def get_image_left_right(self):for i in range(self.num4):self.count=self.count+1t=self.countname=dir+str(t)+'.jpg'contest=tf.image.random_flip_left_right(self.image_data)contest.set_shape(self.shape)with tf.Session() as sess:sess.run(tf.global_variables_initializer())self.Save_image(name,contest)#print('4')
#100 5def get_image_bright(self):for i in floatrange(-0.6,0.6,self.num5):self.count=self.count+1t=self.countname=dir+str(t)+'.jpg'contest=tf.image.adjust_brightness(self.image_data,i)contest.set_shape(self.shape)with tf.Session() as sess:sess.run(tf.global_variables_initializer())self.Save_image(name,contest)#print('5')
#050 6def get_image_contrast(self):for i in range(self.num6):index=np.random.randint(-4,4)self.count=self.count+1t=self.countname=dir+str(t)+'.jpg'contest=tf.image.adjust_contrast(self.image_data,index)contest.set_shape(self.shape)with tf.Session() as sess:sess.run(tf.global_variables_initializer())self.Save_image(name,contest)#print ('6')#200 7def get_image_hue(self):for i in floatrange(0.0,0.5,self.num7):self.count=self.count+1t=self.countname=dir+str(t)+'.jpg'contest=tf.image.random_hue(self.image_data,i)contest.set_shape(self.shape)with tf.Session() as sess:sess.run(tf.global_variables_initializer())self.Save_image(name,contest)#print ('7')
#150 8def get_image_sation(self):for i in range(self.num8):index=np.random.randint(-6,10)self.count=self.count+1t=self.countname=dir+str(t)+'.jpg'contest=tf.image.adjust_saturation(self.image_data,index)contest.set_shape(self.shape)with tf.Session() as sess:sess.run(tf.global_variables_initializer())self.Save_image(name,contest)#print ('8')
#'1'def get_count(self):return self.countdef run(self):self.get_image_random_tranpose()self.get_image_left_right()self.get_image_central()self.get_image_bright()self.get_image_hue()self.get_image_contrast()self.get_image_sation()self.get_image_up_down()def run_1(self):#self.get_image_bright()self.get_image_random_tranpose()self.get_image_left_right()#self.get_image_contrast()#self.get_image_up_down()#self.get_image_central()#self.get_image_hue()self.get_image_hue()self.get_image_sation()#self.get_image_sation()def show(self):x=tf.image.encode_jpeg(self.image_data)with tf.Session() as sess:sess.run(tf.global_variables_initializer())plt.imread(x.eval())plt.show()def get_image_path(path):list_name = []if os.path.isdir(path):for file in os.listdir(path):if file.endswith('.jpg') and not file.startswith('.'):filename = path+'/'+filelist_name.append(filename)return list_name
def get_dir(dir):dirs = []if os.path.isdir(dir):for path in os.listdir(dir):paths = dir +'/'+pathif os.path.isdir(paths):dirs.append(paths)return dirs
def make_dirs(path):name = 'file'for i in range(250):names = path +name +str(i)if not os._exists(names):os.makedirs(names)

调用用例为:


if __name__=='__main__':test=DataAugment('/Users/josen/Desktop/001_0003.jpg',[64,64,3],0,2,2,2,2,2,2,2,2)test.run_1()t=test.get_count()print ('the final data is ',str(t))cout = 0path = '/Users/josen/Desktop/256_ObjectCategories/'+input('dir:')dir = input('file-path:')list_name = get_image_path(path)for i in range(len(list_name)):test = DataAugment(list_name[i],[64,64,3],cout,2,2,2,2,2,2,2,2)test.run_1()cout = test.get_count()print(cout)root = '/Users/josen/Desktop/Object256/'+input('file:--')#list_dir = get_dir(root)#print(len(list_dir))cout = 0#for i in range(len(list_dir)):list_name = get_image_path(root)#dir = list_dir[i] +'/'#nfor = list_name.split('/')[4].split('.')[0]for j in range(len(list_name)):test = DataAugment(list_name[j],[64,64,3],cout,2,2,2,2,2,2,2,2)test.run_1()cout = test.get_count()if cout == 650:breakprint(cout)

Data Augment ------TensorFlow 训练图片处理相关推荐

  1. 【tensorflow 深度学习】8.训练图片分类模型

    1.训练图片分类模型的三种方法 (1).从无到有,先确定好算法框架,准备好需要训练的数据集,从头开始训练,参数一开始也是初始化的随机值,一个批次一个批次地进行训练. (2).准备好已经训练好的模型,权 ...

  2. 完整实现利用tensorflow训练自己的图片数据集

    经过差不多一个礼拜的时间的学习,终于把完整的一个利用自己爬取的图片做训练数据集的卷积神经网络的实现(基于tensorflow) 目录 总体思路 第三部分:预处理 第四部分:网络模型 第五部分:训练 2 ...

  3. 使用PaddleFluid和TensorFlow训练序列标注模型

    专栏介绍:Paddle Fluid 是用来让用户像 PyTorch 和 Tensorflow Eager Execution 一样执行程序.在这些系统中,不再有模型这个概念,应用也不再包含一个用于描述 ...

  4. 使用PaddleFluid和TensorFlow训练RNN语言模型

    专栏介绍:Paddle Fluid 是用来让用户像 PyTorch 和 Tensorflow Eager Execution 一样执行程序.在这些系统中,不再有模型这个概念,应用也不再包含一个用于描述 ...

  5. 将tensorflow训练好的模型移植到Android (MNIST手写数字识别)

    将tensorflow训练好的模型移植到Android (MNIST手写数字识别) [尊重原创,转载请注明出处]https://blog.csdn.net/guyuealian/article/det ...

  6. [GAN学习系列3]采用深度学习和 TensorFlow 实现图片修复(下)

    这是本文的最后一部分内容了,前两部分内容的文章: [GAN学习系列3]采用深度学习和 TensorFlow 实现图片修复(上) [GAN学习系列3]采用深度学习和 TensorFlow 实现图片修复( ...

  7. [GAN学习系列3]采用深度学习和 TensorFlow 实现图片修复(中)

    上一篇文章–[GAN学习系列3]采用深度学习和 TensorFlow 实现图片修复(上)中,我们先介绍了对于图像修复的背景,需要利用什么信息来对缺失的区域进行修复,以及将图像当做概率分布采样的样本来看 ...

  8. C#使用公共语言拓展(CLE)调用Python3(使用TensorFlow训练的模型)

    对于Python2来说,使用IronPython可以方便的实现C#调用Python,但是对于特定需求,比如使用TensorFlow(最低支持Python3.5),就没办法使用IronPython了,为 ...

  9. 手把手教你使用TensorFlow训练出自己的模型

    手把手教你使用TensorFlow训练出自己的模型 一.前言 搭建TensorFlow开发环境一直是初学者头疼的问题,为了帮忙初学者快速使用TensorFlow框架训练出自己的模型,作者开发了一款基于 ...

最新文章

  1. 欠阿里云一分钱,会是什么样的后果...
  2. 笔记-计算机网络基础-5G
  3. 推荐搜索炼丹笔记:双塔模型在Airbnb搜索排名中的应用
  4. VTK:反射用法实战
  5. Vuex的store中的Module
  6. 云开发无需服务期无需域名壁纸小程序源码
  7. unsigned char bcd串乱码问题解决
  8. 使用ADD命令将目录复制到Docker的其他目录
  9. 最小 的浏览器 界面最精简 大小只有 压缩后只有7K 多
  10. 基本的核方法和径向基函数简介
  11. OLED屏幕的手机和LCD屏幕的手机,到底哪个好?
  12. html5 打字机效果,逼真的js打字机效果插件
  13. Erlang中的fun函数使用详解
  14. 【PBR系列一】PBR知识体系
  15. 爬虫学习笔记(用python爬取东方财富网实验)
  16. excel表格横向纵向变换_什么是报表工具?和 EXCEL 有什么区别?
  17. 讲讲React中的State和Props
  18. 中国各个省份的id代号是多少?各省简称是什么?
  19. FIFO原理及其应用
  20. mac系统双开应用(QQ、微信)

热门文章

  1. Apache Hue:Hue集成Hbase
  2. 18.企业信息化战略与实施
  3. Linux 安装仿宋字体
  4. Mysql实现排名及指定内容查询排名
  5. 在线轻松绘制配对连线箱线图
  6. 函数图像变换的规律,以一元函数和二元函数为例来说明,对多元函数同样适用。...
  7. Mongodb之(初出茅庐)
  8. 一文读懂CPU工作原理、程序是如何在单片机内执行的、指令格式之操作码地址码
  9. 爬取通过ajax动态加载的页面(实时监控华尔街见闻资讯与快讯)
  10. B2 - H - Historic Exhibition(二分图匹配+优化建图)