yolo-v3 github: https://github.com/pjreddie/darknet
参考博客: YOLOv3 ubuntu 配置及训练自己的VOC格式数据集
int main(int argc, char **argv)
{
if(argc < 2){
fprintf(stderr, "usage: %s \n" , argv[0]);
return 0;
}
gpu_index = find_int_arg(argc, argv, "-i", 0);
if(find_arg(argc, argv, "-nogpu")) {
gpu_index = -1;
}
#ifndef GPU
gpu_index = -1;
#else
if(gpu_index >= 0){
cuda_set_device(gpu_index);
}
#endif
if (0 == strcmp(argv[1], "average")){
average(argc, argv);
} else if (0 == strcmp(argv[1], "yolo")){
run_yolo(argc, argv);
} else if (0 == strcmp(argv[1], "super")){
run_super(argc, argv);
} else if (0 == strcmp(argv[1], "lsd")){
run_lsd(argc, argv);
} else if (0 == strcmp(argv[1], "detector")){
run_detector(argc, argv);
} else if (0 == strcmp(argv[1], "detect")){
float thresh = find_float_arg(argc, argv, "-thresh", .5);
char *filename = (argc > 4) ? argv[4]: 0;
char *outfile = find_char_arg(argc, argv, "-out", 0);
int fullscreen = find_arg(argc, argv, "-fullscreen");
test_detector("cfg/coco.data", argv[2], argv[3], filename, thresh, .5, outfile, fullscreen);
} else if (0 == strcmp(argv[1], "cifar")){
run_cifar(argc, argv);
...
return 0;
}
给不同的参数,对应跳转到不同的函数执行。
3. 用作者训练好的通用目标模型检测效果图:
a. 略
b. 略
可以看到,在简单场景下,通用检测检测效果还行,但是复杂场景正对特定目标,会有一些问题(比如误检、小目标无法检测等)
4. 训练自己的数据集,以头肩为例,训练自己的数据集。
a. 首先,利用voc_label.py将voc格式的数据转换为训练所需要的数据格式。
b. 训练
./darknet detector train cfg/voc.data cfg/yolov3-voc.cfg darknet53.conv.74
训练出现问题:
Region 82 Avg IOU: 0.259673, Class: 0.593880, Obj: 0.831784, No Obj: 0.515905, .5R: 0.000000, .75R: 0.000000, count: 1
Region 94 Avg IOU: -nan, Class: -nan, Obj: -nan, No Obj: 0.494105, .5R: -nan, .75R: -nan, count: 0
Region 106 Avg IOU: -nan, Class: -nan, Obj: -nan, No Obj: 0.412357, .5R: -nan, .75R: -nan, count: 0
1: 579.859924, 579.859924 avg, 0.000000 rate, 0.039695 seconds, 1 images
Loaded: 0.008419 seconds
Region 82 Avg IOU: -nan, Class: -nan, Obj: -nan, No Obj: 0.515768, .5R: -nan, .75R: -nan, count: 0
Region 94 Avg IOU: -nan, Class: -nan, Obj: -nan, No Obj: 0.494756, .5R: -nan, .75R: -nan, count: 0
Region 106 Avg IOU: 0.224065, Class: 0.304794, Obj: 0.247472, No Obj: 0.415191, .5R: 0.000000, .75R: 0.000000, count: 4
2: 594.244812, 581.298401 avg, 0.000000 rate, 0.092844 seconds, 2 images
Loaded: 0.000024 seconds
输入416,anchor聚类:
(29,31),(7,9),(18,30),(44,82),(119,212),(72,110),(28,56),(47,45),(14,17)
于是anchor = 7,9, 14,17, 18,30, 29,31, 28,56, 47,45, 44,82, 72,110, 119,212
时隔很久。。又开始训练yolo的代码。yolov2训练成功了,可是yolov3怎么也不成功。。
[net]
# Testing
# batch=1 #注释
# subdivisions=1 #注释
# Training
batch=8
# subdivisions=16
width=416
height=416
channels=3
momentum=0.9
decay=0.0005
angle=0
saturation = 1.5
exposure = 1.5
hue=.1
结果把#Testing 后面的batch以及subdivisions注释就成功了…
没注释之前,按照batch=1在计算,注释之后,按照batch=8在计算。因为我的训练样本中有很多小目标,所以batch太小是有问题的。唉。。