20190904
此篇以people detection為例
資料的label只有"person"一種類別
github: caffe-SSD
不然會出現一些layer找不到的issue
issue:caffe.LayerParameter has no field named permute_param
If you just want to perform inference, I think adding about three new layers (prior_bbox_layer, permute_layer, detection_output_layer) to your caffe is enough.
Train SSD on the Custom Dataset
Mobilenet-SSD的Caffe系列實現
chuanqi305/MobileNet-SSD
將已準備好的pascal voc格式的資料放在/home/data/VOCdevkit
裡 (不然就要改creat_list.sh裡面的path)
複製相關的4個sh,txt檔 到 新的資料夾(MYDATASET)內
結果會像這樣
create_list.sh
In the second loop, replace the keywords VOC2007 and VOC2012 with "MYDATASET" since we have only one dataset.
test/trainval.txt
to generate test_name_size.txt
, test.txt
, and trainval.txt
in data/MYDATASET/
.
結果會像這樣:
labelmap_voc.prototxt
In this file, the first block points to the background. So, don't change it. For the rest block, change their class names accordingly.
create_data.sh
Convert dataset to lmdb database
edit ~/caffe-SSD/data/MYDATASET/create_data.sh
create_data.sh
This will create LMDB database in ~/data/VOCdevkit
and make a soft link in examples/MYDATASET/.
–> ~/data/VOCdevkit/persondataset
會多一個"lmdb"資料夾(成功!)
~/data/examples/MYDATASET/
會多soft link
~/caffe-ssd/scripts/create_annoset.py
檔create symlinks to current directory.
在caffe-SSD/examples/MobileNet-SSD
由於原VOC數據集是21類(20+背景),而我們是"2類"(1+背景)
因此,需要重新生成訓練、測試和運行網絡文件
這裡使用gen_model.sh
,他會調用template文件夾中的模板,按照我們指定的參數,生成所需的文。用法如下:
執行之後,得到example文件夾,內已生好prototxt檔了!
根據作者設置,其中的deploy文件是已經合併過bn層的,需要後面配套使用。
solver.prototxt
setting~/caffe-SSD/examples/MobileNet-SSD
solver_train.prototxt
和solver_test.prototxt
。test_iter=測試集圖片數量/batchsize
;修改並運行train.sh
,中途可以不斷調節參數。
訓練結束後,運行test.sh
,測試網絡的精度值。
Download the training weights from the link above, and run train.sh, after about 30000 iterations, the loss should be 1.5 - 2.5.
10 iteration要 3分鐘
1000–>300
10000–>3000min = 50 hr
batch size:24 + 300x300 –> train gpu 5651MiB~7163MiB
it does not do well for small objects.
A 50x50 object may only have 5-6 pixels on conv4_3 (i.e. 8x reduction in resolution).
To detect smaller objects better, besides what you mentioned, you could increase input image size or increase feature map size.
accuracy & loss
caffemodel test result:
–- END –-