![](/img/trans.png)
[英]How to prepare PIL Image.Image for tf.image.decode_image
[英]How to display the code of an image after tf.decode_image
我正在尝试查看tf如何解码图像,所以我尝试
import tensorflow as tf
image1 = tf.image.decode_png('/usr/src/pycharm-2017.1/bin/pycharm.png')
print(image1.shape)
with tf.Session() as sess:
img = sess.run(image1)
print(img.shape, img)
但这会引发错误
InvalidArgumentError (see above for traceback): Invalid PNG header, data size 39
[[Node: DecodePng = DecodePng[channels=0, dtype=DT_UINT8, _device="/job:localhost/replica:0/task:0/cpu:0"](DecodePng/contents)]]
我也尝试过tf.image.decode_image,但是它也不起作用。 怎么了 ? 我该如何解决? 感谢你
tf.image.decode_png
接受字符串类型的Tensor,因此您需要先使用Tensorflow读取png,然后再将其传递给函数:
import tensorflow as tf
image1 = tf.image.decode_png(tf.read_file('/usr/src/pycharm-2017.1/bin/pycharm.png'))
print(image1.shape)
with tf.Session() as sess:
img = sess.run(image1)
print(img.shape, img)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.