我在Tensorflow for Poets tutorial中训练了一个分类器。
在本地工作得很好,但是如果我有URL,如何修改它以使用图像?
Update: Updated first row of input and output data as well as Algo,
to reflect updated query based on primary reply from @Gregor.
但是如何从外部网址对图像进行分类?例如 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()
答案 0 :(得分:2)
想通了我们可以使用urllib.request。
替换:
image_data = tf.gfile.FastGFile(image_path, 'rb').read()
使用:
# image_url = "http://www.google.com/logo.png"
req = urllib.request.Request(image_url)
response = urllib.request.urlopen(req)
image_data = response.read()