Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resizing images for training in TensorFlow

Tags:

tensorflow

I tried to read my own images for training in TensorFlow. However, there seems to be an error:

ValueError: 'size' must be a 1-D Tensor of 2 elements: new_height, new_width. 

What is wrong with the following code sample?

filenames=['images/000001.jpg','images/000002.jpg','images/000003.jpg','images/000004.jpg']
labels=[1,0,1,0]

filename_queue=tf.train.string_input_producer(filenames)

reader=tf.WholeFileReader()
filename, content = reader.read(filename_queue)
images=tf.image.decode_jpeg(content, channels=3)
images=tf.cast(images, tf.float32)
resized_images=tf.image.resize_images(images, 224, 224)

image_batch, label_batch=tf.train.batch([resized_images, labels], batch_size=2)
like image 337
cerebrou Avatar asked Oct 28 '16 06:10

cerebrou


1 Answers

The error says, size must be a 1-D Tensor. What tensorflow actually means with this is just to make the second argument of tf.image.resize_images a tuple:

resized_images = tf.image.resize_images(images, (224, 224))
like image 129
cerebrou Avatar answered Oct 23 '22 09:10

cerebrou