JJJ
JJJ

Reputation: 2899

How do I load images from URLs into tensorflow?

I'm currently running this:

image = urllib.urlopen(imgUrl)
pool3_features = sess.run(pool3,{'incept/DecodeJpeg/contents:0': image})

and I get this error:

Unable to get element from the feed as bytes.

Upvotes: 1

Views: 2547

Answers (2)

JJJ
JJJ

Reputation: 2899

The solution was quite simple... All I had to do was call the read method on response from urlopen. The following works like a charm:

image = urllib.urlopen(imgUrl)
pool3_features = sess.run(pool3,{'incept/DecodeJpeg/contents:0': image.read()})

Upvotes: 3

aselle
aselle

Reputation: 639

Just use a method to load it into NumPy and then load that into TensorFlow. This is likely more reliable, more flexible.

http://www.pyimagesearch.com/2015/03/02/convert-url-to-image-with-python-and-opencv/

Upvotes: -1

Related Questions