cifar10_input的distorted_inputs功能介绍

cifar10_input.py文件里还有个功能强大的函数——distorted_inputs,可以在代码中找到其实现。它是针对train数据的,对train数据进行了变形处理,起了一个数据增广的作用。在数据集比较小、数据量远远不够的情况下,可以对图片进行翻转、随机剪切等操作以增加数据,制作出更多的样本,提高对图片的利用率。
该函数的核心代码如下:
 # 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)
上述代码分别调用了不同的函数对图片进行不同的变换,具体解释如下:
  • tf.random_crop:为图片随机裁剪
  • tf.image.random_flip_left_right:随机左右翻转
  • tf.image.random_brightness:随机亮度变化
  • tf.image.random_contrast:随机对比度变化
  • tf.image.per_image_standardization:减去均值像素,并除以像素方差(图片标准化)。
注意:这些函数都是增加数据的好方法。


猜你喜欢

转载自blog.csdn.net/chengqiuming/article/details/80292535