我试着用Tensorflow建立一个简单的CNN。问题是我无法读取一个简单的.png文件来给CNN提供信息。
>>> filename = tf.constant("training/a1.png")
>>> filename
<tf.Tensor 'Const_1:0' shape=() dtype=string>
>>> image_string = tf.read_file(filename)
>>> image_string
<tf.Tensor 'ReadFile_1:0' shape=() dtype=string>
>>> image_decoded = tf.image.decode_png(image_string)
>>> image_decoded
<tf.Tensor 'DecodePng_1:0' shape=(?, ?, ?) dtype=uint8>正如您在上面的代码中所看到的。tf.image.decode_png( image_string )返回形状未知的张量。
谢谢vladimir-bystricky!这样啊,原来是这么回事。这是它可以帮助其他人的代码。
>>> import tensorflow as tf
>>> filename = tf.constant("training/a1.png")
>>> image_string = tf.read_file(filename)
>>> image_decoded = tf.image.decode_png(image_string)
>>> shape = tf.shape( image_decoded )
>>> sess = tf.Session()
>>> print(sess.run( shape ) )
[360 360 4]发布于 2017-10-15 10:28:15
这是正确的行为,因为在您的代码中,您只创建一个图,TF在此步骤上不实际读取png文件,而只创建在会话中启动Graph时将执行的操作。操作结果为形状未知的张量(此时)。您可以根据预定义的大小调整或裁剪它。
https://stackoverflow.com/questions/46753885
复制相似问题