JackDonMcLovin
JackDonMcLovin

Reputation: 177

Importing png files with 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(
        'out.png'
    )

It continues to come up with

tensorflow.python.framework.errors_impl.InvalidArgumentError: Expected image (JPEG, PNG, or GIF), got unknown format starting with 'out.png' [Op:DecodePng]

Although the png looks fine from outside this command

Upvotes: 2

Views: 171

Answers (1)

Kenan
Kenan

Reputation: 14094

According to the docs the first param should be a tensor of type string.

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'}))

This seems like a lot of work to read an img, i think opencv would be better

import cv2
trees[x] = cv2.imread('out.png')

Upvotes: 2

Related Questions