在JetBot安裝yolov4
2023/09更新
JetBot安裝JetPack4.5,因為啟動GPU很耗電,所以直接使用變壓器供電,外接USB攝影機(/dev/video1),詳細軟體版本,執行jetson_release結果如下。
#jetson_release
Software part of jetson-stats 4.2.3 - (c) 2023, Raffaello Bonghi
Model: NVIDIA Jetson Nano Developer Kit - Jetpack 4.5 [L4T 32.5.0]
NV Power Mode[1]: 5W
Serial Number: [XXX Show with: jetson_release -s XXX]
Hardware:
- P-Number: p3448-0000
- Module: NVIDIA Jetson Nano (4 GB ram)
Platform:
- Distribution: Ubuntu 18.04 Bionic Beaver
- Release: 4.9.201-tegra
jtop:
- Version: 4.2.3
- Service: Active
Libraries:
- CUDA: 10.2.89
- cuDNN: 8.0.0.180
- TensorRT: 7.1.3.0
- VPI: 1.0.12
- Vulkan: 1.2.70
- OpenCV: 4.1.1 - with CUDA: NO
Step1)從https://github.com/AlexeyAB/darknet.git下載程式碼,如以下指令。
$ mkdir yolov
$ cd yolov
$ git clone https://github.com/AlexeyAB/darknet.git
$ cd darknet
Step2)編譯產生執行檔darknet
編輯Makefile,Jetson nano計算能力為53,設定為compute_53,code=[sm_53,compute_53]
$ vi Makefile
GPU=1
CUDNN=1
CUDNN_HALF=1
OPENCV=1
AVX=0
OPENMP=1
LIBSO=1
ZED_CAMERA=0
ZED_CAMERA_v2_8=0
......
ARCH= -gencode arch=compute_53,code=[sm_53,compute_53]
接著執行make編譯產生執行檔darknet
$make
Step3)讓Jetson nano維持最大效能
$ sudo nvpmodel -m 0
$ sudo jetson_clocks
Step4)下載yolov4.weight
$ wget https://github.com/AlexeyAB/darknet/releases/download/darknet_yolo_v3_optimal/yolov4.weights
Step5)辨識圖片,執行指令「./darknet detect cfg/yolov4.cfg yolov4.weights data/eagle.jpg」辨識圖片eagle.jpg,辨識結果自動儲存在preditions.jpg,如下圖。
Step6)辨識影片,以下執行需要Jetson Nano連接HDMI螢幕,執行指令「./darknet detector demo cfg/coco.data cfg/yolov4.cfg yolov4.weights car.mp4 -out_filename car.avi」辨識影片car.mp4,辨識結果儲存到car.avi,如下圖。
影片來自於https://pixabay.com/videos/car-road-transportation-vehicle-2165/
Step7)以下執行需要Jetson Nano連接HDMI螢幕,執行「darknet detector demo cfg/coco.data cfg/yolov4.cfg yolov4.weights -c 1 」開啟USB攝影機(dev/video1)進行即時辨識,「Ctrl+C」中斷執行。
(1)出現nvcc找不到錯誤
#nano ~/.bashrc
新增以下兩行
export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
執行.bashrc
#source ~/.bashrc