YOLOv3提供了单张图片处理接口,但并未提供图像的批处理接口,通过修改detector.c 实现从文本读入image list并将结果保存到输出txt文件,代码如下:
在detector.c中添加如下函数:
并修改主函数部分如下:只修改对应的部分即可
if(0==strcmp(argv[2], "test")) test_detector(datacfg, cfg, weights, filename, thresh, hier_thresh, outfile, fullscreen); else if(0==strcmp(argv[2],"batch")){ if(argv<=7){ printf("%s\n","image_list and output_file is required!"); exit(0); } char *image_list= argv[6]; char *save_file= argv[7]; batch_process(datacfg, cfg, weights, image_list, thresh, hier_thresh, save_file); } else if(0==strcmp(argv[2], "train")) train_detector(datacfg, cfg, weights, gpus, ngpus, clear); else if(0==strcmp(argv[2], "valid")) validate_detector(datacfg, cfg, weights, outfile); else if(0==strcmp(argv[2], "valid2")) validate_detector_flip(datacfg, cfg, weights, outfile); else if(0==strcmp(argv[2], "recall")) validate_detector_recall(cfg, weights); else if(0==strcmp(argv[2], "demo")) { list *options = read_data_cfg(datacfg); int classes = option_find_int(options, "classes", 20); char *name_list = option_find_str(options, "names", "data/names.list"); char **names = get_labels(name_list); demo(cfg, weights, thresh, cam_index, filename, names, classes, frame_skip, prefix, avg, hier_thresh, width, height, fps, fullscreen); }
调用命令行接口如下:
./darknet detector batch cfg/coco.data cfg/yolov3.cfg yolov3.weights input_image_list.txt output_results.txt其中input_image_list.txt含有待检测图像的绝对地址,output_results.txt中存储输出结果。类似SSD。
文章来源: YOLOv3图像批处理程序