galliot-us / smart-social-distancing

Social Distancing Detector using deep learning and capable to run on edge AI devices such as NVIDIA Jetson, Google Coral, and more.
https://neuralet.com
Apache License 2.0
140 stars 39 forks source link

Add Pose Estimation Support for Jetsons #62

Open undefined-references opened 4 years ago

undefined-references commented 4 years ago

I tried to run existing pose estimation algorithms on Jetson devices as what @alpha-carinae29 has done for X86, GPU and Coral. I’m going to write my results and issues here.

undefined-references commented 4 years ago

First, I started with the NVIDIA-AI-IOT/trt_pose project. There are several pretrained models on their repo and I could easily make a dockerfile to run it using their instruction. It is reported to work with 12-22 fps on Jetson Nano but its pose estimation accuracy on frames from surveillance cameras wasn’t good enough for our problem due to the small object sizes and the best result from this project was with the pretrained densenet121_baseline_att_256x256_B model with the frame rate of 9 fps.

undefined-references commented 4 years ago

I continued this task with OpenPifPaf project, as I found out it has the best results for our task. I decided to export openpifpaf model as ONNX format and then generate a TensorRT engine from that onnx model. To export onnx from openpifpaf I used openpifpaf 0.10.0 and this command:

python3 -m openpifpaf.export_onnx --checkpoint resnet50 --outfile resnet50-openpifpaf.onnx --no-polish

I used ONNX-TensorRT repo to convert onnx model. Since I had jetpack 4.3 (TensorRT 6.0.1) installed on my Jetson devices, I used 6.0-full-dims tag. After getting lots of error I used these instruction to build ONNX-TensorRT on a smart-distancing l4t docker for Jetson:

docker run --runtime nvidia --privileged -it -v /usr/include/aarch64-linux-gnu/:/usr/include/aarch64-linux-gnu/ -v $PWD:/repo neuralet/onnx2trt 
git clone https://github.com/onnx/onnx-tensorrt.git
cd onnx-tensorrt
git checkout 6.0-full-dims
mkdir build
cd build
cmake ../ -DCUDA_INCLUDE_DIRS=/usr/local/cuda-10.0/include -DTENSORRT_INCLUDE_DIR=/usr/include/aarch64-linux-gnu -DTENSORRT_LIBRARY_INFER_PLUGIN=/usr/lib/aarch64-linux-gnu/libnvinfer_plugin.so -DTENSORRT_ROOT=/usr/src/tensorrt/ -DGPU_ARCHS="53" -DCUDNN_INCLUDE_DIR=/usr/lib/aarch64-linux-gnu -DTENSORRT_LIBRARY_INFER=/usr/lib/aarch64-linux-gnu/libnvinfer.so
make -j4
make install

ERROR: make[2]: * No rule to make target '/usr/lib/aarch64-linux-gnu/libnvinfer_plugin.so', needed by 'libnvonnxparser.so.6.0.1'. Stop

Solve with:

ln -s /usr/lib/aarch64-linux-gnu/libnvinfer.so.6 /usr/lib/aarch64-linux-gnu/libnvinfer.so
ln -s /usr/lib/aarch64-linux-gnu/libnvinfer_plugin.so.6 /usr/lib/aarch64-linux-gnu/libnvinfer_plugin.so

And finally TensorRT generation was performed using command bellow:

onnx2trt resnet50-openpifpaf -o resnet50-openpifpaf.trt

Tips: