数据增强(增广)
在进行图像分类或者检测时候,如果数据量比较少的情况下,可以对已有的图像数据进行一些处理来扩充数据集大小。
分类
对于图像分类而言,可以有的操作有翻转,随机裁剪,随机亮度变化,随机对比度变化,随机旋转等,而标签保持不变;
在tensorflow中有一些封装好的处理函数,比如在cifar10_input.py
中就有使用到如下几个:
tf.image.random_crop
: 对图像随机裁剪tf.image.random_flip_left_right
:随机左右翻转tf.image_random_brightness
: 随机亮度变化tf.image_random_contrast:
随机对比度变化tf.image_per_image_standardization
: 减去均值像素,并除以像素方差(图片标准化)
height = IMAGE_SIZE
width = IMAGE_SIZE
# Image processing for training the network. Note the many random
# distortions applied to the image.
# Randomly crop a [height, width] section of the image.
distorted_image = tf.random_crop(reshaped_image, [height, width, 3])
# Randomly flip the image horizontally.
distorted_image = tf.image.random_flip_left_right(distorted_image)
# Because these operations are not commutative, consider randomizing
# the order their operation.
distorted_image = tf.image.random_brightness(distorted_image,
max_delta=63)
distorted_image = tf.image.random_contrast(distorted_image,
lower=0.2, upper=1.8)
# Subtract off the mean and divide by the variance of the pixels.
float_image = tf.image.per_image_standardization(distorted_image)
检测
对于检测而言,涉及到旋转操作到,要注意标签的改变。其他操作等标签基本上保持一致即可。