【问题标题】:Tensorflow image reading emptyTensorFlow 图像读取为空
【发布时间】:2015-12-18 13:27:57
【问题描述】:

本题基于:Tensorflow image reading & display

按照他们的代码,我们有以下内容:

string = ['/home/user/test.jpg']
filepath_queue = tf.train.string_input_producer(string)
self.reader = tf.WholeFileReader()
key, value = self.reader.read(filepath_queue)

print(value)
# Output: Tensor("ReaderRead:1", shape=TensorShape([]), dtype=string)

my_img = tf.image.decode_jpeg(value, channels=3)
print(my_img)
# Output: Tensor("DecodeJpeg:0", shape=TensorShape([Dimension(None), Dimension(None), Dimension(3)]), dtype=uint8)

为什么my_img 没有维度? (Dimension(3) 只是因为参数channels=3

这是否意味着图像未正确加载? (img = misc.imread('/home/user/test.jpg') 确实会加载该图像)。

【问题讨论】:

    标签: tensorflow


    【解决方案1】:

    图像将被正确加载,但在运行操作之前,TensorFlow 没有足够的信息来推断图像的形状。这是因为tf.image.decode_jpeg() 可以产生不同形状(高度和宽度)的张量,具体取决于字符串张量value 的内容。这使您可以使用不同大小的图像集合构建input pipelines

    形状中的Dimension(None) 表示"unknown" rather than "empty"。 如果您碰巧知道此操作读取的所有图像将具有相同的大小,您可以使用Tensor.set_shape() 提供此信息,这样做将有助于验证图表后面部分的形状:

    my_img = tf.image.decode_jpeg(value, channels=3)    
    KNOWN_HEIGHT = 28
    KNOWN_WIDTH = 28
    my_img.set_shape([KNOWN_HEIGHT, KNOWN_WIDTH, 3])
    
    print(my_img)
    # Output: Tensor("DecodeJpeg:0", shape=TensorShape([Dimension(28), Dimension(28), Dimension(3)]), dtype=uint8)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-24
      • 1970-01-01
      • 2015-01-03
      • 2017-12-09
      • 2016-04-11
      • 1970-01-01
      • 2019-02-02
      • 1970-01-01
      相关资源
      最近更新 更多