返回无效的JPEG数据,大小为1100

时间:2016-11-05 21:05:55

标签: python tensorflow jpeg

我是张量流的新手,我正在尝试将jpg图像提供给tensorflow但是返回错误。

这是代码:

import tensorflow as tf

filename_queue = tf.train.string_input_producer(['D-MAIZ-BUENO/lista'])   

reader = tf.WholeFileReader()
key, value = reader.read(filename_queue)

my_img = tf.image.decode_jpeg(value,channels=0) # jpg decoder 


init_op = tf.initialize_all_variables()

with tf.Session() as sess:
  sess.run(init_op)



  coord = tf.train.Coordinator()
  threads = tf.train.start_queue_runners(coord=coord)

 for i in range(50): #length of your filename list
  image = my_img.eval() #here is your image Tensor :) 

#    print(image.shape)
#    Image.show(Image.fromarray(np.asarray(image)))
#
#  coord.request_stop()
#  coord.join(threads)

图像位于D-MAIZ-BUENO / lista中 lista是一个带有jpg图像的列表。 图像是jpg 640x480像素大小24.2kb

错误是:

  

tensorflow.python.framework.errors.InvalidArgumentError:无效的JPEG数据,大小1100        [[Node:DecodeJpeg = DecodeJpegacceptable_fraction = 1,channels = 0,fancy_upscaling = true,ratio = 1,try_recover_truncated = false,_device =" / job:localhost / replica:0 / task:0 / cpu:0&#34 ;]]   由op' DecodeJpeg'引起,定义于:

1 个答案:

答案 0 :(得分:1)

您必须将文件名列表提供给队列。所以,例如,

with open('D-MAIZ-BUENO/lista', 'r') as f:
  filename_list = f.read().splitlines()
filename_queue = tf.train.string_input_producer(filename_list)