如何将URL中的图像加载到张量流中?
问题描述:
我目前正在运行的这一点:如何将URL中的图像加载到张量流中?
image = urllib.urlopen(imgUrl)
pool3_features = sess.run(pool3,{'incept/DecodeJpeg/contents:0': image})
,我得到这个错误:
Unable to get element from the feed as bytes.
答
的解决方案是很简单......我所要做的就是调用read
方法从响应的urlopen。下面的作品就像一个魅力:
image = urllib.urlopen(imgUrl)
pool3_features = sess.run(pool3,{'incept/DecodeJpeg/contents:0': image.read()})
答
只需使用一个方法将其加载到与NumPy然后加载到TensorFlow。这可能更可靠,更灵活。
http://www.pyimagesearch.com/2015/03/02/convert-url-to-image-with-python-and-opencv/
你可以发布一个完整的可运行代码,gfile是什么意思? –
对不起,我想将img数据放入一个[bytesio](https://docs.python.org/3/library/io.html#binary-io),但我没有找到任何可用的api在张量流中。 –