我使用 TensorFlow 函数 tf.image.resize_images 来调整图像大小,但在代码中出现此错误:ValueError: 'images' contains no shape。完整代码如下:
# -*- coding: utf-8 -*-
import tensorflow as tf
file = ["./1.jpg"]
f = tf.train.string_input_producer(file)
reader = tf.WholeFileReader()
key, img = reader.read(f)
img = tf.image.decode_image(img)
# img.set_shape([218,178,3])
img = tf.image.resize_images(img, [64,64])
coord = tf.train.Coordinator()
with tf.Session() as sess:
tf.train.start_queue_runners(coord=coord)
image = sess.run(img)
完整的错误信息是
Traceback (most recent call last):
File "image_read_test.py", line 10, in <module>
img = tf.image.resize_images(img, [64,64])
File "C:\Python35\lib\site-packages\tensorflow\python\ops\image_ops_impl.py", line 724, in resize_images
raise ValueError('\'images\' contains no shape.')
ValueError: 'images' contains no shape.
然后我尝试解决这个问题,但只能找到这样的方法
# -*- coding: utf-8 -*-
import tensorflow as tf
file = ["./1.jpg"]
f = tf.train.string_input_producer(file)
reader = tf.WholeFileReader()
key, img = reader.read(f)
img = tf.image.decode_image(img)
# img.set_shape([218,178])
# img = tf.image.resize_images(img, [64,64])
coord = tf.train.Coordinator()
with tf.Session() as sess:
tf.train.start_queue_runners(coord=coord)
image = sess.run(img)
image = tf.image.resize_images(image, [64,64])
只有这样功能才能正常工作,但不知道为什么?函数 tf.image.resize_images 是否仅将 numpy 数组作为参数?或者我可以找到另一种方法来解决这个问题?注意:img.set_shape([218,78,3]) 对我不起作用