【问题标题】:How do I load images from URLs into tensorflow?如何将 URL 中的图像加载到 tensorflow 中?
【发布时间】:2017-02-14 05:48:56
【问题描述】:

我目前正在运行这个:

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

我得到这个错误:

无法从提要中以字节形式获取元素。

【问题讨论】:

  • 能否贴出完整的可运行代码,gfile是什么意思?
  • 对不起,我想把img数据放到bytesio,但是我没有找到任何可以在tensorflow中使用的api。

标签: python tensorflow


【解决方案1】:

解决方案非常简单...我所要做的就是根据来自 urlopen 的响应调用 read 方法。下面的工作就像一个魅力:

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

【讨论】:

    【解决方案2】:

    只需使用一种方法将其加载到 NumPy 中,然后将其加载到 TensorFlow 中。这可能更可靠、更灵活。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-21
      • 1970-01-01
      • 2023-03-20
      • 2015-11-04
      • 2013-08-18
      • 1970-01-01
      • 1970-01-01
      • 2012-10-29
      相关资源
      最近更新 更多