1. 在深度学习中,当数据量不够大时候,常常采用下面4中方法:

 (1)人工增加训练集的大小. 通过平移, 翻转, 加噪声等方法从已有数据中创造出一批"新"的数据.也就是Data Augmentation

(2)Regularization. 数据量比较小会导致模型过拟合, 使得训练误差很小而测试误差特别大. 通过在Loss Function 后面加上正则项可以抑制过拟合的产生. 缺点是引入了一个需要手动调整的hyper-parameter. 详见https://www.wikiwand.com/en/Regularization_(mathematics)

(3)Dropout. 这也是一种正则化手段. 不过跟以上不同的是它通过随机将部分神经元的输出置零来实现. 详见http://www.cs.toronto.edu/~hinton/absps/JMLRdropout.pdf

(4)Unsupervised Pre-training. 用Auto-Encoder或者RBM的卷积形式一层一层地做无监督预训练, 最后加上分类层做有监督的Fine-Tuning. 参考 http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.207.1102&rep=rep1&type=pdf

 
下面我们来讨论Data Augmentation:

不同的任务背景下, 我们可以通过图像的几何变换, 使用以下一种或多种组合数据增强变换来增加输入数据的量. 这里具体的方法都来自数字图像处理的内容, 相关的知识点介绍, 网上都有, 就不一一介绍了.

  • 旋转 | 反射变换(Rotation/reflection): 随机旋转图像一定角度; 改变图像内容的朝向;
  • 翻转变换(flip): 沿着水平或者垂直方向翻转图像;
  • 缩放变换(zoom): 按照一定的比例放大或者缩小图像;
  • 平移变换(shift): 在图像平面上对图像以一定方式进行平移; 
    可以采用随机或人为定义的方式指定平移范围和平移步长, 沿水平或竖直方向进行平移. 改变图像内容的位置;
  • 尺度变换(scale): 对图像按照指定的尺度因子, 进行放大或缩小; 或者参照SIFT特征提取思想, 利用指定的尺度因子对图像滤波构造尺度空间. 改变图像内容的大小或模糊程度;
  • 对比度变换(contrast): 在图像的HSV颜色空间,改变饱和度S和V亮度分量,保持色调H不变. 对每个像素的S和V分量进行指数运算(指数因子在0.25到4之间), 增加光照变化;
  • 噪声扰动(noise): 对图像的每个像素RGB进行随机扰动, 常用的噪声模式是椒盐噪声和高斯噪声;
  • 颜色变换(color): 在训练集像素值的RGB颜色空间进行PCA, 得到RGB空间的3个主方向向量,3个特征值, p1, p2, p3, λ1, λ2, λ3. 对每幅图像的每个像素Ixy=[IRxy,IGxy,IBxy]T进行加上如下的变化:

[p1,p2,p3][α1λ1,α2λ2,α3λ3]T

其中:αi是满足均值为0,方差为0.1的随机变量.

代码实现

作为实现部分, 这里介绍一下在python 环境下, 利用已有的开源代码库Keras作为实践:

 1 # -*- coding: utf-8 -*-
2 __author__ = 'Administrator'
3
4 # import packages
5 from keras.preprocessing.image import ImageDataGenerator, array_to_img, img_to_array, load_img
6
7 datagen = ImageDataGenerator(
8 rotation_range=0.2,
9 width_shift_range=0.2,
10 height_shift_range=0.2,
11 shear_range=0.2,
12 zoom_range=0.2,
13 horizontal_flip=True,
14 fill_mode='nearest')
15
16 img = load_img('C:\Users\Administrator\Desktop\dataA\lena.jpg') # this is a PIL image, please replace to your own file path
17 x = img_to_array(img) # this is a Numpy array with shape (3, 150, 150)
18 x = x.reshape((1,) + x.shape) # this is a Numpy array with shape (1, 3, 150, 150)
19
20 # the .flow() command below generates batches of randomly transformed images
21 # and saves the results to the `preview/` directory
22
23 i = 0
24 for batch in datagen.flow(x,
25 batch_size=1,
26 save_to_dir='C:\Users\Administrator\Desktop\dataA\pre',#生成后的图像保存路径
27 save_prefix='lena',
28 save_format='jpg'):
29 i += 1
30 if i > 20:
31 break # otherwise the generator would loop indefinitely

主要函数:ImageDataGenerator 实现了大多数上文中提到的图像几何变换方法.

  • rotation_range: 旋转范围, 随机旋转(0-180)度;
  • width_shift and height_shift: 随机沿着水平或者垂直方向,以图像的长宽小部分百分比为变化范围进行平移;
  • rescale: 对图像按照指定的尺度因子, 进行放大或缩小, 设置值在0 - 1之间,通常为1 / 255;
  • shear_range: 水平或垂直投影变换, 参考这里 https://keras.io/preprocessing/image/
  • zoom_range: 按比例随机缩放图像尺寸;
  • horizontal_flip: 水平翻转图像;
  • fill_mode: 填充像素, 出现在旋转或平移之后.

主要函数:ImageDataGenerator 实现了大多数上文中提到的图像几何变换方法.函数原型如下

 keras.preprocessing.image.ImageDataGenerator(featurewise_center=False,
samplewise_center=False,
featurewise_std_normalization=False,
samplewise_std_normalization=False,
zca_whitening=False,
rotation_range=0.,
width_shift_range=0.,
height_shift_range=0.,
shear_range=0.,
zoom_range=0.,
channel_shift_range=0.,
fill_mode='nearest',
cval=0.,
horizontal_flip=False,
vertical_flip=False,
rescale=None,
dim_ordering=K.image_dim_ordering())

参数解释:

featurewise_center:布尔值,使输入数据集去中心化(均值为0)
samplewise_center:布尔值,使输入数据的每个样本均值为0
featurewise_std_normalization:布尔值,将输入除以数据集的标准差以完成标准化
samplewise_std_normalization:布尔值,将输入的每个样本除以其自身的标准差
zca_whitening:布尔值,对输入数据施加ZCA白化
rotation_range:整数,数据提升时图片随机转动的角度
width_shift_range:浮点数,图片宽度的某个比例,数据提升时图片水平偏移的幅度
height_shift_range:浮点数,图片高度的某个比例,数据提升时图片竖直偏移的幅度
shear_range:浮点数,剪切强度(逆时针方向的剪切变换角度)
zoom_range:浮点数或形如[lower,upper]的列表,随机缩放的幅度,若为浮点数,则相当于[lower,upper] = [1 - zoom_range, 1+zoom_range]
channel_shift_range:浮点数,随机通道偏移的幅度
fill_mode:;‘constant’,‘nearest’,‘reflect’或‘wrap’之一,当进行变换时超出边界的点将根据本参数给定的方法进行处理
cval:浮点数或整数,当fill_mode=constant时,指定要向超出边界的点填充的值
horizontal_flip:布尔值,进行随机水平翻转
vertical_flip:布尔值,进行随机竖直翻转
rescale: 重放缩因子,默认为None. 如果为None或0则不进行放缩,否则会将该数值乘到数据上(在应用其他变换之前)
dim_ordering:‘tf’和‘th’之一,规定数据的维度顺序。‘tf’模式下数据的形状为samples, width, height, channels,‘th’下形状为(samples, channels, width, height).该参数的默认值是Keras配置文件~/.keras/keras.json的image_dim_ordering值,如果你从未设置过的话,就是'th'

tensorflow中的部分数据增强

 import tensorflow as tf
import cv2
import numpy as np flags = tf.app.flags
FLAGS = flags.FLAGS
flags.DEFINE_boolean('random_flip_up_down', True, 'If uses flip')
flags.DEFINE_boolean('random_flip_left_right', True, 'If uses flip')
flags.DEFINE_boolean('random_brightness', True, 'If uses brightness')
flags.DEFINE_boolean('random_contrast', True, 'If uses contrast')
flags.DEFINE_boolean('random_saturation', True, 'If uses saturation')
flags.DEFINE_integer('image_size', 224, 'image size.') """
#flags examples
flags.DEFINE_float('learning_rate', 0.01, 'Initial learning rate.')
flags.DEFINE_integer('max_steps', 2000, 'Number of steps to run trainer.')
flags.DEFINE_string('train_dir', 'data', 'Directory to put the training data.')
flags.DEFINE_boolean('fake_data', False, 'If true, uses fake data for unit testing.')
"""
def pre_process(images):
if FLAGS.random_flip_up_down:
images = tf.image.random_flip_up_down(images)
if FLAGS.random_flip_left_right:
images = tf.image.random_flip_left_right(images)
if FLAGS.random_brightness:
images = tf.image.random_brightness(images, max_delta=0.3)
if FLAGS.random_contrast:
images = tf.image.random_contrast(images, 0.8, 1.2)
if FLAGS.random_saturation:
tf.image.random_saturation(images, 0.3, 0.5)
new_size = tf.constant([FLAGS.image_size,FLAGS.image_size],dtype=tf.int32)
images = tf.image.resize_images(images, new_size)
return images raw_image = cv2.imread("004545.jpg")
#image = tf.Variable(raw_image)
image = tf.placeholder("uint8",[None,None,3])
images = pre_process(image)
with tf.Session() as session:
result = session.run(images, feed_dict={image: raw_image})
cv2.imshow("image",result.astype(np.uint8))
cv2.waitKey(1000)

效果如下图所示:

2. 几种常使用的data augmentation方法总结

(1) Color Jittering:对颜色的数据增强:图像亮度、饱和度、对比度变化(此处对色彩抖动的理解不知是否得当);

(2) PCA  Jittering:首先按照RGB三个颜色通道计算均值和标准差,再在整个训练集上计算协方差矩阵,进行特征分解,得到特征向量和特征值,用来做PCA Jittering

(3) Random Scale:尺度变换;

(4) Random Crop:采用随机图像差值方式,对图像进行裁剪、缩放;包括Scale Jittering方法(VGG及ResNet模型使用)或者尺度和长宽比增强变换;

(5) Horizontal/Vertical Flip:水平/垂直翻转;

(6)5Shift:平移变换;

(7) Rotation/Reflection:旋转/仿射变换;

(8) Noise:高斯噪声、模糊处理;

(9) Label shuffle:类别不平衡数据的增广,参见海康威视ILSVRC2016的报告,里面提到了一种监督数据扩展方法(supervised data sugmentation).

参考来源:http://blog.csdn.net/mduanfire/article/details/51674098

https://zhuanlan.zhihu.com/p/23249000

paper 147:Deep Learning -- Face Data Augmentation(一)的更多相关文章

  1. 论文解读(SimGRACE)《SimGRACE: A Simple Framework for Graph Contrastive Learning without Data Augmentation》

    论文信息 论文标题:SimGRACE: A Simple Framework for Graph Contrastive Learning without Data Augmentation论文作者: ...

  2. paper 149:Deep Learning 学习笔记(一)

     1. 直接上手篇 台湾李宏毅教授写的,<1天搞懂深度学习> slideshare的链接: http://www.slideshare.net/tw_dsconf/ss-62245351? ...

  3. Paper | Xception: Deep Learning with Depthwise Separable Convolutions

    目录 故事 Inception结构和思想 更进一步,以及现有的深度可分离卷积 Xception结构 实验 这篇论文写得很好.只要你知道卷积操作或公式,哪怕没看过Inception,也能看懂. 核心贡献 ...

  4. 【深度学习Deep Learning】资料大全

    最近在学深度学习相关的东西,在网上搜集到了一些不错的资料,现在汇总一下: Free Online Books  by Yoshua Bengio, Ian Goodfellow and Aaron C ...

  5. 机器学习(Machine Learning)&深度学习(Deep Learning)资料(Chapter 2)

    ##机器学习(Machine Learning)&深度学习(Deep Learning)资料(Chapter 2)---#####注:机器学习资料[篇目一](https://github.co ...

  6. (转) Deep Learning Resources

    转自:http://www.jeremydjacksonphd.com/category/deep-learning/ Deep Learning Resources Posted on May 13 ...

  7. Why are very few schools involved in deep learning research? Why are they still hooked on to Bayesian methods?

    Why are very few schools involved in deep learning research? Why are they still hooked on to Bayesia ...

  8. What are some good books/papers for learning deep learning?

    What's the most effective way to get started with deep learning?       29 Answers     Yoshua Bengio, ...

  9. New Machine Learning Server for Deep Learning in Nuke(翻译)

    最近一直在开发Orchestra Pipeline System,歇两天翻译点文章换换气.这篇文章是无意间看到的,自己从2015年就开始关注机器学习在视效领域的应用了,也曾利用碎片时间做过一些算法移植 ...

随机推荐

  1. 多任务Multitask Learning

    一次只学习一个任务,大部分机器学习都属于单任务学习. 多任务学习:把多个相关的任务放在一起学习,同时学习多个任务. 对于复杂的问题,可以分解为简单的相互独立的子问题来解决,然后再合并结果,得到最初复杂 ...

  2. 华为交换机telnet配置

    1.在路由器上和交换机相连的借口上配置一个IP地址:比如192.168.1.1 24 2.在交换机上配置如下:<switch>system-view[switch]vlan 10[swit ...

  3. Bootstrap Date Range Picker

    var optionSet1 = { startDate: moment().subtract(29, 'days'), endDate: moment(), minDate: '12/21/2012 ...

  4. 正则finditer的使用

    import re #\. 是刚需必须有 d+ 必须一个或多个数字 pattern = re.compile(r'\d+\.\d*') d = pattern.finditer('3.14159265 ...

  5. ESET激活码,可用。

    ESET Internet Security 12.1.31.0 Finalhttps://download.eset.com/com/eset/apps/home/eis/windows/v12/1 ...

  6. [模板]网络最大流 & 最小费用最大流

    我的作业部落有学习资料 可学的知识点 Dinic 模板 #define rg register #define _ 10001 #define INF 2147483647 #define min(x ...

  7. NOIP后一波总结

    我的山寨较为可靠分数为305(洛谷是真的水~显然不能用啊,果断换了一组合适的数据) 据大神们估计,得奖的分数在280, 我肯定是没有啥希望了.(我旁边的lxy同学从初二开始,每次以超分数线至少60分的 ...

  8. aiohttp上报:Got more than 8190 bytes (10160) when reading Status line is too long.错误的解决办法

    通过浏览器向web服务传递base64码的图片时遇到参数过长的问题? 解决办法:查看aiohttp的源码:aiohttp/http_parser.py下找到: class HeadersParser: ...

  9. shell整数测试

  10. setbuf, setbuffer, setlinebuf, setvbuf - 流缓冲操作

    SYNOPSIS 总览 #include <stdio.h> void setbuf(FILE *stream, char *buf); void setbuffer(FILE *stre ...