对图像进行解码和调整大小会产生未知的张量形状

时间:2017-10-16 06:54:06

标签: python image-processing tensorflow

我正在尝试加载两张图片,一张是 .png ,另一张是 .jpg tensorflow 并使用tf.image.pad_to_bounding_box将它们调整为100x100像素大小,以便它们具有相同的大小并可用于训练。这是我的代码:

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/']  

我做错了什么?请帮忙。

1 个答案:

答案 0 :(得分:0)

令人困惑的是,decode_image没有给出完全定义的张量形状,因为它也支持gif - 这看起来有点像范围蠕变。 此外,decode_jpeg现在静默处理PNG,并具有完全定义的张量形状。