Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save bharath5673/800a18cc7474ce9c22fda6deaaa98354 to your computer and use it in GitHub Desktop.

Select an option

Save bharath5673/800a18cc7474ce9c22fda6deaaa98354 to your computer and use it in GitHub Desktop.
NVIDIA DeepStream SDK 6.1 / 6.0.1 / 6.0 configuration for YOLO-v5 & YOLO-v7 models

Steps to install Deepstream-6.1 on Ubuntu_20.04-LTS, Run YOLO and YOLO.py


Alt Text

***Needed Ubuntu-20 and nvidia driver 510

Step 1: Install Cuda 11.6


wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-ubuntu2004.pin
sudo mv cuda-ubuntu2004.pin /etc/apt/preferences.d/cuda-repository-pin-60
wget https://developer.download.nvidia.com/compute/cuda/11.6.1/local_installers/cuda-repo-ubuntu2004-11-6-local_11.6.1-510.47.03-1_amd64.deb
sudo dpkg -i cuda-repo-ubuntu2004-11-6-local_11.6.1-510.47.03-1_amd64.deb
sudo apt-key add /var/cuda-repo-ubuntu2004-11-6-local/7fa2af80.pub
sudo apt-get update
sudo apt-get -y install cuda
    
    
    
sudo nano ~/.bashrc
    
#paste these 2 lines at the end of bashrc file
export LD_LIBRARY_PATH="/usr/local/cuda/lib64:/usr/local/cuda-11.6/extras/CUPTI/lib64:$LD_LIBRARY_PATH"
export PATH="/usr/local/cuda-11.6/bin:$PATH"
source ~/.bashrc

Step 1.1: Install Cuda 11.4


tensort 8.2* installations requires cuda-11.4 cuda samples.
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-ubuntu1804.pin
sudo mv cuda-ubuntu1804.pin /etc/apt/preferences.d/cuda-repository-pin-600
wget https://developer.download.nvidia.com/compute/cuda/11.4.1/local_installers/cuda-repo-ubuntu1804-11-4-local_11.4.1-470.57.02-1_amd64.deb
sudo dpkg -i cuda-repo-ubuntu1804-11-4-local_11.4.1-470.57.02-1_amd64.deb
sudo apt-key add /var/cuda-repo-ubuntu1804-11-4-local/7fa2af80.pub
sudo apt-get update
sudo apt-get -y install cuda

Step 2: Install cudnn 8.4.0.27

wget https://developer.nvidia.com/compute/cudnn/secure/8.4.0/local_installers/11.6/cudnn-local-repo-ubuntu2004-8.4.0.27_1.0-1_amd64.deb
sudo dpkg -i cudnn-local-repo-ubuntu2004-8.4.0.27_1.0-1_amd64.deb
sudo apt-get update
sudo apt install libcudnn8=8.4.0.27-1+cuda11.6 libcudnn8-dev=8.4.0.27-1+cuda11.6

Step 3: Installing tensorrt 8.2.5.1

wget https://developer.nvidia.com/compute/machine-learning/tensorrt/secure/8.2.5.1/local_repos/nv-tensorrt-repo-ubuntu2004-cuda11.4-trt8.2.5.1-ga-20220505_1-1_amd64.deb
sudo dpkg -i nv-tensorrt-repo-ubuntu2004-cuda11.4-trt8.2.5.1-ga-20220505_1-1_amd64.deb
sudo apt-key add /var/nv-tensorrt-repo-ubuntu2004-cuda11.4-trt8.2.5.1-ga-20220505/82307095.pub
sudo apt-get update
sudo apt install tensorrt

Step 4: Installing Deepstream 6.1


please Uninstall any previous deepstream versions
sudo apt install \
libssl1.1 \
libgstreamer1.0-0 \
gstreamer1.0-tools \
gstreamer1.0-plugins-good \
gstreamer1.0-plugins-bad \
gstreamer1.0-plugins-ugly \
gstreamer1.0-libav \
libgstrtspserver-1.0-0 \
libjansson4 \
libyaml-cpp-dev \
gcc \
make \
git \
python3

wget https://developer.nvidia.com/deepstream-6.1_6.1.0-1_amd64deb
sudo dpkg -i deepstream-6.1_6.1.0-1_amd64.deb

Step 5 : Install librdkafka (to enable Kafka protocol adaptor for message broker)

git clone https://github.com/edenhill/librdkafka.git
cd librdkafka
#git reset --hard 7101c2310341ab3f4675fc565f64f0967e135a6a
./configure
sudo make -j
sudo make install
sudo mkdir -p /opt/nvidia/deepstream/deepstream-6.1/lib
sudo cp /usr/local/lib/librdkafka* /opt/nvidia/deepstream/deepstream-6.1/lib

Step 6: test deepstream installation

deepstream-app -h

Step 7: lets try YOLO ;)

Step 7.1

(YOLOv5)
cd ~/Downloads 
git clone https://github.com/marcoslucianops/DeepStream-Yolo.git
cd DeepStream-Yolo

CUDA_VER=11.6 make -C nvdsinfer_custom_impl_Yolo


git clone https://github.com/ultralytics/yolov5  # clone
cd yolov5
pip install -r requirements.txt  # install

#here we are testing for yolov5n
wget https://github.com/ultralytics/yolov5/releases/download/v6.1/yolov5n.pt

cd ..
cp -r utils/gen_wts_yoloV5.py yolov5/gen_wts_yoloV5.py
cd yolov5 
python3 gen_wts_yoloV5.py -w yolov5n.pt

#Copy generated cfg and wts files to DeepStream-Yolo folder
cp -r yolov5n.cfg ~/Downloads/DeepStream-Yolo
cp -r yolov5n.wts ~/Downloads/DeepStream-Yolo

Step 7.2

(YOLOv7)
cd ~/Downloads 
git clone https://github.com/marcoslucianops/DeepStream-Yolo.git
cd DeepStream-Yolo

CUDA_VER=11.6 make -C nvdsinfer_custom_impl_Yolo


git clone https://github.com/WongKinYiu/yolov7  # clone
cd yolov7
pip install -r requirements.txt  # install

#here we are testing for yolov5n
wget hhttps://github.com/WongKinYiu/yolov7/releases/download/v0.1/yolov7.pt

cd ..
cp -r utils/gen_wts_yoloV7.py yolov7/gen_wts_yoloV7.py
cd yolov7 
python3 gen_wts_yoloV7.py -w yolov7.pt

#Copy generated cfg and wts files to DeepStream-Yolo folder
cp -r yolov7n.cfg ~/Downloads/DeepStream-Yolo
cp -r yolov7n.wts ~/Downloads/DeepStream-Yolo

Step 8: Change the deepstream_app_config.txt file

...
[primary-gie]
enable=1
gpu-id=0
gie-unique-id=1
nvbuf-memory-type=0
config-file=config_infer_primary_yoloV5.txt
#or
config-file=config_infer_primary_yoloV7.txt

...

#run
deepstream-app -c deepstream_app_config.txt

Step 9:Installing python binding


wget https://github.com/NVIDIA-AI-IOT/deepstream_python_apps/releases/download/v1.1.2/pyds-1.1.2-py3-none-linux_x86_64.whl
pip3 install ./pyds-1.1.2-py3-none-linux_x86_64.whl
# or
python3.8 -m pip install ./pyds-1.1.2-py3-none-linux_x86_64.whl

sudo apt install libcairo2-dev libxt-dev libgirepository1.0-dev
pip install pycairo PyGObject

Step 10: Running yolo.py


wget https://raw.githubusercontent.com/bharath5673/Deepstream/main/deepstream-yolo.py
python3 deepstream-yolo.py file:///opt/nvidia/deepstream/deepstream/samples/streams/sample_1080p_h264.mp4

Step 11: Running yolo-Tracker.py


wget https://raw.githubusercontent.com/bharath5673/Deepstream/main/deepstream-yolo-track.py
wget https://raw.githubusercontent.com/bharath5673/Deepstream/main/tracker_config.txt
python3 deepstream-yolo-track.py /opt/nvidia/deepstream/deepstream/samples/streams/sample_720p.h264
@Sina-Asgari
Copy link
Copy Markdown

Hello
how should i change the config file to pass onnx file format instead of pt?
Thanks

@Guydada
Copy link
Copy Markdown

Guydada commented Oct 27, 2022

This is very awesome. You are the only one who clearly made me get this to work. Thank you very much!

@bharath5673
Copy link
Copy Markdown
Author

@aafaqin
Copy link
Copy Markdown

aafaqin commented Dec 27, 2022

why did you install 2 Cuda? 11.6 and 11.4?

@Gobishangar1
Copy link
Copy Markdown

can i install deepstream on windows

@bharath5673
Copy link
Copy Markdown
Author

No

@utkarsh23kushwaha
Copy link
Copy Markdown

the link to yolo.py is not working now could you please reshare the working link

@prince0310
Copy link
Copy Markdown

prince0310 commented Jul 14, 2023

/usr/include/x86_64-linux-gnu/NvInferRuntimeCommon.h:19:10: fatal error: cuda_runtime_api.h: No such file or directory

i don't have this file in directory

@IGR2014
Copy link
Copy Markdown

IGR2014 commented Apr 6, 2024

I'm getting following error:
dpkg-deb: error: 'deepstream-6.1_6.1.0-1_amd64.deb' is not a Debian format archive

@IGR2014
Copy link
Copy Markdown

IGR2014 commented Apr 6, 2024

I'm getting following error: dpkg-deb: error: 'deepstream-6.1_6.1.0-1_amd64.deb' is not a Debian format archive

Found the problem. F***ing nVidia gives login page instead of .deb package:

5.730 --2024-04-06 13:36:00--  https://developer.nvidia.com/deepstream-6.1_6.1.0-1_arm64deb
5.739 Resolving developer.nvidia.com (developer.nvidia.com)... 152.199.20.126, 152.199.20.126
5.807 Connecting to developer.nvidia.com (developer.nvidia.com)|152.199.20.126|:443... connected.
6.011 HTTP request sent, awaiting response... 301 Moved Permanently
6.143 Location: https://developer.nvidia.com/downloads/deepstream-6.1_6.1.0-1_arm64deb [following]
6.144 --2024-04-06 13:36:01--  https://developer.nvidia.com/downloads/deepstream-6.1_6.1.0-1_arm64deb
6.144 Reusing existing connection to developer.nvidia.com:443.
6.144 HTTP request sent, awaiting response... 302 Found
6.864 Location: https://developer.nvidia.com/login [following]
6.864 --2024-04-06 13:36:02--  https://developer.nvidia.com/login
6.864 Reusing existing connection to developer.nvidia.com:443.
6.864 HTTP request sent, awaiting response... 200 OK
7.457 Length: 8533 (8.3K) [text/html]
7.457 Saving to: ‘deepstream-6.1_6.1.0-1_arm64deb’
7.473
7.473      0K ........                                              100% 1.01M=0.008s
7.473
7.473 2024-04-06 13:36:02 (1.01 MB/s) - ‘deepstream-6.1_6.1.0-1_arm64deb’ saved [8533/8533]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment