This project is intended to build and deploy an scene detection application onto Qualcomm Robotics development Kit (RB5) that detects whether the bot is in an indoor or outdoor environment and takes necessary actions. The source code is arranged in the following directories:
- src : This directory contains code for the main application which act as a driver for capturing the video stream from camera and decide on the movement of bot according to the scene in which bot is present.
- snpe_shared_library : This directory contains the code for loading and inferring DLC model.
- artifacts : This directory contains pytorch, ONNX and DLC model of Scene detection.
-
A Linux workstation with Ubuntu 18.04.
-
Install Android Platform tools (ADB, Fastboot)
-
Download and install the SDK Manager
-
Flash the RB5 firmware image on to the board
-
Setup the Network
-
Setup the SNPE SDK in the host system. You can download SNPE SDK here.
-
Setup pytorch and ONNX on the host system.
-
Setup opencv from source for cpp support on RB5.
-
Turtlebot burger is assembled, operational and is connected to RB3
To get a local copy up and running follow these steps.
- Clone the project repository from the gitlab to host system.
git clone <URL of REPO>
cd rb5-scene-detectionCreate a directory named rb5-scene-detection in the home directory of RB5.
adb shell
mkdir /home/rb5-scene-detection
exit- Push the directories/files named bot_py, include, src and artifacts from project directory to newly created directory in RB5.
adb push artifacts /home/rb5-scene-detection
adb push bot_py /home/rb5-scene-detection
adb push src /home/rb5-scene-detection
adb push include /home/rb5-scene-detectionIn this project we have created a scene detection model using pytorch. As SNPE doesn’t support pytorch models directly, we have to convert pytorch model to ONNX first. Later on we will use snpe-onnx-to-dlc script provided by SNPE SDK to convert onnx model to DLC. A python script to convert the pytorch model to onnx is present in the python_scripts directory. A pre-trained pytorch scene detection model is placed in the artifacts directory.
- Run the python script to convert pytorch model to ONNX
python pytorch_to_onnx.pyIf successful, ONNX model (best_model.onnx) will be generated in artifacts.
- Convert the onnx model to dlc by executing the following command:
snpe-onnx-to-dlc --input_network artifacts/best_model.onnx -o artifacts/best_model.dlc- Push the dlc model to RB5
adb push artifacts/best_model.dlc /home/rb5-scene-detection/artifactsThis shared library can be cross compiled by following steps (If toolchain for cross compilation is not present in your system, skip step 2 and 3):
- From project directory change the directory to that of shared library source
cd snpe_shared_library- Run the Makefile (Note: Make sure App Tool chain SDK for cross compilation and setup for SNPE SDK in the host system is ready)
make -f Makefile.aarch64-linux-gcc4.9 -
Once the build is successful, libSNPEScene.so will be created in obj/local/aarch64-linux-gcc4.9/
-
Push the shared library .so file to RB5
adb push obj/local/aarch64-linux-gcc4.9/libSNPESceneso /lib
adb push $SNPE_ROOT/lib/aarch64-linux-gcc4.9/libSNPE.so /lib- Access RB5 through adb and change directory to /home/rb5-scene-detection
adb shell
cd /home/rb5-scene-detection- Execute the following command for compiling main application
g++ src/*.cpp -o rb5-scene-detection -I ./include/ -I $SNPE_ROOT/include/zdl/ -lSNPE -lSNPEScene `pkg-config --cflags --libs opencv`- If compilation is successful, an executable named rb5-scene-detection will be generated.
The executable takes 3 arguments. The Path to DLC model is compulsory and the other 2 arguments are optional. Arguments supported are as follows:
- -h : Help
- -d : Path to the DLC file
- -r : The runtime to be used [gpu, dsp, cpu] (cpu is default).
- -c : Camera id of video stream (default is 0)
Follow the below steps for running the application:
- Access the RB5 through adb
adb shell
cd /home/rb5-scene-detection- To run the application in CPU mode execute the following command in shell
./rb5-scene-detection -d <PATH-TO_DLC> -r cpu -c 0