tf return 无效的 JPEG 数据,大小 1100

tf return Invalid JPEG data, size 1100

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

这是代码:

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: Invalid JPEG data, size 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"]] Caused by op 'DecodeJpeg', defined at:

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

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