解码和调整大小的图像给未知的张量形状
问题描述:
我试图载入两幅图片,一个是png格式,另一个是的.jpg,到tensorflow并将其调整到使用tf.image.pad_to_bounding_box
100×100像素大小,以便它们具有相同的尺寸并可用于训练。这是我的代码:解码和调整大小的图像给未知的张量形状
import os
import tensorflow as tf
def decode(image_data):
return tf.image.decode_image(image_data, channels=3)
def adjust_paddig(image_tensor):
return tf.image.pad_to_bounding_box(image_tensor, offset_height=0, offset_width=0, target_height=100, target_width=100)
def load(images_paths):
filename_queue = tf.train.string_input_producer(images_paths)
reader = tf.WholeFileReader()
_, image_file = reader.read(filename_queue)
image_tensor = decode(image_file)
padded_image_tensor = adjust_paddig(image_tensor)
return padded_image_tensor
if __name__ == '__main__':
IMAGES_PATH = ["images/1.png","images/2.jpg"] # Both image are of different shape
class_images_tensor = load(IMAGES_PATH)
print(class_images_tensor.shape)
但是,一些如何调整大小的图像大小是不适当的。它显示高度和宽度,但不是深度(我的意思是频道)。
Output: (100,100,?) #height, width are 100, but depth is '?'
令人惊讶的是,它也为无效路径提供相同的输出。
Eg: IMAGES_PATH = ['images/']
我在做什么错?请帮忙。
答
令人困惑的是,decode_image没有给出完全定义的张量形状,因为它也支持gif - 这看起来有点像范围蠕变。 此外,decode_jpeg现在静静地处理PNG,并且具有完全定义的张量形状。