yolofastest源碼學(xué)習(xí)記錄
主要防止自己忘了,不詳細(xì)了寫了
順序記錄下程序的流程:
1.darknet.c

運(yùn)行darknet.c,輸入以下命令:
? ? //./darknet detector ?test ./data/voc.data ?./Yolo-Fastest/VOC/yolo-fastest-xl.cfg ?./Yolo-Fastest/VOC/yolo-fastest-xl.weights ?data/dog.jpg ?-thresh 0.55
? ? //./darknet detector train voc.data yolo-fastest.cfg yolo-fastest.conv.109
darknet.c程序中根據(jù)命令不同進(jìn)入不同的函數(shù)接口
if (0 == strcmp(argv[1], "average")){
? ? ? ? average(argc, argv);}?
else if (0 == strcmp(argv[1], "yolo")){ ? ? ??
//string compare(字符串比較),strcmp(str1,str2),若str1=str2,則返回零;若str1str2,則返回正數(shù)。
? ? } else if (0 == strcmp(argv[1], "detector")){ ??
//argv[1]==“detector”,所以進(jìn)入的分支函數(shù)是run_detector(),并將argv參數(shù)一并傳入
2.detector.c

? ? //在run_detector()函數(shù)內(nèi),又會(huì)根據(jù)參數(shù)argv[2]的不同選擇執(zhí)行不同的分支:
? ? //當(dāng)?shù)诙€(gè)參數(shù)為test時(shí),執(zhí)行test_detector()

3.detector.c的test_detector()函數(shù)

//1.建立網(wǎng)絡(luò)
network?net?=?parse_network_cfg_custom
//2.對(duì)建立好的網(wǎng)絡(luò)結(jié)構(gòu)加載權(quán)重文件。./Yolo-Fastest/VOC/yolo-fastest-xl.weights
load_weights(&net,?weightfile);

?//3.讀取圖像input為圖像地址,net.c為輸入層通道數(shù),然后根據(jù)參數(shù),選擇縮放的方式:
? ? ? ? image im = load_image(input, 0, 0, net.c);
? ? ? ? image sized;
? ? ? ? if(letter_box) sized = letterbox_image(im, net.w, net.h);
? ? ? ? else sized = resize_image(im, net.w, net.h);
?//4.模型進(jìn)行推理,X為輸入圖像數(shù)據(jù)
? ? ? ? network_predict(net, X); ? ?

//5.通過網(wǎng)絡(luò)提取出檢測到的目標(biāo)的位置以及類別? ? ?? ?
//5.1 get_network_boxes函數(shù)實(shí)現(xiàn)的是預(yù)測框的獲取,位于darknet/src下的network.c
????detection?*dets?=?get_network_boxes();? ? ? ?? ?
//5.2 完成后,通過do_nms_sort做非極大化抑制。位于box.c
????do_nms_sort(dets,?nboxes,?l.classes,?nms);
//6.將目標(biāo)的位置以及類別標(biāo)注在圖片中。
????draw_detections_v3(im, dets, nboxes, thresh, names, alphabet, l.classes, ext_output);? ? ? ? ????save_image(im, "predictions");
整個(gè)流程結(jié)束,里面最關(guān)鍵是第五步:通過網(wǎng)絡(luò)提取出檢測到的目標(biāo)的位置以及類別??
get_network_boxes函數(shù)實(shí)現(xiàn)的是預(yù)測框的獲取,位于darknet/src下的network.c
4.network.c的get_network_boxes()函數(shù)

首先通過make_network_boxes()生成檢測(dets)信息,然后以fill_network_boxes()過濾boxes。
兩者都位于yolo_layer.c,下面進(jìn)入最關(guān)鍵的yolo.c文件
5.yolo.c的全部函數(shù)
這部分過于重要,需要全文學(xué)習(xí)。
參考:https://zhuanlan.zhihu.com/p/107266500
東西太多,下次發(fā)。