I'm trying to see how the tf decode images so I try
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)
but it raise the error
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)]]
Also I've tried tf.image.decode_image, but it didn't work either. What's wrong ? How can I fix it? Thank u
tf.image.decode_png
accepts a Tensor of type string, so you need to read the png with Tensorflow before passing it to the function:
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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.