Kaan Akdik
Kaan Akdik

Reputation: 35

Deeplab test with a local image file

I am trying to run deeplab on my local computer. I installed deeplab on my computer and defined paths. Deeplab is running successfully on my local computer. This is the last block of 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)

I am running it jupyter notebook. It works fine for '_SAMPLE_URL' variable or any link that includes an image file. I would like to test deeplab with a local image file.

Note: Environment variables have been defined. So i can access my local files from this notebook. All libraries are working. But i don't want to test an image at URL, just local image files.

Upvotes: 0

Views: 103

Answers (2)

Rujun Long
Rujun Long

Reputation: 11

change the local path

_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')

Upvotes: 1

Kaan Akdik
Kaan Akdik

Reputation: 35

I did it by change 'BytesIO(jpeg_str)' with '123.jpg' at 'original_im = Image.open(BytesIO(jpeg_str))' line.

Upvotes: 0

Related Questions