xubuntu20.04
kernel:5.8.0-59-generic
nvnidia driver:
NVRM version: NVIDIA UNIX x86_64 Kernel Module 460.80 ($ cat /proc/driver/nvidia/version)
display card: rtx3070
cpu: intel 11800H
參考:
Face Mask Detection using darknet’s YOLOv3
路徑:
$ cd ~/object_recognition/darknet/darknet_alexeyAB/ubuntu_mask/
開始:
- 下載口罩dataset: 下載
- Train-Test Split: 建立train_folder和test_folder
- 將VOC轉成Yolo格式: 該作者提供程式轉換xml_to_yolo.xml Usage:
- 必需自訂5個的檔案
- face_maske.names (*.names)
- face_maske.data (*.data)
- face_mask.cfg (*.cfg, copy the yolov3.cfg and modify it)
- train.txt 把所有訓練圖的絕對路徑寫到裡面
- test.txt 把所有測試圖的絕對路徑寫到裡面
這兩個folder再各自建立annomations和images
下載的檔案,把90%放在train_folder,10%放在test_folder
(比例可調整,也有看到寫8:2的文章)
以這個範列來說,
maksssksksss0~maksssksksss85.png放在test_folder/images
maksssksksss0~maksssksksss85.xml放在test_folder/annotations
maksssksksss86~maksssksksss783.png放在train_folder/images
maksssksksss86~maksssksksss783.xml放在train_folder/annotations
$ python3 xml_to_yolo.py --input annotations/ --output images/
yolo格式的txt檔會放在images (也必需放在images裡)
xml_to_yolo.py
...
...
'with_mask' : '0', (face_mask.names, Good)
'without_mask' : '1', (face_mask.names, Bad)
'mask_weared_incorrect' : '1' (face_mask.names, Bad)
...
...
Good
Bad
classes = 2 (number of face_maske.names, Good and Bad)
train = ubuntu_mask/data/train.txt
valid = ubuntu_mask/data/test.txt
names = ubuntu_mask/data/face_mask.names
backup = backup/
batch=64
subdivisions=64
width=416 (好像是32倍數)
height=416 (好像是32倍數)
channels=3
momentum=0.9
decay=0.0005
angle=0
saturation = 1.5
exposure = 1.5
hue=.1
learning_rate=0.001
burn_in=1000
max_batches = 4000 (classes*2000)
policy=steps
steps=3200,3600 (max_batches*0.8, max_batches*0.9)
scales=.1,.1
...
...
...
[convolutional](共三組,分別用[yolo]的mask0,1,2和3,4,5和6,7,8當keyword找)
size=1
stride=1
pad=1
filters=21 (filters=(classes + 5) * 3)
activation=linear
[yolo] (共三組,分別用0,1,2和3,4,5和6,7,8當keyword找)
mask = 0,1,2
anchors = 10,13, 16,30, 33,23, 30,61, 62,45, 59,119, 116,90, 156,198, 373,326
classes=2
num=9
jitter=.3
ignore_thresh = .7
truth_thresh = 1
random=1
/home/ubuntu/object_recognition/darknet/darknet_alexeyAB/ubuntu_mask/image/train_folder/images/maksssksksss86.png
...
...
/home/ubuntu/object_recognition/darknet/darknet_alexeyAB/ubuntu_mask/image/train_folder/images/maksssksksss783.png
/home/ubuntu/object_recognition/darknet/darknet_alexeyAB/ubuntu_mask/image/test_folder/images/maksssksksss0.png
...
...
...
/home/ubuntu/object_recognition/darknet/darknet_alexeyAB/ubuntu_mask/image/test_folder/images/maksssksksss85.png
最後樹狀圖約如下:
$ tree -L 3 darknet_alexeyAB/ubuntu_mask/
darknet_alexeyAB/ubuntu_mask/
├── data
│ ├── face_mask.cfg
│ ├── face_mask.data
│ ├── face_mask.names
│ ├── test.txt
│ └── train.txt
├── image
│ ├── test_folder
│ │ ├── annotations (*.xml)
│ │ ├── images (png images for test)
│ │ └── xml_to_yolo.py (只是方便用)
│ └── train_folder
│ ├── annotations (*.xml)
│ ├── images (png images for train)
│ └── xml_to_yolo.py (只是方便用)
└── tools (可以不用)
├── show_bb.py
└── xml_to_yolo.py
訓練:
./darknet detector train ubuntu_mask/data/face_mask.data ubuntu_mask/data/face_mask.cfg -dont_show -i 0 -map
執行: (It will open the camera)./darknet detector demo ubuntu_mask/data/face_mask.data ubuntu_mask/data/face_mask.cfg -i 0 -thresh 0.25
跑了約5個小時darknet53.conv.74還不是很瞭解訓練時到底要不要用...
ref:
1. Face Mask Detection using darknet’s YOLOv3
2. 建立自己的YOLO辨識模型–以柑橘辨識為例
3. YOLO 簡單訓練自己的資料集
沒有留言:
張貼留言