對于長條目標長寬比比較大的目標,如長1000pix,寬度10pix等在訓練時masic數據增強圖片中會出現有的圖片中標簽遺失問題,將原來標注好的目標,但是在增強圖片中沒有標簽,就會導致召回率低的問題。
在訓練代碼中augmentations.py文件中box_candidates函數用在random_perspective中,是對透視變換后的圖片label進行篩選,去除被裁剪過小的框(面積小于裁剪前的area_thr) 并且保留下來的框的長寬必須大于wh_thr個像素,且長寬比范圍在(1/ar_thr, ar_thr)之間,函數默認參數為
def box_candidates(box1, box2, wh_thr=2, ar_thr=20, area_thr=0.1, eps=1e-16):"""box_candidates() is used to filter the labels and reject poor label candidates:用在random_perspective中 對透視變換后的圖片label進行篩選去除被裁剪過小的框(面積小于裁剪前的area_thr) 還有長和寬必須大于wh_thr個像素,且長寬比范圍在(1/ar_thr, ar_thr)之間的限制Compute candidate boxes: box1 before augment, box2 after augment, wh_thr (pixels), aspect_ratio_thr, area_ratio:params box1: [4, n]:params box2: [4, n]:params wh_thr: 篩選條件 寬高閾值:params ar_thr: 篩選條件 寬高比、高寬比最大值閾值:params area_thr: 篩選條件 面積閾值:params eps: 1e-16 接近0的數 防止分母為0:return i: 篩選結果 [n] 全是True或False 使用比如: box1[i]即可得到i中所有等于True的矩形框 False的矩形框全部刪除"""w1, h1 = box1[2] - box1[0], box1[3] - box1[1] # 求出所有box1矩形框的寬和高 [n] [n]w2, h2 = box2[2] - box2[0], box2[3] - box2[1] # 求出所有box2矩形框的寬和高 [n] [n]ar = np.maximum(w2 / (h2 + eps), h2 / (w2 + eps)) # 求出所有box2矩形框的寬高比和高寬比的較大者 [n, 1]# 篩選條件: 增強后w、h要大于2 增強后圖像與增強前圖像面積比值大于area_thr 寬高比大于ar_thrreturn ((w2 > wh_thr)& (h2 > wh_thr)& (w2 * h2 / (w1 * h1 + eps) > area_thr)& (ar < ar_thr)) # candidates
?嘗試修改參數wh_thr=1,ar_thr=50增大長寬比范圍
參考 https://zhuanlan.zhihu.com/p/669418392