Deeplab v3 Test

  1. Create Python Env
    $ mkdir ~/tf_ros && cd ~/tf_ros
    $ virtualenv --system-site-packages -p python2 tensor_ros_deeplab
  2. Activate Environment
    source tensor_ros_deeplab/bin/activate
  3. Install tensorflow GPU
    pip install --upgrade tensorflow_gpu-1.12.0-cp27-none-linux_x86_64.whl
  4. Move to the Deeplab dir
    $ git clone
  5. Clone Tensorflow's Models repo containing Deeplab
  6. Download a pretrained model:
    $ wget
  7. Use sample script for a single image:
  8. 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")
  9. 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."""
    original_im =
  except IOError:
    print('Cannot read image. Please check path: ' + image_path)

  print('running deeplab on image %s...' % image_path)
  resized_im, seg_map =

  vis_segmentation(resized_im, seg_map)
  1. Finally save and run the script:

TensorFlow and ROS Kinetic with Python 3.5 Natively


Native setup, no venv
1. Create working directory
$ mkdir ~/py3_tf_ros && cd ~/py3_tf_ros

  1. Install Python 3.5
    $ sudo apt-get install python3-dev python3-yaml python3-setuptools

  2. Install rospkg for Python 3

$ git clone git://
$ cd roskpkg && sudo python3 install
  1. Install catkin_pkg for Python 3
$ git clone git://
$ cd catkin_pkg && sudo python3 install && cd ..
  1. Install catkin for Python 3
$ git clone git://
$ cd catkin && sudo python3 install && cd ..
  1. Install OpenCV for Python 3
    pip3 install opencv-python

  2. Download desired TensorFlow version

  3. Setup Nvidia Drivers, CUDA and CUDNN according to the TensorFlow version.

  4. Install downloaded TensforFlow package
    pip3 install --user --upgrade tensorflow-package.whl

  5. Check that symbolic link /usr/local/cuda corresponds to the CUDA version required by TensorFlow. (if there are several CUDA versions installed in the system).

  6. Test TensorFlow
    python -c "import tensorflow as tf; print(tf.__version__)"
    This should display the version 1.XX.YY you selected.

  7. It is possible to import ros and import tensorflow.

  8. If cv2 package is also required:


import cv2


import ros

TensorFlow and ROS Kinetic with Python 2.7

TensorFlow and ROS Kinetic with Python 2.7

  1. Create a working directory
    $ mkdir ~/tf_ros && cd ~/tf_ros

  2. Download and Install an NVIDIA Driver >= 384.x ( We recommend RUN files, please check our other post on this topic.

  3. Download and Install CUDA 9.0 (

  4. Download and Install CUDNN for CUDA 9.0 (;

  5. Download TensorFlow for Python 2.7
    $ wget

  6. Install Python VirtualEnv
    $ sudo apt-get install python-virtualenv

  7. Create Python 2.7 virtual environment.
    $ virtualenv --system-site-packages -p python2 p2tf_venv
    (p2tf_venv can be any name)

  8. Activate environment
    $ source p2tf_venv/bin/activate

  9. Install TensorFlow
    (p2_venv) $ pip install --upgrade tensorflow_gpu-1.10.1-cp27-none-linux_x86_64.whl

  10. Make sure you have in LD_LIBARY_PATH, the cuda 9 libraries and binaries.

$ export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH && export PATH=/usr/local/cuda/bin:$PATH

  1. Check the ROS libraries are in the LD_LIBRARY_PATH as well.
    $ echo $LD_LIBRAY_PATH.
    It should contain /opt/ros/kinetic/lib:/opt/ros/kinetic/lib/x86_64-linux-gnu

  2. Check that Python ROS libraries are also included in the $PYTHONPATH.
    $ echo $PYTHONPATH.
    It should contain /opt/ros/kinetic/lib/python2.7/dist-packages.

  3. Test your installation is correct.
    (p2_venv) $ python -c "import tensorflow as tf; print(tf.__version__)"
    It should print the TensorFlow version install, such as 1.10.1.

  4. Ready to go!