1、YOLO V4模型訓練的基本思路
所有機器學習涉及模型訓練,一般都有訓練集、驗證集、測試集,因此需要准備數據集。有了數據集,再調用訓練的算法,獲取訓練的結果。v3、v4模型訓練方法相同。
2、YOLO V4模型訓練的體驗
利用已有數據,體驗一下模型訓練的各個步驟。
網址:https://pjreddie.com/darknet/yolo/
2.1、YOLO模型訓練的數據集格式
YOLO訓練所要求的數據格式是PASCAL VOC或者COCO等標准數據集格式。
darknet\build\darknet\x64\data\voc目錄下,有一個voc_label.py文件,用於數據轉換。涉及的數據集的格式為PASCAL VOC格式。
關於PASCAL VOC格式的介紹,參見:
-
《PASCAL VOC數據集的標注格式》(https://zhuanlan.zhihu.com/p/33405410);
-
《計算機視覺標准數據集整理—PASCAL VOC數據集》(https://blog.csdn.net/xingwei_09/article/details/79142558);
-
《VOC 2007數據集結構》(https://blog.csdn.net/qq_38273984/article/details/90749314)
關於Annotations的xml文件中,圖像size的depth屬性,含義為通道數,RGB圖像,值為3。參見:https://blog.csdn.net/qq_18343569/article/details/47830503。
2.2、構造VOC目錄結構
按照上面引用網文的說法,構造基本的目錄結構:Annotations、JPEGImages以及ImageSets/Main。
我這邊正好搞到了VOC2012的訓練/驗證的數據集。
如果要下載,地址:https://pjreddie.com/projects/pascal-voc-dataset-mirror/,文件都點大。
先將VOC2012數據集復制到darknet\build\darknet\x64\data\voc目錄下,結構如下:
darknet\build\darknet\x64\data\voc\VOCdevkit
darknet\build\darknet\x64\data\voc\VOCdevkit\VOC2012
darknet\build\darknet\x64\data\voc\VOCdevkit\VOC2012\...
...
2.3、執行voc_label.py文件
voc_label.py文件的解析,可參考:《YOLO_DarkNet_解析之旅_voc_label.py的解析》(https://blog.csdn.net/Willen/article/details/83868164)。
由於我使用VOC2012數據集,沒有VOC2007,ImageSets/Main中,只有train,val和trainval文件,因此,需要修改voc_label.py文件。
#line7 修改
sets=[('2012', 'train'), ('2012', 'val'), ('2007', 'train'), ('2007', 'val'), ('2007', 'test')]
#==>
sets=[('2012', 'train'), ('2012', 'val'),('2012', 'trainval')]
#否則,報錯:
FileNotFoundError: [Errno 2] No such file or directory: 'VOCdevkit/VOC2007/ImageSets/Main/train.txt'
然后,執行voc_label.py文件,在AnaConda環境下,執行下列語句:
(tensorflow) E:\workspace\darknet\build\darknet\x64\data\voc>python voc_label.py
獲取下列文件:
darknet\build\darknet\x64\data\voc\2012_train.txt
darknet\build\darknet\x64\data\voc\2012_val.txt
darknet\build\darknet\x64\data\voc\2012_trainval.txt
darknet\build\darknet\x64\data\voc\VOCdevkit\VOC2012\labels目錄及文件
2.4、模型訓練
首先,修改darknet/build/darknet/x64/data中的voc.data。修改train和valid這兩行的數據文件路徑。
classes= 20
train = data/voc/2012_train.txt
valid = data/voc/2012_val.txt
#difficult = data/difficult_2007_test.txt
names = data/voc.names
backup = backup/
然后執行下列語句:
darknet.exe detector train data/voc.data cfg/yolov4.cfg yolov4.weights
最后一個參數為預訓練權重文件,應該使用只包含卷積層的預訓練權重文件,下載地址:https://pjreddie.com/media/files/darknet53.conv.74。
我這里擔心訓練時間過長,偷懶了,直接用yolov4.weights。
運行結果如下:
E:\workspace\darknet\build\darknet\x64>darknet.exe detector train data/voc.data cfg/yolov4.cfg yolov4.weights
GPU isn't used
Used AVX
Used FMA & AVX2
OpenCV version: 4.2.0
yolov4
mini_batch = 8, batch = 64, time_steps = 1, train = 1
layer filters size/strd(dil) input output
0 conv 32 3 x 3/ 1 608 x 608 x 3 -> 608 x 608 x 32 0.639 BF
1 conv 64 3 x 3/ 2 608 x 608 x 32 -> 304 x 304 x 64 3.407 BF
2 conv 64 1 x 1/ 1 304 x 304 x 64 -> 304 x 304 x 64 0.757 BF
3 route 1 -> 304 x 304 x 64
4 conv 64 1 x 1/ 1 304 x 304 x 64 -> 304 x 304 x 64 0.757 BF
5 conv 32 1 x 1/ 1 304 x 304 x 64 -> 304 x 304 x 32 0.379 BF
6 conv 64 3 x 3/ 1 304 x 304 x 32 -> 304 x 304 x 64 3.407 BF
7 Shortcut Layer: 4, wt = 0, wn = 0, outputs: 304 x 304 x 64 0.006 BF
8 conv 64 1 x 1/ 1 304 x 304 x 64 -> 304 x 304 x 64 0.757 BF
9 route 8 2 -> 304 x 304 x 128
10 conv 64 1 x 1/ 1 304 x 304 x 128 -> 304 x 304 x 64 1.514 BF
11 conv 128 3 x 3/ 2 304 x 304 x 64 -> 152 x 152 x 128 3.407 BF
12 conv 64 1 x 1/ 1 152 x 152 x 128 -> 152 x 152 x 64 0.379 BF
13 route 11 -> 152 x 152 x 128
14 conv 64 1 x 1/ 1 152 x 152 x 128 -> 152 x 152 x 64 0.379 BF
15 conv 64 1 x 1/ 1 152 x 152 x 64 -> 152 x 152 x 64 0.189 BF
16 conv 64 3 x 3/ 1 152 x 152 x 64 -> 152 x 152 x 64 1.703 BF
17 Shortcut Layer: 14, wt = 0, wn = 0, outputs: 152 x 152 x 64 0.001 BF
18 conv 64 1 x 1/ 1 152 x 152 x 64 -> 152 x 152 x 64 0.189 BF
19 conv 64 3 x 3/ 1 152 x 152 x 64 -> 152 x 152 x 64 1.703 BF
20 Shortcut Layer: 17, wt = 0, wn = 0, outputs: 152 x 152 x 64 0.001 BF
21 conv 64 1 x 1/ 1 152 x 152 x 64 -> 152 x 152 x 64 0.189 BF
22 route 21 12 -> 152 x 152 x 128
23 conv 128 1 x 1/ 1 152 x 152 x 128 -> 152 x 152 x 128 0.757 BF
24 conv 256 3 x 3/ 2 152 x 152 x 128 -> 76 x 76 x 256 3.407 BF
25 conv 128 1 x 1/ 1 76 x 76 x 256 -> 76 x 76 x 128 0.379 BF
26 route 24 -> 76 x 76 x 256
27 conv 128 1 x 1/ 1 76 x 76 x 256 -> 76 x 76 x 128 0.379 BF
28 conv 128 1 x 1/ 1 76 x 76 x 128 -> 76 x 76 x 128 0.189 BF
29 conv 128 3 x 3/ 1 76 x 76 x 128 -> 76 x 76 x 128 1.703 BF
30 Shortcut Layer: 27, wt = 0, wn = 0, outputs: 76 x 76 x 128 0.001 BF
31 conv 128 1 x 1/ 1 76 x 76 x 128 -> 76 x 76 x 128 0.189 BF
32 conv 128 3 x 3/ 1 76 x 76 x 128 -> 76 x 76 x 128 1.703 BF
33 Shortcut Layer: 30, wt = 0, wn = 0, outputs: 76 x 76 x 128 0.001 BF
34 conv 128 1 x 1/ 1 76 x 76 x 128 -> 76 x 76 x 128 0.189 BF
35 conv 128 3 x 3/ 1 76 x 76 x 128 -> 76 x 76 x 128 1.703 BF
36 Shortcut Layer: 33, wt = 0, wn = 0, outputs: 76 x 76 x 128 0.001 BF
37 conv 128 1 x 1/ 1 76 x 76 x 128 -> 76 x 76 x 128 0.189 BF
38 conv 128 3 x 3/ 1 76 x 76 x 128 -> 76 x 76 x 128 1.703 BF
39 Shortcut Layer: 36, wt = 0, wn = 0, outputs: 76 x 76 x 128 0.001 BF
40 conv 128 1 x 1/ 1 76 x 76 x 128 -> 76 x 76 x 128 0.189 BF
41 conv 128 3 x 3/ 1 76 x 76 x 128 -> 76 x 76 x 128 1.703 BF
42 Shortcut Layer: 39, wt = 0, wn = 0, outputs: 76 x 76 x 128 0.001 BF
43 conv 128 1 x 1/ 1 76 x 76 x 128 -> 76 x 76 x 128 0.189 BF
44 conv 128 3 x 3/ 1 76 x 76 x 128 -> 76 x 76 x 128 1.703 BF
45 Shortcut Layer: 42, wt = 0, wn = 0, outputs: 76 x 76 x 128 0.001 BF
46 conv 128 1 x 1/ 1 76 x 76 x 128 -> 76 x 76 x 128 0.189 BF
47 conv 128 3 x 3/ 1 76 x 76 x 128 -> 76 x 76 x 128 1.703 BF
48 Shortcut Layer: 45, wt = 0, wn = 0, outputs: 76 x 76 x 128 0.001 BF
49 conv 128 1 x 1/ 1 76 x 76 x 128 -> 76 x 76 x 128 0.189 BF
50 conv 128 3 x 3/ 1 76 x 76 x 128 -> 76 x 76 x 128 1.703 BF
51 Shortcut Layer: 48, wt = 0, wn = 0, outputs: 76 x 76 x 128 0.001 BF
52 conv 128 1 x 1/ 1 76 x 76 x 128 -> 76 x 76 x 128 0.189 BF
53 route 52 25 -> 76 x 76 x 256
54 conv 256 1 x 1/ 1 76 x 76 x 256 -> 76 x 76 x 256 0.757 BF
55 conv 512 3 x 3/ 2 76 x 76 x 256 -> 38 x 38 x 512 3.407 BF
56 conv 256 1 x 1/ 1 38 x 38 x 512 -> 38 x 38 x 256 0.379 BF
57 route 55 -> 38 x 38 x 512
58 conv 256 1 x 1/ 1 38 x 38 x 512 -> 38 x 38 x 256 0.379 BF
59 conv 256 1 x 1/ 1 38 x 38 x 256 -> 38 x 38 x 256 0.189 BF
60 conv 256 3 x 3/ 1 38 x 38 x 256 -> 38 x 38 x 256 1.703 BF
61 Shortcut Layer: 58, wt = 0, wn = 0, outputs: 38 x 38 x 256 0.000 BF
62 conv 256 1 x 1/ 1 38 x 38 x 256 -> 38 x 38 x 256 0.189 BF
63 conv 256 3 x 3/ 1 38 x 38 x 256 -> 38 x 38 x 256 1.703 BF
64 Shortcut Layer: 61, wt = 0, wn = 0, outputs: 38 x 38 x 256 0.000 BF
65 conv 256 1 x 1/ 1 38 x 38 x 256 -> 38 x 38 x 256 0.189 BF
66 conv 256 3 x 3/ 1 38 x 38 x 256 -> 38 x 38 x 256 1.703 BF
67 Shortcut Layer: 64, wt = 0, wn = 0, outputs: 38 x 38 x 256 0.000 BF
68 conv 256 1 x 1/ 1 38 x 38 x 256 -> 38 x 38 x 256 0.189 BF
69 conv 256 3 x 3/ 1 38 x 38 x 256 -> 38 x 38 x 256 1.703 BF
70 Shortcut Layer: 67, wt = 0, wn = 0, outputs: 38 x 38 x 256 0.000 BF
71 conv 256 1 x 1/ 1 38 x 38 x 256 -> 38 x 38 x 256 0.189 BF
72 conv 256 3 x 3/ 1 38 x 38 x 256 -> 38 x 38 x 256 1.703 BF
73 Shortcut Layer: 70, wt = 0, wn = 0, outputs: 38 x 38 x 256 0.000 BF
74 conv 256 1 x 1/ 1 38 x 38 x 256 -> 38 x 38 x 256 0.189 BF
75 conv 256 3 x 3/ 1 38 x 38 x 256 -> 38 x 38 x 256 1.703 BF
76 Shortcut Layer: 73, wt = 0, wn = 0, outputs: 38 x 38 x 256 0.000 BF
77 conv 256 1 x 1/ 1 38 x 38 x 256 -> 38 x 38 x 256 0.189 BF
78 conv 256 3 x 3/ 1 38 x 38 x 256 -> 38 x 38 x 256 1.703 BF
79 Shortcut Layer: 76, wt = 0, wn = 0, outputs: 38 x 38 x 256 0.000 BF
80 conv 256 1 x 1/ 1 38 x 38 x 256 -> 38 x 38 x 256 0.189 BF
81 conv 256 3 x 3/ 1 38 x 38 x 256 -> 38 x 38 x 256 1.703 BF
82 Shortcut Layer: 79, wt = 0, wn = 0, outputs: 38 x 38 x 256 0.000 BF
83 conv 256 1 x 1/ 1 38 x 38 x 256 -> 38 x 38 x 256 0.189 BF
84 route 83 56 -> 38 x 38 x 512
85 conv 512 1 x 1/ 1 38 x 38 x 512 -> 38 x 38 x 512 0.757 BF
86 conv 1024 3 x 3/ 2 38 x 38 x 512 -> 19 x 19 x1024 3.407 BF
87 conv 512 1 x 1/ 1 19 x 19 x1024 -> 19 x 19 x 512 0.379 BF
88 route 86 -> 19 x 19 x1024
89 conv 512 1 x 1/ 1 19 x 19 x1024 -> 19 x 19 x 512 0.379 BF
90 conv 512 1 x 1/ 1 19 x 19 x 512 -> 19 x 19 x 512 0.189 BF
91 conv 512 3 x 3/ 1 19 x 19 x 512 -> 19 x 19 x 512 1.703 BF
92 Shortcut Layer: 89, wt = 0, wn = 0, outputs: 19 x 19 x 512 0.000 BF
93 conv 512 1 x 1/ 1 19 x 19 x 512 -> 19 x 19 x 512 0.189 BF
94 conv 512 3 x 3/ 1 19 x 19 x 512 -> 19 x 19 x 512 1.703 BF
95 Shortcut Layer: 92, wt = 0, wn = 0, outputs: 19 x 19 x 512 0.000 BF
96 conv 512 1 x 1/ 1 19 x 19 x 512 -> 19 x 19 x 512 0.189 BF
97 conv 512 3 x 3/ 1 19 x 19 x 512 -> 19 x 19 x 512 1.703 BF
98 Shortcut Layer: 95, wt = 0, wn = 0, outputs: 19 x 19 x 512 0.000 BF
99 conv 512 1 x 1/ 1 19 x 19 x 512 -> 19 x 19 x 512 0.189 BF
100 conv 512 3 x 3/ 1 19 x 19 x 512 -> 19 x 19 x 512 1.703 BF
101 Shortcut Layer: 98, wt = 0, wn = 0, outputs: 19 x 19 x 512 0.000 BF
102 conv 512 1 x 1/ 1 19 x 19 x 512 -> 19 x 19 x 512 0.189 BF
103 route 102 87 -> 19 x 19 x1024
104 conv 1024 1 x 1/ 1 19 x 19 x1024 -> 19 x 19 x1024 0.757 BF
105 conv 512 1 x 1/ 1 19 x 19 x1024 -> 19 x 19 x 512 0.379 BF
106 conv 1024 3 x 3/ 1 19 x 19 x 512 -> 19 x 19 x1024 3.407 BF
107 conv 512 1 x 1/ 1 19 x 19 x1024 -> 19 x 19 x 512 0.379 BF
108 max 5x 5/ 1 19 x 19 x 512 -> 19 x 19 x 512 0.005 BF
109 route 107 -> 19 x 19 x 512
110 max 9x 9/ 1 19 x 19 x 512 -> 19 x 19 x 512 0.015 BF
111 route 107 -> 19 x 19 x 512
112 max 13x13/ 1 19 x 19 x 512 -> 19 x 19 x 512 0.031 BF
113 route 112 110 108 107 -> 19 x 19 x2048
114 conv 512 1 x 1/ 1 19 x 19 x2048 -> 19 x 19 x 512 0.757 BF
115 conv 1024 3 x 3/ 1 19 x 19 x 512 -> 19 x 19 x1024 3.407 BF
116 conv 512 1 x 1/ 1 19 x 19 x1024 -> 19 x 19 x 512 0.379 BF
117 conv 256 1 x 1/ 1 19 x 19 x 512 -> 19 x 19 x 256 0.095 BF
118 upsample 2x 19 x 19 x 256 -> 38 x 38 x 256
119 route 85 -> 38 x 38 x 512
120 conv 256 1 x 1/ 1 38 x 38 x 512 -> 38 x 38 x 256 0.379 BF
121 route 120 118 -> 38 x 38 x 512
122 conv 256 1 x 1/ 1 38 x 38 x 512 -> 38 x 38 x 256 0.379 BF
123 conv 512 3 x 3/ 1 38 x 38 x 256 -> 38 x 38 x 512 3.407 BF
124 conv 256 1 x 1/ 1 38 x 38 x 512 -> 38 x 38 x 256 0.379 BF
125 conv 512 3 x 3/ 1 38 x 38 x 256 -> 38 x 38 x 512 3.407 BF
126 conv 256 1 x 1/ 1 38 x 38 x 512 -> 38 x 38 x 256 0.379 BF
127 conv 128 1 x 1/ 1 38 x 38 x 256 -> 38 x 38 x 128 0.095 BF
128 upsample 2x 38 x 38 x 128 -> 76 x 76 x 128
129 route 54 -> 76 x 76 x 256
130 conv 128 1 x 1/ 1 76 x 76 x 256 -> 76 x 76 x 128 0.379 BF
131 route 130 128 -> 76 x 76 x 256
132 conv 128 1 x 1/ 1 76 x 76 x 256 -> 76 x 76 x 128 0.379 BF
133 conv 256 3 x 3/ 1 76 x 76 x 128 -> 76 x 76 x 256 3.407 BF
134 conv 128 1 x 1/ 1 76 x 76 x 256 -> 76 x 76 x 128 0.379 BF
135 conv 256 3 x 3/ 1 76 x 76 x 128 -> 76 x 76 x 256 3.407 BF
136 conv 128 1 x 1/ 1 76 x 76 x 256 -> 76 x 76 x 128 0.379 BF
137 conv 256 3 x 3/ 1 76 x 76 x 128 -> 76 x 76 x 256 3.407 BF
138 conv 255 1 x 1/ 1 76 x 76 x 256 -> 76 x 76 x 255 0.754 BF
139 yolo
[yolo] params: iou loss: ciou (4), iou_norm: 0.07, cls_norm: 1.00, scale_x_y: 1.20
nms_kind: greedynms (1), beta = 0.600000
140 route 136 -> 76 x 76 x 128
141 conv 256 3 x 3/ 2 76 x 76 x 128 -> 38 x 38 x 256 0.852 BF
142 route 141 126 -> 38 x 38 x 512
143 conv 256 1 x 1/ 1 38 x 38 x 512 -> 38 x 38 x 256 0.379 BF
144 conv 512 3 x 3/ 1 38 x 38 x 256 -> 38 x 38 x 512 3.407 BF
145 conv 256 1 x 1/ 1 38 x 38 x 512 -> 38 x 38 x 256 0.379 BF
146 conv 512 3 x 3/ 1 38 x 38 x 256 -> 38 x 38 x 512 3.407 BF
147 conv 256 1 x 1/ 1 38 x 38 x 512 -> 38 x 38 x 256 0.379 BF
148 conv 512 3 x 3/ 1 38 x 38 x 256 -> 38 x 38 x 512 3.407 BF
149 conv 255 1 x 1/ 1 38 x 38 x 512 -> 38 x 38 x 255 0.377 BF
150 yolo
[yolo] params: iou loss: ciou (4), iou_norm: 0.07, cls_norm: 1.00, scale_x_y: 1.10
nms_kind: greedynms (1), beta = 0.600000
151 route 147 -> 38 x 38 x 256
152 conv 512 3 x 3/ 2 38 x 38 x 256 -> 19 x 19 x 512 0.852 BF
153 route 152 116 -> 19 x 19 x1024
154 conv 512 1 x 1/ 1 19 x 19 x1024 -> 19 x 19 x 512 0.379 BF
155 conv 1024 3 x 3/ 1 19 x 19 x 512 -> 19 x 19 x1024 3.407 BF
156 conv 512 1 x 1/ 1 19 x 19 x1024 -> 19 x 19 x 512 0.379 BF
157 conv 1024 3 x 3/ 1 19 x 19 x 512 -> 19 x 19 x1024 3.407 BF
158 conv 512 1 x 1/ 1 19 x 19 x1024 -> 19 x 19 x 512 0.379 BF
159 conv 1024 3 x 3/ 1 19 x 19 x 512 -> 19 x 19 x1024 3.407 BF
160 conv 255 1 x 1/ 1 19 x 19 x1024 -> 19 x 19 x 255 0.189 BF
161 yolo
[yolo] params: iou loss: ciou (4), iou_norm: 0.07, cls_norm: 1.00, scale_x_y: 1.05
nms_kind: greedynms (1), beta = 0.600000
Total BFLOPS 128.459
avg_outputs = 1068395
Loading weights from yolov4.weights...
seen 64, trained: 32032 K-images (500 Kilo-batches_64)
Done! Loaded 162 layers from weights-file
Learning Rate: 0.0013, Momentum: 0.949, Decay: 0.0005
If error occurs - run training with flag: -dont_show
Saving weights to backup//yolov4_final.weights
Create 6 permanent cpu-threads
結果在darknet\build\darknet\x64\backup目錄,生成一個yolov4_final.weights。
訓練很快就完成了。這是因為初始權重文件yolov4.weights,已經是根據上述數據訓練的,迭代終止條件立即滿足。可以認為:yolov4_final.weights和yolov4.weights是相同的。
至此,基本的模型訓練體驗完畢。下面的工作,是結合實際應用來實現自己的模型訓練。
3、訓練自己的模型
3.1、建立自己的VOC目錄結構
構造基本的VOC目錄結構:Annotations、JPEGImages以及ImageSets/Main。
為了簡單起見,仍可使用voc_label.py文件,我按如下方式構造目錄:
#在VOCdevkit目錄下創建VOC2020
darknet\build\darknet\x64\data\voc\VOCdevkit\VOC2020
#創建三個基本子目錄
darknet\build\darknet\x64\data\voc\VOCdevkit\VOC2020\Annotations
darknet\build\darknet\x64\data\voc\VOCdevkit\VOC2020\JPEGImages
darknet\build\darknet\x64\data\voc\VOCdevkit\VOC2020\ImageSets
#ImageSets目錄再創建Main子目錄
darknet\build\darknet\x64\data\voc\VOCdevkit\VOC2020\ImageSets\Main
(下列所有修改,應該先備份一下原文件)
修改voc_label.py文件:
sets=[('2020', 'train'), ('2020', 'val'),('2020', 'trainval'),('2020', 'test')]
修改darknet\build\darknet\x64\data目錄下的voc.data文件的對應行:
train = data/voc/2020_train.txt
valid = data/voc/2020_val.txt
3.2、設置自己的分類
關於分類,網上資料顯示,VOC數據集分類最大20個,COCO數據集最大80個,這個最大分類數可以調整為自己需要的數值,當然分類很多時,需要使用YOLO9000模型。
參考了下列資料:
-
《一文看懂YOLO v3》(https://zhuanlan.zhihu.com/p/60944510);
-
《YOLO_V3 原理以及訓練說明》 (https://blog.csdn.net/qq_31511955/article/details/87917308);
-
《YOLOv3訓練自己的數據》 (https://www.jianshu.com/p/2f1608a4459b);
-
《每一步超詳細!制作自己的voc數據集並通過yolov3訓練》(https://blog.csdn.net/qq_34806812/article/details/81673798)
-
《一文詳解YOLO 2與YOLO 9000目標檢測系統| 分享總結》(https://baijiahao.baidu.com/s?id=1576943106747207357&wfr=spider&for=pc)。
假設自己的分類數為[n],則需要修改之處有:
1)修改darknet\build\darknet\x64\data\voc.names
將自己的[n]個分類標簽輸入,每個分類一行。
2)修改darknet\build\darknet\x64\data\voc.data
classes= 20 ==> classes= [n]
3)修改darknet\build\darknet\x64\cfg\yolov4.cfg
[yolo]標簽下:
classes=80 ==> classes= [n]
[yolo]標簽前面的一個[convolutional]標簽:
filters=255 ==> filters=([n]+5)*3
3.3、標注自己的數據
使用labelImg工具來進行標注工作,參見《windows下使用labelImg標注圖像》(https://blog.csdn.net/python_pycharm/article/details/85338801)。
這是一個費時的工作。
圖片放置在JPEGImages目錄下,最好按編號命名。對應的labelImg生成的標注文件,放入Annotations目錄下,命名與圖片文件名一致。
然后,生成ImageSets/Main下的文件。網上有makeTxt.py文件,生成train,val,test,trainval文件,參見:https://blog.csdn.net/public669/article/details/98020800)。
但我發現這是相當於執行了voc_label.py后,生成的文件。暫時可以用這個方法。
問題:
目前VOC2012/ImageSets/Main目錄下的文件形式,是按類型分的。如car這個分類,有下列文件:
car_train.txt
car_val.txt
car_trainval.txt
考慮到后續處理的需要,需要一個新的處理python腳本。基本思路是:掃描分類文件voc.names,針對每一個分類,掃描Annotations中的文件,檢測是否包含這個分類的對象,設置[flag]為1或-1,加入這個分類的list對象,最后再打散,生成各個分類的train,val,test,trainval文件。
3.4、后續工作
類似於2.3和2.4步,執行訓練即可。我目前還沒有開始具體應用分類試驗,暫時先進行到此。