- Create Python Env
$ mkdir ~/tf_ros && cd ~/tf_ros
$ virtualenv --system-site-packages -p python2 tensor_ros_deeplab
- Activate Environment
source tensor_ros_deeplab/bin/activate
- Install tensorflow GPU
pip install --upgrade tensorflow_gpu-1.12.0-cp27-none-linux_x86_64.whl
- Move to the Deeplab dir
$ git clone https://github.com/tensorflow/models
- Clone Tensorflow’s Models repo containing Deeplab
~/tf_ros/models/research/deeplab
- Download a pretrained model:
$ wget https://github.com/tensorflow/models/blob/master/research/deeplab/g3doc/model_zoo.md
- Use sample script for a single image:
https://github.com/tensorflow/models/blob/master/research/deeplab/deeplab_demo.ipynb
- Change the
MODEL
var to the path of the previously downloaded model:
MODEL = DeepLabModel("~/tf_ros/models/research/deeplab/deeplabv3_mnv2_dm05_pascal_trainaug_2018_10_01.tar.gz")
- To use a local image instead of a URL change the run_visualization function to:
def run_visualization(image_path):
"""Inferences DeepLab model and visualizes result."""
try:
original_im = Image.open(image_path)
except IOError:
print('Cannot read image. Please check path: ' + image_path)
return
print('running deeplab on image %s...' % image_path)
resized_im, seg_map = MODEL.run(original_im)
vis_segmentation(resized_im, seg_map)
- Finally save and run the script:
ptyhon script_name.py