Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
TensorFlow:ValueError:&x27;图像';不包含任何形状_Tensorflow_Tensorflow Gpu - Fatal编程技术网

TensorFlow:ValueError:&x27;图像';不包含任何形状

TensorFlow:ValueError:&x27;图像';不包含任何形状,tensorflow,tensorflow-gpu,Tensorflow,Tensorflow Gpu,我使用TensorFlow函数tf.image.resize_images来调整图像大小,但在代码中出现以下错误: ValueError:“图像”不包含形状。 完整代码如下: # -*- 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

我使用TensorFlow函数tf.image.resize_images来调整图像大小,但在代码中出现以下错误: ValueError:“图像”不包含形状。 完整代码如下:

# -*- 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.

只有这样,函数才能很好地工作,但我不知道为什么?函数tf.image.resize_images是否仅将numpy数组作为参数?或者我可以找到另一种方法来解决这个问题?注意:img.set_shape([218,78,3])对我不起作用

我最近遇到了这个问题

tf.image.decode_image() 
不会返回带有形状的张量,但我的图像都是jpeg格式的

所以我用

 tf.image.decode_jpeg() 
它返回的张量和解决问题的形状。 注意还有tf.image.decode_png()


更多信息可在此处找到

重要的是将
expand\u animations=False
作为参数传递:

尝试:

确保你有一个三维形状的张量。 这个问题是由于gif格式造成的,因为decode_gif返回一个4-D数组[num_frames,height,width,3],而其他格式包括decode_bmp,decode_jpeg和decode_png,它们返回3-D数组[height,width,num_channels]


有关更多信息,请查看

为什么tensorfow从
decode_image()
中避免使用形状参数?@alireza Akhavan回答了您下面的问题;这是因为该方法也可以读取GIF。有点烦人和神秘,因为在文档中它说它返回一个形状。
tf.image.decode\u jpeg()
有效。
tf.image.decode_image()
不应该自动推断出
jpeg
格式吗?
 tf.image.decode_jpeg() 
image_string = tf.read_file(filename)
image_decoded = tf.cond(
      tf.image.is_jpeg(image_string),
      lambda: tf.image.decode_jpeg(image_string, channels=3),
      lambda: tf.image.decode_png(image_string, channels=3))
tf.image.decode_image(img, expand_animations = False)