【发布时间】:2017-06-09 06:09:09
【问题描述】:
我刚开始学习 Tensorflow 和 Numpy 概念。我正在使用 Tensorflow 将不同形状的图像重塑为我正在使用循环的一个固定形状。在循环结束时,我将这些重新整形的图像累积到一个数组中。现在,如果我从这个数组中绘制图像,我会得到模糊的图像。但是,如果我使用 Tensorflow 绘制重塑图像的实例,我会得到正确的图像。请问有人能解释一下我哪里出了问题吗?
代码:
fixedW = 227.0
fixedH = 227.0
X_data = np.zeros((3, fixedW, fixedH, 3), dtype = np.float32) # Only 3 images in this example
tf.reset_default_graph()
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
for i in range(3):
img = matplotlib.image.imread(image_file_name[i])
preshape = img.shape
img = np.reshape(img, (1, preshape[0], preshape[1], preshape[2])) #Make it single batched image
tf_img = tf.image.resize_images(img, (fixedW, fixedH), tf.image.ResizeMethod.NEAREST_NEIGHBOR)
resized_img = sess.run(tf_img)[0]
print(resized_img.shape) # Prints correctly
X_data[i, :, :, :] = resized_img[:, :, :] # Something is wrong here
# This plots correctly
plt.imshow(resized_img)
plt.show()
# This plots some blurred image
plt.imshow(X_data[2])
plt.show()
请任何人解释我在这方面哪里出了问题,以及在我对这项任务的理解中我在这里遗漏了什么概念。
【问题讨论】:
标签: python numpy matplotlib tensorflow