版權聲明:本文爲博主原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處鏈接和本聲明。
本文鏈接:https://blog.csdn.net/dhaduce/article/details/80379792
本人準備使用YOLO進行人臉檢測,硬件設備爲Jetson TX2。查閱YOLO官網,要部署YOLO,首先要安裝CUDA、CUDNN、OPENCV,然後部署Darknet,最後部署YOLO。
本文參考:
https://pjreddie.com/darknet/yolo/
https://pjreddie.com/darknet/install/
https://zhuanlan.zhihu.com/p/35630431
準備工作:
1. 安裝CUDA、CUDNN和OPENCV,由於筆者使用的設備TX2在刷機之後,自帶CUDA9.0和OPENCV3.3.1,並且已經裝過CUDNN,可直接開始安裝Darknet;若沒有CUDNN,可參看:https://blog.csdn.net/dhaduce/article/details/80155121
2. 瞭解YOLO。YOLO將物體檢測作爲迴歸問題求解。基於一個單獨的end-to-end網絡,完成從原始圖像的輸入到物體位置和類別的輸出。簡單的說,就是一個字快。詳細說明可參看官網:https://pjreddie.com/darknet/yolo/;還有論文:https://arxiv.org/abs/1506.02640
部署過程:
1. 部署darknet
git clone https://github.com/pjreddie/darknet.git
cd darknet
sudo gedit Makefile
修改Makefile:
GPU=1
CUDNN=1
OPENCV=1
OPENMP=0
DEBUG=0
ARCH= -gencode arch=compute_53,code=[sm_53,compute_53] \
-gencode arch=compute_62,code=[sm_62,compute_62]
# -gencode arch=compute_20,code=[sm_20,sm_21] \ This one is deprecated?
# This is what I use, uncomment if you know your arch and want to specify
# ARCH= -gencode arch=compute_52,code=compute_52
make -j4
部署成功會出現如下信息:
mkdir -p obj
gcc -I/usr/local/cuda/include/ -Wall -Wfatal-errors -Ofast....
gcc -I/usr/local/cuda/include/ -Wall -Wfatal-errors -Ofast....
gcc -I/usr/local/cuda/include/ -Wall -Wfatal-errors -Ofast....
.....
gcc -I/usr/local/cuda/include/ -Wall -Wfatal-errors -Ofast -lm....
2. 部署YOLOv3
wget https://pjreddie.com/media/files/yolov3.weights //下載已經訓練好的YOLO文件
3. 測試yolov3
./darknet detect cfg/yolov3.cfg yolov3.weights data/dog.jpg
測試完成會出現如下信息:
layer filters size input output
0 conv 32 3 x 3 / 1 416 x 416 x 3 -> 416 x 416 x 32 0.299 BFLOPs
1 conv 64 3 x 3 / 2 416 x 416 x 32 -> 208 x 208 x 64 1.595 BFLOPs
.......
105 conv 255 1 x 1 / 1 52 x 52 x 256 -> 52 x 52 x 255 0.353 BFLOPs
106 detection
truth_thresh: Using default '1.000000'
Loading weights from yolov3.weights...Done!
data/dog.jpg: Predicted in 0.029329 seconds.
dog: 99%
truck: 93%
bicycle: 99%
如安裝了opencv會彈出圖像:
在data文件裏有好多測試圖片
4. 在data文件裏有一些測試圖片,可以替換測試命令中的data/dog.jpg爲data/eagle.jpg
data/person.jpg
data/horses.jpg
data/scream.jpg
data/giraffe.jpg
data/kite.jpg
也可以下載jpg格式的圖片進行測試
5. 調整閾值
YOLO默認的閾值爲.25 可以在測試語句最後面添加 -thresh <閾值> 從而修改閾值
./darknet detect cfg/yolov3.cfg yolov3.weights data/dog.jpg -thresh .1
使用攝像頭進行實時檢測
./darknet detector demo cfg/coco.data cfg/yolov3.cfg yolov3.weights
筆者在進行測試時,出現如下錯誤:
libv4l2: error setting pixformat: Invalid argument
libv4l2: error setting pixformat: Invalid argument
libv4l2: error setting pixformat: Invalid argument
libv4l2: error setting pixformat: Invalid argument
VIDEOIO ERROR: V4L2: Pixel format of incoming image is unsupported by OpenCV
Couldn't connect to webcam.
OPENCV默認採用0號攝像頭,TX2的0號攝像頭是板子上自帶的板上攝像頭,而我們的usb攝像頭是1號,故筆者使用如下代碼,解決了問題:
./darknet detector demo cfg/coco.data cfg/yolov3.cfg yolov3.weights -c 1//使用1號攝像頭
如果上述方法不能解決問題,可以嘗試如下操作:
首先檢查是否安裝了v4l1compat.so
dpkg -S v4l1compat.so
若沒有安裝,則安裝;若找到該文件,則跳過安裝,進行下一步
apt-cache search libv4l
sudo apt-get install libv4l-ruby1.8
然後添加環境變量
export LD_PRELOAD=/usr/lib/aarch64-linux-gnueabihf/libv4l/v4l1compat.so
export LD_PRELOAD=/usr/lib/aarch64-linux-gnueabihf/libv4l/v4l2convert.so
sudo ldconfig
————————————————
版權聲明:本文爲CSDN博主「dhaduce」的原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/dhaduce/article/details/80379792