본문 바로가기
NVIDIA Jeston/DNN & TensorRT

Jetpack 설치부터 TensorRT Yolo V4 예제 실행하기

by makepluscode 2022. 7. 5.
반응형

NVIDIA Xavier NX devkit 에서 Yolo V4 예제실행

NVIDIA Xavier NX devkit (emmc module) 에 Jetpack 4.6 (L4T R32.6.1) 을 설치하고 TensorRT 가 지원되는 Yolo V4 예제를 설치하고 실행한다.

Jetpack 설치부터 Yolo V4 예제 빠르게 실행하기

테스트 환경

  • NVIDIA Xavier NX devkit (16G emmc module)
  • Jetpack 4.6 (L4T R32.6.1)

BSP image 설치

NVIDIA SDK Manager 또는 BSP 를 직접 build 하여 NVIDIA Xavier NX devkit 에 L4T R32.6.1 를 설치한다. 설치 후, 불필요한 프로그램을 삭제하여 공간을 최대한 확보한다.

$ df | grep mmcblk0p1
/dev/mmcblk0p1  14384136 6486548   7147204  48% /

$ sudo apt-get update
$ sudo apt remove thunderbird libreoffice-* chromium-browser* -y
$ sudo apt autoremove -y

$ df | grep mmcblk0p1
/dev/mmcblk0p1  14384136 5927508   7706244  44% /

Jetpack 설치

터미널에서 apt 명령으로 jetpack 을 설치한다. (약 6G byte 의 공간 필요)

  • nvidia-cuda
  • nvidia-opencv
  • nvidia-cudnn8
  • nvidia-tensorrt
  • nvidia-visionworks
  • nvidia-container
  • nvidia-vpi
  • nvidia-l4t-jetson-multimedia-api
$ apt depends nvidia-jetpack | awk '{print $2}' | xargs -I {} sudo apt install -y {}
Reading package lists... Done
Building dependency tree
Reading state information... Done
nvidia-cuda is already the newest version (4.6-b199).
0 upgraded, 0 newly installed, 0 to remove and 268 not upgraded.
Reading package lists... Done
Building dependency tree
Reading state information... Done
nvidia-opencv is already the newest version (4.6-b199).
0 upgraded, 0 newly installed, 0 to remove and 268 not upgraded.
Reading package lists... Done
Building dependency tree
Reading state information... Done
nvidia-cudnn8 is already the newest version (4.6-b199).
0 upgraded, 0 newly installed, 0 to remove and 268 not upgraded.
Reading package lists... Done
Building dependency tree
Reading state information... Done
nvidia-tensorrt is already the newest version (4.6-b199).
0 upgraded, 0 newly installed, 0 to remove and 268 not upgraded.
Reading package lists... Done
Building dependency tree
Reading state information... Done
nvidia-visionworks is already the newest version (4.6-b199).
0 upgraded, 0 newly installed, 0 to remove and 268 not upgraded.
Reading package lists... Done
Building dependency tree
Reading state information... Done
nvidia-container is already the newest version (4.6-b199).
0 upgraded, 0 newly installed, 0 to remove and 268 not upgraded.
Reading package lists... Done
Building dependency tree
Reading state information... Done
nvidia-vpi is already the newest version (4.6-b199).
0 upgraded, 0 newly installed, 0 to remove and 268 not upgraded.
Reading package lists... Done
Building dependency tree
Reading state information... Done
nvidia-l4t-jetson-multimedia-api is already the newest version (32.6.1-20210916210945).
0 upgraded, 0 newly installed, 0 to remove and 268 not upgraded.
Reading package lists... Done
Building dependency tree
Reading state information... Done
nvidia-l4t-jetson-multimedia-api is already the newest version (32.6.1-20210916210945).
0 upgraded, 0 newly installed, 0 to remove and 268 not upgraded.

설치 후에 파일시스템 사용량이 약 6G byte 정도 증가했다.

$ df | grep mmcblk0p1
/dev/mmcblk0p1  14384136 11783856   1849896  87% /

불필요한 sample 등을 삭제해서 공간을 확보한다.

$ sudo rm -rf /usr/local/cuda/samples \
    /usr/src/cudnn_samples_* \
    /usr/src/tensorrt/data \
    /usr/src/tensorrt/samples \
    /usr/share/visionworks* ~/VisionWorks-SFM*Samples \
    /opt/nvidia/deepstream/deepstream*/samples

nvidia@linux:~$ df | grep mmcblk0p1
/dev/mmcblk0p1  14384136 10863680   2770072  80% /

설치 후에 jtop 으로 CUDA, OpenCV, TensorRT, VPI, cuDNN 등이 설치된 것을 확인할 수 있다.

Yolo V4 예제 실행하기

TensorRT 가 지원되는 Yolo V4 예제를 설치하고 실행한다. 터미널에서 git clone 명령어로 enazoe 의 yolo-tensorrt 저장소를 복제한다.

$ git clone https://github.com/enazoe/yolo-tensorrt.git

Yolo V4 를 실행하기 위해서, configs 디렉토리에 yolov4 weight 파일을 다운로드한다.

$ cd yolo-tensorrt/configs/
$ wget https://github.com/AlexeyAB/darknet/releases/download/darknet_yolo_v3_optimal/yolov4.weights

Yolo V4 를 실행하기 위해서, sample_detector.cpp 를 아래와 같이 수정한다.

yolo-tensorrt$ git diff
diff --git a/samples/sample_detector.cpp b/samples/sample_detector.cpp
index fadafaa..fb8a4f1 100644
--- a/samples/sample_detector.cpp
+++ b/samples/sample_detector.cpp
@@ -32,7 +32,7 @@ int main()
        config_v5.inference_precison = FP32;

        std::unique_ptr<Detector> detector(new Detector());
-       detector->init(config_v5);
+       detector->init(config_v4);

yolo-tensorrt 에서 build 하위 디렉토리를 생성하고 cmake 와 make 를 수행한다.

yolo-tensorrt$ mkdir build && cd build
yolo-tensorrt/build$ cmake ../
yolo-tensorrt/build$ make

생성된 yolo-trt 파일을 실행하면 다음과 같이 Yolo V4 예제가 실행된다.

참고자료

https://github.com/enazoe/yolo-tensorrt

 

GitHub - enazoe/yolo-tensorrt: TensorRT8.Support Yolov5n,s,m,l,x .darknet -> tensorrt. Yolov4 Yolov3 use raw darknet *.weights

TensorRT8.Support Yolov5n,s,m,l,x .darknet -> tensorrt. Yolov4 Yolov3 use raw darknet *.weights and *.cfg fils. If the wrapper is useful to you,please Star it. - GitHub - enazoe/yolo-tensorrt...

github.com

반응형

'NVIDIA Jeston > DNN & TensorRT' 카테고리의 다른 글

Jetson mmdetection 모델 변환 과정  (0) 2023.01.23
Jetson mmdetection 포팅 가이드  (0) 2023.01.21