使用本地图像文件进行 Deeplab 测试

问题描述

我正在尝试在本地计算机上运行 deeplab。我在我的电脑上安装了 deeplab 并定义了路径。 Deeplab 在我的本地计算机上成功运行。这是 deeplab_demo.ipynb 的最后一块

SAMPLE_IMAGE = 'image1'  # @param ['image1','image2','image3']
IMAGE_URL = ''  #@param {type:"string"}

_SAMPLE_URL = ('https://github.com/tensorflow/models/blob/master/research/'
               'deeplab/g3doc/img/%s.jpg?raw=true')


def run_visualization(url):
  """Inferences DeepLab model and visualizes result."""
  try:
    f = urllib.request.urlopen(url)
    jpeg_str = f.read()
    original_im = Image.open(BytesIO(jpeg_str))
  except IOError:
    print('Cannot retrieve image. Please check url: ' + url)
    return

  print('running deeplab on image %s...' % url)
  resized_im,seg_map = MODEL.run(original_im)

  vis_segmentation(resized_im,seg_map)


image_url = IMAGE_URL or _SAMPLE_URL % SAMPLE_IMAGE
run_visualization(image_url)

我正在运行它 jupyter notebook。它适用于“_SAMPLE_URL”变量或任何包含图像文件链接。我想用本地图像文件测试 deeplab。

注意:环境变量已经定义。所以我可以从这个笔记本访问我的本地文件。所有图书馆都在工作。但我不想在 URL 上测试图像,只想测试本地图像文件

解决方法

更改本地路径

_SAMPLE_URL = ('https://github.com/tensorflow/models/blob/master/research/' 'deeplab/g3doc/img/%s.jpg?raw=true')

--->

_SAMPLE_URL = ('file:///path to/tensorflow/models/blob/master/research/' 'deeplab/g3doc/img/%s.jpg')

,

我通过在 'original_im = Image.open(BytesIO(jpeg_str))' 行将 'BytesIO(jpeg_str)' 更改为 '123.jpg' 来实现的。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...