SDK version supported: 6.2
The latest prebuilt release package complete with python bindings and sample applications can be downloaded from the release section for both x86 and Jetson platforms.
This readme describes how to compile and install DeepStream python bindings (henceforth referred as bindings). This process is mainly useful for making customizations in the bindings and compiling it yourself instead of using the prebuilt versions provided in the release section.
The readme is divided into three main parts:
- DeepStream python bindings
The following dependencies need to be met in order to compile bindings:
Go to https://developer.nvidia.com/deepstream-sdk, download and install Deepstream SDK and its dependencies
To compile bindings on Ubuntu - 20.04 [use python-3.8, python-3.6 will not work] :
apt install python3-gi python3-dev python3-gst-1.0 python-gi-dev git python-dev \
python3 python3-pip python3.8-dev cmake g++ build-essential libglib2.0-dev \
libglib2.0-dev-bin libgstreamer1.0-dev libtool m4 autoconf automake libgirepository1.0-dev libcairo2-dev
Make sure you clone the deepstream_python_apps repo under <DeepStream 6.2 ROOT>/sources: git clone https://github.com/NVIDIA-AI-IOT/deepstream_python_apps
This will create the following directory:
<DeepStream 6.2 ROOT>/sources/deepstream_python_apps
The repository utilizes gst-python and pybind11 submodules. To initializes them, run the following command:
cd /opt/nvidia/deepstream/deepstream/sources/deepstream_python_apps/
git submodule update --init
Following commands ensure we add the new certificates that gst-python git server now uses:
sudo apt-get install -y apt-transport-https ca-certificates -y
sudo update-ca-certificates
Build and install gst-python:
cd 3rdparty/gst-python/
./autogen.sh
make
sudo make install
Python bindings are compiled using CMake. Following commands provide quick cmake configurations for common compilation options:
cd deepstream_python_apps/bindings
mkdir build
cd build
cmake ..
make
Multiple options can be used with cmake as follows:
cmake .. [-D<var>=<value> [-D<var>=<value> [-D<var>=<value> ... ]]]
Var | Default value | Purpose | Available values |
---|---|---|---|
DS_VERSION | 6.2 | Used to determine default deepstream library path | should match to the deepstream version installed on your computer |
PYTHON_MAJOR_VERSION | 3 | Used to set the python version used for the bindings | 3 |
PYTHON_MINOR_VERSION | 8 | Used to set the python version used for the bindings | 6, 8 |
PIP_PLATFORM | linux_x86_64 | Used to select the target architecture to compile the bindings | linux_x86_64, linux_aarch64 |
DS_PATH | /opt/nvidia/deepstream/deepstream-${DS_VERSION} | Path where deepstream libraries are available | Should match the existing deepstream library folder |
Following commands can be used to compile the bindings natively on Jetson devices
cd deepstream_python_apps/bindings
mkdir build
cd build
cmake .. -DPYTHON_MAJOR_VERSION=3 -DPYTHON_MINOR_VERSION=8 \
-DPIP_PLATFORM=linux_aarch64 -DDS_PATH=/opt/nvidia/deepstream/deepstream/
make
This section outlines how to enable cross-compiling of the DeepStreamSDK python bindings for aarch64 using Docker on x86 host.
NOTE: This will only emulate the CPU, so any calls requiring embedded hardware, such as using CUDA or inference are not supported.
We use qemu processor emulator to achieve cross-compilation. Qemu can be installed on the x86 Ubuntu host machine as shown below:
# Install qemu packages
sudo apt-get install qemu binfmt-support qemu-user-static
# Execute the registering scripts
docker run --rm --privileged dockerhub.nvidia.com/multiarch/qemu-user-static --reset -p yes
# Verify qemu installation
docker run --rm -t nvcr.io/nvidia/deepstream-l4t:6.2-samples uname -m
#aarch64
Cross-compilation for Jetson on x86 host requires some low level libraries which can be downloaded using SDK Manager. Follow these steps to obtain these libraries, which are utilized by the docker build later.
- Download and install the NVIDIA SDK manager
- Launch the SDK Manager and login with your NVIDIA developer account.
- Select the platform and target OS (example: Jetson AGX Xavier,
Linux Jetpack 5.1
) and click Continue. - Under
Download & Install Options
change the download folder and selectDownload now, Install later
. Agree to the license terms and click Continue. - Go to the download folder, and run:
# create directories as follows:
mkdir -p deepstream_python_apps/bindings/docker/jetpack_files
# <path/to> would be /opt/nvidia/deepstream/deepstream/sources/deepstream_python_apps/
# where you downloaded the deepstream_python_apps repository
mv ~/Downloads/nvidia/sdkm_downloads/* <path/to>/deepstream_python_apps/bindings/docker/jetpack_files
Below command generates the build container
# cd to bindings dir
cd deepstream_python_apps/bindings
# Make sure you are in deepstream_python_apps/bindings directory
# This command builds the cross-compile docker and adds the mentioned tag
docker build --tag=deepstream-6.2-ubuntu20.04-python-l4t -f qemu_docker/ubuntu-cross-aarch64.Dockerfile .
# Create a directory to mount to the container and store your pyds wheel package in
mkdir export_pyds
# Run the container. Make sure the tag matches the one from Generate step above
docker run -it -v $PWD/export_pyds:/export_pyds deepstream-6.2-ubuntu20.04-python-l4t bash
After the container launches successfully, while inside the cross-compile docker, run following commands:
# cd to /opt/nvidia/deepstream/deepstream/sources/ dir
cd /opt/nvidia/deepstream/deepstream/sources/
# Sync deepstream_python_apps repo from github
git clone https://github.com/NVIDIA-AI-IOT/deepstream_python_apps.git
cd deepstream_python_apps/bindings/
# Initialize submodules
git submodule update --init
# Create build dir and cd to it
mkdir build && cd build
# Run cmake with following options
cmake .. -DPYTHON_MAJOR_VERSION=3 -DPYTHON_MINOR_VERSION=8 -DPIP_PLATFORM=linux_aarch64 -DDS_PATH=/opt/nvidia/deepstream/deepstream
# Build pybind wheel and pyds.so
make -j$(nproc)
# Copy the pyds wheel package to the export dir
cp pyds-*.whl /export_pyds
Build output (pip wheel) is copied to the previously created export_pyds directory (deepstream_python_apps/bindings/export_pyds) on the host machine.
Following commands can be used to install the generated pip wheel.
pip3 install ./pyds-1.1.6-py3-none*.whl
If the wheel installation fails, upgrade the pip using the following command:
python3 -m pip install --upgrade pip
cd apps/deepstream-test1
python3 deepstream_test_1.py <input .h264 file>