Reputation: 23
I am new in tensor flow and I am trying to feed jpg images to tensorflow but return an error.
This is the code:
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)
the images are in D-MAIZ-BUENO/lista and the lista is a list with the jpg images. The images are jpg 640x480 pixels size 24.2kb
The error is:
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:
Upvotes: 0
Views: 2244
Reputation: 1637
You have to feed the list of filenames to the queue. So, for instance,
with open('D-MAIZ-BUENO/lista', 'r') as f:
filename_list = f.read().splitlines()
filename_queue = tf.train.string_input_producer(filename_list)
Upvotes: 1