背景:實現相應的目標檢測網絡需要能夠測試mAP
目的:實現mAP的測試。
參考代碼:https://github.com/Cartucho/mAP#create-the-ground-truth-files
目錄
一、mAP概覽
1.1 mAP概覽
mAP為目標檢測領域的基礎指標。
首先標簽相同交並比IoU>0.5表示網絡檢測正確。
然后畫出相應的查全率與查准率的曲線,積分得到的藍色區域即為mAP。
各類的平均AP即mAP
1.2 測試需要的步驟
•Create a separate ground-truth text file for each image. In these files, each line should be in the following format: <class_name> <left> <top> <right> <bottom> [<difficult>]
生成相應的標注文檔,無論是GroundTruth還是網絡生成的預測,都需要按照上面的格式標注。
•Use matching names (e.g. image: "image_1.jpg", ground-truth: "image_1.txt"; "image_2.jpg", "image_2.txt"...).
然后圖片放入相應的文件夾之中。
1.Create the ground-truth files 創建相應的GroundTruth文件
2.Move the ground-truth files into the folder ground-truth/ 放入相應文件夾
3.Create the predicted objects files 創建相應的預測的文件
4.Move the predictions files into the folder predicted/ 放入相應文件夾
5.Run the mAP code 運行mAP的代碼
二、GroundTruth文檔的生成
按照要求將文件拷入文件夾與生成相應的標注。
<class_name> <left> <top> <right> <bottom> [<difficult>] 標注需要與文件同名且每一行按照這種格式生成。
此部分代碼實現了
- 舊用於預測的圖像重命名放入新目錄下
- 舊標簽按照mAP的要求格式生成新標簽
三、網絡預測結果生成
根據網絡預測將所有圖片運行一遍,結果寫入相應txt文件之中,然后調用mAP測試函數對結果進行預測。
四、預測mAP代碼
4.1 運算IoU
4.2 運算AP
先設置兩個點,即precision為1的時候,recall為0;precision為0的時候,recall為1
precision隨着recall的增減,逐漸減少
創建recall的變化
AP即為曲線下積分的面積
4.3 mAP
根據每類的AP算出mAP
。。。代碼中有大量的代碼用於畫出曲線和顯示出ground truth和圖像上的prediction等,我們省去此部分。