Tensorflow图像读取为空
Tensorflow image reading empty
本题基于:
根据他们的代码,我们有以下内容:
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
没有维度? (维度(3)只是因为参数channels=3
)
这是否意味着图像未正确加载? (img = misc.imread('/home/user/test.jpg')
确实加载了该图像)。
图像将被正确加载,但 TensorFlow 没有足够的信息来推断图像的形状,直到运算 运行。出现这种情况是因为 tf.image.decode_jpeg()
can produce tensors of different shapes (heights and widths), depending on the contents of the string tensor value
. This enables you to build 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)
本题基于:
根据他们的代码,我们有以下内容:
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
没有维度? (维度(3)只是因为参数channels=3
)
这是否意味着图像未正确加载? (img = misc.imread('/home/user/test.jpg')
确实加载了该图像)。
图像将被正确加载,但 TensorFlow 没有足够的信息来推断图像的形状,直到运算 运行。出现这种情况是因为 tf.image.decode_jpeg()
can produce tensors of different shapes (heights and widths), depending on the contents of the string tensor value
. This enables you to build 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)