Linux,Unix,BSD/Jetson

[jetson] DeepStream 파이썬 구동 환경 설정 - 예제 실행해보기

채윤아빠 2023. 11. 17. 16:02
728x90
반응형

DeepStream을 정상적으로 설치한 NVIDIA Jetson Orin NX 에서 DeepStream 파이썬 예제를 받아 동작환경을 구성하여 예제를 구동시키는 과정을 정리해 둡니다.

DeepStream Python Examples 예제 실행 시 오류발생

DeepStream Python 예제 저장소를 다음과 같이 복제(clone)합니다.

nvidia@nvidia-OrinNX16G:/opt/nvidia/deepstream/deepstream/sources$ git clone https://github.com/NVIDIA-AI-IOT/deepstream_python_apps
Cloning into 'deepstream_python_apps'...
remote: Enumerating objects: 955, done.
remote: Counting objects: 100% (236/236), done.
remote: Compressing objects: 100% (123/123), done.
remote: Total 955 (delta 147), reused 163 (delta 111), pack-reused 719
Receiving objects: 100% (955/955), 12.71 MiB9.50 MiB/s, done.
Resolving deltas: 100% (605/605), done.

"deepstream_python_apps"을 받은 후, "deepstream-test1" 예제를 그냥 실행하면 다음과 같이 'pyds' 패키지가 설치되지 않았다는 오류가 발생합니다. 이 'pyds' 패키지가 "DeepStream python bindings"에 포함되어 있습니다.

nvidia@nvidia-OrinNX16G:/opt/nvidia/deepstream/deepstream/sources/deepstream_python_apps/apps/deepstream-test1$ python deepstream_test_1.py /opt/nvidia/deepstream/deepstream/samples/streams/sample_720p.h264
Traceback (most recent call last):
  File "deepstream_test_1.py", line 29, in 
    import pyds
ModuleNotFoundError: No module named 'pyds'

DeepStream Python bindings 빌드 및 설치하기

이 문제를 해결하기 위해서는 "bindings" 폴더 안의 "README.me"에 나오는 설명대로 "DeepStream python bindings"를 빌드하여 설치해야만 합니다.

"DeepStream python bindings"를 빌드하기 위하여 다음 패키지를 먼저 설치합니다.

sudo apt install -y python3-gi python3-dev python3-gst-1.0 python-gi-dev git \
    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

연관된 저장소를 다음과 같이 초기화합니다.

nvidia@nvidia-OrinNX16G:~$ cd /opt/nvidia/deepstream/deepstream/sources/deepstream_python_apps/bindings
nvidia@nvidia-OrinNX16G:/opt/nvidia/deepstream/deepstream/sources/deepstream_python_apps/bindings$ git submodule update --init
Submodule '3rdparty/gst-python' (https://github.com/GStreamer/gst-python.git) registered for path '../3rdparty/gst-python'
Submodule '3rdparty/pybind11' (https://github.com/pybind/pybind11.git) registered for path '../3rdparty/pybind11'
Cloning into '/opt/nvidia/deepstream/deepstream-6.3/sources/deepstream_python_apps/3rdparty/gst-python'...
Cloning into '/opt/nvidia/deepstream/deepstream-6.3/sources/deepstream_python_apps/3rdparty/pybind11'...
Submodule path '../3rdparty/gst-python': checked out '1a8f48a6c2911b308231a3843f771a50775cbd2e'
Submodule path '../3rdparty/pybind11': checked out '3b1dbebabc801c9cf6f0953a4c20b904d444f879'

설치를 위해서 필요한 인증 패키지를 설치하고, 최신화합니다.

nvidia@nvidia-OrinNX16G:/opt/nvidia/deepstream/deepstream/sources/deepstream_python_apps/bindings$ sudo update-ca-certificates
Updating certificates in /etc/ssl/certs...
0 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d...
Updating Mono key store
Mono Certificate Store Sync - version 6.8.0.105
Populate Mono certificate store from a concatenated list of certificates.
Copyright 2002, 2003 Motus Technologies. Copyright 2004-2008 Novell. BSD licensed.

Importing into legacy system store:
I already trust 149, your new list has 137
8 previously trusted certificates were removed.
Certificate removed: C=US, O=Google Trust Services LLC, CN=GTS Root R2
Certificate removed: C=NL, O=Staat der Nederlanden, CN=Staat der Nederlanden EV Root CA
Certificate removed: C=ES, O=Agencia Catalana de Certificacio (NIF Q-0801176-I), OU=Serveis Publics de Certificacio, OU=Vegeu https://www.catcert.net/verarrel (c)03, OU=Jerarquia Entitats de Certificacio Catalanes, CN=EC-ACC
Certificate removed: O="Cybertrust, Inc", CN=Cybertrust Global Root
Certificate removed: C=US, O=Google Trust Services LLC, CN=GTS Root R1
Certificate removed: C=GR, O=Hellenic Academic and Research Institutions Cert. Authority, CN=Hellenic Academic and Research Institutions RootCA 2011
Certificate removed: OU=GlobalSign Root CA - R2, O=GlobalSign, CN=GlobalSign
Certificate removed: C=US, O=Network Solutions L.L.C., CN=Network Solutions Certificate Authority
Import process completed.

Importing into BTLS system store:
I already trust 141, your new list has 137
Certificate added: C=US, O=Google Trust Services LLC, CN=GTS Root R1
Certificate added: C=US, O=Google Trust Services LLC, CN=GTS Root R2
Certificate added: C=ES, CN=Autoridad de Certificacion Firmaprofesional CIF A62634068
3 new root certificates were added to your trust store.
8 previously trusted certificates were removed.
Certificate removed: OU=GlobalSign Root CA - R2, O=GlobalSign, CN=GlobalSign
Certificate removed: C=US, O=Google Trust Services LLC, CN=GTS Root R1
Certificate removed: C=US, O=Network Solutions L.L.C., CN=Network Solutions Certificate Authority
Certificate removed: C=GR, O=Hellenic Academic and Research Institutions Cert. Authority, CN=Hellenic Academic and Research Institutions RootCA 2011
Certificate removed: C=NL, O=Staat der Nederlanden, CN=Staat der Nederlanden EV Root CA
Certificate removed: O="Cybertrust, Inc", CN=Cybertrust Global Root
Certificate removed: C=US, O=Google Trust Services LLC, CN=GTS Root R2
Certificate removed: C=ES, O=Agencia Catalana de Certificacio (NIF Q-0801176-I), OU=Serveis Publics de Certificacio, OU=Vegeu https://www.catcert.net/verarrel (c)03, OU=Jerarquia Entitats de Certificacio Catalanes, CN=EC-ACC
Import process completed.
Done
done.

"GStreamer Python binding(gst-python)"을 빌드하여 설치합니다.

cd /opt/nvidia/deepstream/deepstream/sources/deepstream_python_apps/3rdparty/gst-python
./autogen.sh
make
sudo make install

"DeepStream Python binding(pyds)"을 빌드하여 설치합니다. Jetson 보드에서 직접 빌드하므로 "-DPIP_PLATFORM=linux_aarch64" 옵션은 필수적으로 입력해야만 합니다.

cd /opt/nvidia/deepstream/deepstream/sources/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 -j$(nproc)

최종적으로 빌드된 "pyds-1.1.8-py3-none-linux_aarch64.whl" 패키지를 설치합니다.

pip3 install ./pyds-1.1.8-py3-none-linux_aarch64.whl

deepstream-test1 예제 실행

다음은 "deepstream-test1" 예제를 실행한 결과입니다. 예제 실행 전, "xhost" 명령으로 터미널에서도 X 앱을 실행할 수 있도록 권한을 허용해 주어야만 합니다.

nvidia@nvidia-OrinNX16G:~$ export DISPLAY=:0
nvidia@nvidia-OrinNX16G:~$ xhost +
access control disabled, clients can connect from any host
nvidia@nvidia-OrinNX16G:~$ cd /opt/nvidia/deepstream/deepstream/sources/deepstream_python_apps/apps/deepstream-test1
nvidia@nvidia-OrinNX16G:/opt/nvidia/deepstream/deepstream/sources/deepstream_python_apps/apps/deepstream-test1$ python deepstream_test_1.py /opt/nvidia/deepstream/deepstream/samples/streams/sample_720p.h264
Creating Pipeline

Creating Source

Creating H264Parser

Creating Decoder

Creating nv3dsink

Playing file /opt/nvidia/deepstream/deepstream/samples/streams/sample_720p.h264
Adding elements to Pipeline

Linking elements in the Pipeline

Starting pipeline

Opening in BLOCKING MODE
0:00:00.424200977 16340     0x25be5b00 WARN                 nvinfer gstnvinfer.cpp:679:gst_nvinfer_logger: NvDsInferContext[UID 1]: Warning from NvDsInferContextImpl::initialize()  [UID = 1]: Warning, OpenCV has been deprecated. Using NMS for clustering instead of cv::groupRectangles with topK = 20 and NMS Threshold = 0.5
WARNING: [TRT]: Using an engine plan file across different models of devices is not recommended and is likely to affect performance or even cause errors.
0:00:03.977061889 16340     0x25be5b00 INFO                 nvinfer gstnvinfer.cpp:682:gst_nvinfer_logger: NvDsInferContext[UID 1]: Info from NvDsInferContextImpl::deserializeEngineAndBackend()  [UID = 1]: deserialized trt engine from :/opt/nvidia/deepstream/deepstream-6.3/samples/models/Primary_Detector/resnet10.caffemodel_b1_gpu0_int8.engine
INFO: [Implicit Engine Info]: layers num: 3
0   INPUT  kFLOAT input_1         3x368x640
1   OUTPUT kFLOAT conv2d_bbox     16x23x40
2   OUTPUT kFLOAT conv2d_cov/Sigmoid 4x23x40

0:00:04.188815151 16340     0x25be5b00 INFO                 nvinfer gstnvinfer.cpp:682:gst_nvinfer_logger: NvDsInferContext[UID 1]: Info from NvDsInferContextImpl::generateBackendContext()  [UID = 1]: Use deserialized engine model: /opt/nvidia/deepstream/deepstream-6.3/samples/models/Primary_Detector/resnet10.caffemodel_b1_gpu0_int8.engine
0:00:04.219547323 16340     0x25be5b00 INFO                 nvinfer gstnvinfer_impl.cpp:328:notifyLoadModelStatus: [UID 1]: Load new model:dstest1_pgie_config.txt sucessfully
NvMMLiteOpen : Block : BlockType = 261
NvMMLiteBlockCreate : Block : BlockType = 261
Frame Number=0 Number of Objects=10 Vehicle_count=6 Person_count=4
.
.
.
Frame Number=1439 Number of Objects=14 Vehicle_count=11 Person_count=3
Frame Number=1440 Number of Objects=15 Vehicle_count=12 Person_count=3
nvstreammux: Successfully handled EOS for source_id=0
Frame Number=1441 Number of Objects=0 Vehicle_count=0 Person_count=0
End-of-stream

데스크탑 화면에 샘플 영상에 보행자 및 차량이 인식되어 표시되는 화면이 함께 나타납니다.


참고자료