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:减去均值像素,并除以像素方差(图片标准化)。
注意:这些函数都是增加数据的好方法。


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值