0
我想用Tensorflow建立一个简单的CNN。问题是我无法读取一个简单的.png文件来提供CNN。阅读PNG文件并喂一个cnn Tensorflow
>>> 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]