tf 图像随机变换

原文链接: tf 图像随机变换

上一篇: ros turtlesim 控制小乌龟

下一篇: tf.py_func 操作tensor 增强 拓展 tensorflow灵活性

2da74eb1adddd85c887c3b0b8559b9049f2.jpg

c96b261d3da734a89713d9c9e189fe66aa6.jpg

b7372e20d2e9147071ac87e2c5ce609bed1.jpg

随机剪裁,先放大1.5倍,然后剪裁出原始尺寸

# 随机剪裁
# 先放大1.5倍后在剪裁出原图尺寸
crop = [tf.random_crop(
    tf.image.resize_images(
        img,
        (img.shape[0] * 3 // 2, img.shape[1] * 3 // 2)
    ),
    img.shape)
    for i in range(N_IMAGES)]
crop = tf.concat([img] + crop, axis=1)
crop = tf.clip_by_value(crop, 0, 255)
crop = tf.cast(crop, tf.uint8)

随机旋转,需要使用tf对scipy的方法进行包装

#  随机旋转需要使用包装函数
def random_rotate_image_func(image):
    # 旋转角度范围
    angle = np.random.uniform(low=-360.0, high=360.0)
    return misc.imrotate(image, angle, 'bicubic')


# 输入为img,输出类型
rotate = [tf.py_func(random_rotate_image_func, [img], tf.uint8) for i in range(N_IMAGES)]
rotate = tf.concat([tf.cast(img, tf.uint8)] + rotate, axis=1)
# clip函数只支持的类型,所以需要先转换为int32,再转化为uint8
# bfloat16, float16, float32, float64, int32, int64
rotate 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值