tensorflow--数据预处理

转载:

https://mp.weixin.qq.com/s?__biz=MzI2MzYwNzUyNg%3D%3D&chksm=eab804d7ddcf8dc1b274d6343cbf281d5e45508a5966fee47d2e27590f834cc03634645218d4&idx=1&mid=2247483742&scene=21&sn=858c4ebfb253fa5dcecdcafe73b30d79

读取图片

TensorFlow 读取图片数据代码:
reader = tf.WholeFileReader()
key, value = reader.read(tf.train.string_input_producer(['cat.jpg']))
image0 = tf.image.decode_jpeg(value)

图像缩放:

resized_image = tf.image.resize_images(image0, [256, 256], \
        method=tf.image.ResizeMethod.AREA)

其中 method 有四种选择:

ResizeMethod.BILINEAR :双线性插值

ResizeMethod.NEAREST_NEIGHBOR : 最近邻插值

ResizeMethod.BICUBIC : 双三次插值

ResizeMethod.AREA :面积插值

图像剪裁:

cropped_image = tf.image.crop_to_bounding_box(image0, 20, 20, 256, 256)

图像翻转:(水平,上下)

lipped_image = tf.image.flip_left_right(image0)

flipped_image = tf.image.flip_up_down(image0)

图像旋转:(k转90度的次数)

rotated_image = tf.image.rot90(image0, k=1)

图像灰度变化:

grayed_image = tf.image.rgb_to_grayscale(image0)

猜你喜欢

转载自blog.csdn.net/qq_40614981/article/details/81324761
今日推荐