在使用自己的图片做数据集时需要做相应的处理(缩/放)
因此在使用CNN等模型之前,可以使用该方法获得你想要的大小的图片数据
import matplotlib.pyplot as plt
import tensorflow as tf
import numpy as np
image_raw_data = tf.gfile.GFile('C:/Users/DELL/Desktop/CWTPic/train1.jpg','r').read() #加载原始图像
with tf.Session() as sess:
img_data = tf.image.decode_jpeg(image_raw_data) #解码
plt.imshow(img_data.eval())
plt.show()
resized = tf.image.resize_images(img_data, [64,64],method=0) #第一个参数为原始图像,第二个参数为图像大小,第三个参数给出了指定的算法
resized = np.asarray(resized.eval(),dtype='uint8') #变为uint8才能显示
plt.imshow(resized)
plt.show()

本文介绍了一种使用TensorFlow进行图片预处理的方法,重点在于如何调整图片尺寸以适应卷积神经网络(CNN)等深度学习模型的输入要求。通过实际代码演示了从读取原始图片到调整至特定尺寸的过程。
2万+

被折叠的 条评论
为什么被折叠?



