tensorflow:如何旋转图像以进行数据增强? [英] tensorflow: how to rotate an image for data augmentation?

查看:95
本文介绍了tensorflow:如何旋转图像以进行数据增强?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 tensorflow 中,我想从随机角度旋转图像,以进行数据增强.但是我在 tf.image 模块中没有找到这种转换.

In tensorflow, I would like to rotate an image from a random angle, for data augmentation. But I don't find this transformation in the tf.image module.

推荐答案

更新:见下方@astromme 的回答.Tensorflow 现在支持原生旋转图像.

Update: see @astromme's answer below. Tensorflow now supports rotating images natively.

在 tensorflow 中没有本地方法的情况下你可以做的事情是这样的:

What you can do while there is no native method in tensorflow is something like this:

from PIL import Image
sess = tf.InteractiveSession()

# Pass image tensor object to a PIL image
image = Image.fromarray(image.eval())

# Use PIL or other library of the sort to rotate
rotated = Image.Image.rotate(image, degrees)

# Convert rotated image back to tensor
rotated_tensor = tf.convert_to_tensor(np.array(rotated))

这篇关于tensorflow:如何旋转图像以进行数据增强?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆