读取不同大小和格式的图像以在Tensorflow中形成队列

时间:2018-07-24 15:58:19

标签: tensorflow queue

我在Tensorflow上遇到问题。我想阅读一些bmp和jpeg图像以在Tensorflow中形成队列。这些图像的大小不同。

输入是图像路径列表和标签列表。 目前,我使用“ tf.train.slice_input_producer”(生成队列),“ tf.image.decode_image”(读取不同格式的图像),“ tf.image.resize_images”(将图像调整为相同大小)。

但是,这里有一些问题。 “ tf.image.resize_images”需要图像形状,但“ tf.image.decode_image”中没有任何形状。如果我手动设置固定图像形状,则读取一些不同尺寸的图像会出现错误。

是否有解决此问题的更好方法(在Tensorflow中读取不同大小和格式的图像)?

images = tf.convert_to_tensor(image_list)
labels = tf.convert_to_tensor(label_list)
input_queue = tf.train.slice_input_producer([images, labels]) #Slice_input producer shuffles the data by default.

#Decode 
image = tf.read_file(input_queue[0])
image = tf.image.decode_image(image, channels=3) # for different format
label = input_queue[1]

image.set_shape([640, 480, 3]) # if I dont set the shape, "tf.image.resize_images" cannot work, if I set it, it is fixed... 

image = tf.image.resize_images(image, [160, 120])
image_batch, label_batch = tf.train.batch([image , label], batch_size=batch_size)

return image_batch, label_batch

0 个答案:

没有答案