Reputation: 32294
I am able to run all cells except the last one from this colab page.
There is a form in the section "Run on sample images". How do I use script instead of that form? I am using Jupyter notebook that does not support creation of the forms like that.
Upvotes: 1
Views: 2166
Reputation: 14515
If you double click the form in colab you can see the code that sits behind it:
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)
If you copy this code as is into a new cell in your own jupyter instance you can now just fill whatever values you like for the @param
fields and run the cell as normal.
Upvotes: 1