簡體   English   中英

如何在tf.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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM