I trained a classifier in the Tensorflow for Poets tutorial .
Works great locally, but how can I modify this to use images when I have a URL?
import tensorflow as tf
# change this as you see fit
image_path = sys.argv[1]
# Read in the image_data
image_data = tf.gfile.FastGFile(image_path, 'rb').read()
But how can I classify images from an external url? eg http://www.google.com/logo.png
Figured out we can use urllib.request.
Substitute:
image_data = tf.gfile.FastGFile(image_path, 'rb').read()
With:
# image_url = "http://www.google.com/logo.png"
req = urllib.request.Request(image_url)
response = urllib.request.urlopen(req)
image_data = response.read()
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.