Python 使用tensorflow导入png文件

Python 使用tensorflow导入png文件,python,tensorflow,Python,Tensorflow,它继续提出 htmls = "http://www.google.com" tree = [0]*255 trees = [0]*255 for x in range(255): page = requests.get(htmls) tree[x] = html.fromstring(page.content) png = imgkit.from_url(htmls, 'out.png') trees[x] = tf.io.decode_png(

它继续提出

htmls = "http://www.google.com"
tree = [0]*255
trees = [0]*255
for x in range(255):
    page = requests.get(htmls)
    tree[x] = html.fromstring(page.content)

    png = imgkit.from_url(htmls, 'out.png')
    trees[x] = tf.io.decode_png(
        'out.png'
    )
尽管png在这个命令之外看起来很好,但是第一个参数应该是字符串类型的张量

tensorflow.python.framework.errors_impl.InvalidArgumentError: Expected image (JPEG, PNG, or GIF), got unknown format starting with 'out.png' [Op:DecodePng]
阅读img似乎需要做很多工作,我认为opencv会更好

with tf.Session() as session:
     content = tf.placeholder(tf.string)
     tensor = tf.image.decode_image(contents=content) # your using tf.io.decode_png
     trees[x] = (session.run(tensor, {content: 'out.png'}))
import cv2
trees[x] = cv2.imread('out.png')