tensorflow学习(二)——训练分类时,对图像进行增强(基于tf.image存在的一些问题)

0. 写作目的

好记性不如烂笔头。

1. 图像分类时,图像的数据增强

在博主进行图像增强时,存在一些问题,和大家分享一下。

1.1 使用tensorflow自带的读取图像函数存在的问题

如果采用直接读取图像的方式(使用tf.image进行读取图像),然后使用tf.image中的增强函数对数据进行增强,在使用tf.gfile.FastGFile( 'test-{}.jpg'.format(batch), 'rb').read()有时存在路径错误的问题(此处为路径中存在中文问题,这是由于使用Python2的原因),无法正常读取图像数据。

def preprocess_for_train(image, height=256, width=256, bbox=None):
    
    ############ argument for the training images

    # 如果没有提供标注框,则认为整个图像就是需要关注的部分

    #if bbox is None:
    #    bbox = tf.constant([0.0, 0.0, 1.0, 1.0], dtype=tf.float32, shape=[1, 1, 4])

    image = tf.image.convert_image_dtype(image, dtype=tf.float32)

    # 随即截取图像,减小需要关注的物体大小对图像识别算法的影响
    # bbox_begin, bbox_size, _ = tf.image.sample_distorted_bounding_box(tf.shape(image), bounding_boxes = bbox)
    # distorted_image = tf.slice(image, bbox_begin, bbox_size)

    distorted_image = tf.image.random_hue(image, 0.3, seed=2018)

    distorted_image = tf.image.random_saturation(distorted_image, 1, 5, seed=2108)

    distorted_image = tf.image.random_brightness(distorted_image, 0.1, seed=2801)

    # 将随即截取的图片调整为神经网络的输入大小,method可以选择插值的方式, 0为双线性1为最近邻2
  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值