Sample program

Sample program of Neon-RB5 - Capture and Inference - Model converter

Capture and Inference

  • The example program uses the built-in camera of the Neon-RB5 for image capture and employs the YOLOv6 model for object detection. The SNPE version used is 1.68.0.3932.
  • Download link (md5: 253998b5f8b389914924e70b0545d705)

  • Installation guild

  • Install compile environment

    sudo apt-get update
    sudo apt install --fix-broken 
    sudo apt-get install cmake 
    
  • Untar the file

    tar -zxvf Neon-RB5_sample.tar.gz -C /home/adlink/Desktop
    cd /home/adlink/Desktop/Neon-RB5_sample
    cp /home/adlink/Desktop/Neon-RB5_sample/yolov6n_base_quantized.dlc /home/adlink
    tar -zxvf snpe-1.68.0.3932.tar.gz -C /home/adlink
    
  • modidy .bashrc and add content below

    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/adlink/snpe-1.68.0.3932/lib/aarch64-ubuntu-gcc7.5:/usr/local/lib/
    export ADSP_LIBRARY_PATH="/home/adlink/snpe-1.68.0.3932/lib/dsp;/usr/lib/rfsa/adsp/;/vendor/lib/rfsa/dsp/testsig;/system/lib/rfsa/adsp;/system/vendor/lib/rfsa/adsp;/dsp"
    export PATH=$PATH:/home/adlink/snpe-1.68.0.3932/bin/aarch64-ubuntu-gcc7.5
    
  • Reload the .bashrc setting

    source ~/.bashrc
    
  • Compile the sample

    cd /home/adlink/Desktop/Neon-RB5_sample/samples
    mkdir build && cd build
    cmake .. && make
    
  • Execute the inference sample

    cd /home/adlink/Desktop/Neon-RB5_sample/samples/build
    cp ../../yolo.txt .
    ./yolov6_snpe
    

Procedure of Model Conversion

Required hardware

- x86 Host PC with [ubuntu18.04](https://releases.ubuntu.com/18.04)
- Neon-RB5

The AI model used in the example is Meituan YOLOv6-N Below, we will describe how to convert the downloaded yolov6n.pt file into a dlc file for use with Neon-RB5.

The model conversion process primarily consists of four steps and requires a host PC with Ubuntu 18.04. Steps 1~5 are executed on the host.

Step 1: Environment Setup

sudo apt-get update && sudo apt-get upgrade 
sudo apt install python3-pip -y
pip3 install --upgrade pip
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.6 1
update-alternatives --list python

Step 2: Download conversion tools

wget https://sftp.adlinktech.com/image/Neon-RB5/snpe-1.68.0.zip -O ~/snpe-1.68.0.zip
wget https://sftp.adlinktech.com/image/Neon-RB5/YOLOv6.tar.gz ~/YOLOv6.tar.gz

Step 3: Setup conversion environment

cd ~
unzip -X snpe-1.68.0.zip -d ~
export SNPE_ROOT=/home/adlink/snpe-1.68.0.3932
export PYTHONPATH=$PYTHONPATH:$SNPE_ROOT/lib/python
source $SNPE_ROOT/bin/dependencies.sh
source $SNPE_ROOT/bin/check_python_depends.sh 
pip3 install numpy==1.16.5 sphinx==2.2.1 scipy==1.3.1 matplotlib==3.0.3 scikit-image==0.15.0 protobuf==3.6.0 pyyaml==5.1 
source snpe-1.68.0.3932/bin/check_python_depends.sh 
pip3 install onnx
pip3 install torch 
pip3 install onnxsim

Step 4: Convert *.pt to ONNX

cd ~
tar -zxvf YOLOv6.tar.gzcd ~/YOLOv6/
python3 ./deploy/ONNX/export_onnx.py \
    --weights ./deploy/ONNX/yolov6n.pt \
    --img 288 \
    --batch 1 

Step 5: Convert *.ONNX to *.dlc

cd ~/snpe-1.68.0.3932/bin/x86_64-linux-clang
./snpe-onnx-to-dlc --input_network ~/YOLOv6/deploy/ONNX/yolov6n.onnx  --output_path yolov6n_base_quantized.dlc

Step 6: Replace model in Neon-RB5

Replace *.dlc in /home/adlink/Desktop/Neon-RB5_sample/samples/build

    cd /home/adlink/Desktop/Neon-RB5_sample/samples/build
    ./yolov6_snpe