Installing object detection libraries

You install an object detection library so that you can run the object detection model on an edge.

About this task

IBM® Maximo® PQI SaaS Visual Insights supports the following object detection libraries: YOLO (you only look once), Faster R-CNN, and SSD (Single Shot MultiBox Detector).

Procedure

  1. Install the related Python packages by using the following commands:
    sudo apt-get install python-numpy
    sudo apt-get install python-scipy
    sudo pip install cython
    sudo pip install easydict
    sudo pip install uuid
    sudo pip install multiprocessing
  2. Install all of the following libraries:
    Library Installation Instructions
    YOLO version 2 library
    1. Run the following commands to get the YOLO source code:
      git clone --recursive https://github.com/pjreddie/darknet.git
      cd darknet
      git checkout 691debd
    2. Edit the Makefile file by enabling the GPU, and select the correct GPU ARCH parameter according to your machine configuration:
      vi Makefile
      GPU=1
    3. Run the following command to compile YOLO:
      make
    Faster-RCNN Python library
    1. Run the following command to get the Faster R-CNN source code:

      git clone --recursive https://github.com/rbgirshick/py-faster-rcnn.git
    2. In the py-faster-rcnn directory, in the lib folder, run the following command to Compile Cython:
      make
    3. Go to the caffe-fast-rcnn directory under the py-faster-rcnn directory and make a copy of the make configuration file by using the following commands:
      cd caffe-fast-rcnn
      cp Makefile.config.example Makefile.config
    4. Add the following variables to the Makefile.config file:
      USE_CUDNN := 1
      CUDA_DIR := /usr/local/cuda
      PYTHON_INCLUDE := /usr/include/python2.7 \
      /usr/lib/python2.7/dist-packages/numpy/core/include
      PYTHON_LIB:=/usr/lib/x86_64-linux-gnu
      WITH_PYTHON_LAYER := 1
      INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include \
      /usr/include/hdf5/serial
      LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib \
      /usr/lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/hdf5/serial
    5. Run the following command to compile Caffe:
      make
    6. Run the following command to compile pycaffe by using the Python layer:
      make pycaffe
    SSD library
    1. Run the following command to get the SSD source code:
      git clone --recursive https://github.com/weiliu89/caffe.git ~/ssd-caffe
      cd ~/ssd-caffe
      git checkout ssd
    2. Make a copy of the Makefile configuration file by using the following command:
      cp Makefile.config.example Makefile.config
    3. Edit the Makefile configuration file and change the CUDA_ARCH, BLAS, and PYTHON_INCLUDE parameters according to your machine configuration.
    4. Run the following command on one line:
      find . -type f -exec sed -i -e 's^"hdf5.h"^"hdf5/serial/hdf5.h"^g' -e 's^"hdf5_hl.h"^"hdf5/serial/hdf5_hl.h"^g' '{}' \;
    5. Compile the code by using following command:
      make -j8
    6. Compile the Python layer by using the following command:
      make py
    7. Compile the test by using the following command:
      make test -j8
  3. Add the following environment variables to the ~/.bashrc file: YOLO_HOME, FRCNN_HOME, and SSD_HOME. The following text is an example of adding environment variables: YOLO_HOME=~/darknet/ FRCNN_HOME=~/py-faster-rcnn/ SSD_HOME=~/ssd-caffe/.