为了账号安全,请及时绑定邮箱和手机立即绑定

TensorFlow 可用的数据增强

标签:
Sass/Less
#!/usr/bin/env python# -*- coding: utf-8 -*-# @Time    : 18-8-7 下午2:53# @File    : data_argument.py# @Software: PyCharm# @Author  : wxw# @Contact : xwwei@lighten.ai# @Desc    :import tensorflow as tfimport cv2import numpy as npwith tf.Session() as sess:
    raw_img = tf.gfile.Open('patch.jpg', 'rb').read()
    img_data = tf.image.decode_image(raw_img)
    img_data = tf.image.convert_image_dtype(img_data, tf.float32)
    cv2.imshow('raw_image', img_data.eval())
    print('raw_shape:', img_data.eval().shape)    """resize"""
    # img_data = tf.image.resize_images(img_data.eval(), (224, 224))
    """crop and black pad"""
    # img_data = tf.image.resize_image_with_crop_or_pad(img_data, target_height=1000,
    #                                                   target_width=1000)
    """按照倍数中心裁剪, 倍数=(0, 1]"""
    # img_data = tf.image.central_crop(img_data, central_fraction=0.2)
    """pad """
    # img_data = tf.image.pad_to_bounding_box(img_data, offset_height=10, offset_width=10,
    #                                         target_height=576+10, target_width=576+10)
    """crop"""
    # img_data = tf.image.crop_to_bounding_box(img_data, 40, 40, 576-40, 576-40)
    """extract
                                o----->y
                                |
                                |
                                v
                                x
    """
    # img_data = tf.image.extract_glimpse(tf.expand_dims(img_data, 0), size=[100, 100],
    #                                     offsets=tf.reshape(tf.constant([-.4, .4], dtype=tf.float32), [1, 2]))
    """roi pooling 必要操作 boxes为长宽比值!!! """
    # img_data = tf.image.crop_and_resize(tf.expand_dims(img_data, 0), boxes=[[0/576, 0/576, 1, 1]],
    #                                     box_ind=[0], crop_size=[100, 100])
    """上下翻转/左右/转置翻转/90度旋转---(random_)flip_up_down/flip_left_right/transpose/rot90"""
    # img_data = tf.image.rot90(img_data, k=-1)
    """Converting Between Colorspaces"""
    """灰度"""
    # img_data = tf.image.rgb_to_grayscale(img_data)
    """图像亮度[-1, 1]"""
    # img_data = tf.image.adjust_brightness(img_data, delta=-.7)
    """随机图像亮度"""
    # img_data = tf.image.random_brightness(img_data, max_delta=0.6)
    """随机对比度"""
    # img_data = tf.image.random_contrast(img_data, lower=0, upper=4)
    """随机色调"""
    # img_data = tf.image.random_hue(img_data, 0.5)
    """随机饱和度"""
    # img_data = tf.image.random_saturation(img_data, lower=0, upper=2)
    """图片标准化    (x - mean) / max(stddev, 1.0/sqrt(image.NumElements()))"""
    # img_data = tf.image.per_image_standardization(img_data)
    """draw boxes"""
    # img_data = tf.image.draw_bounding_boxes(tf.expand_dims(img_data, 0), [[[0.1, 0.2, 0.5, 0.9]]])
    print('Tensor:', img_data)
    print(img_data.eval().shape)
    print(img_data.eval())
    cv2.imshow('changed', img_data[0].eval())
    cv2.waitKey()



作者:翻开日记
链接:https://www.jianshu.com/p/c3a9573ecb0d


点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

举报

0/150
提交
取消