def get_hw_center(json_path, h, w, scale): """ 從json格式中讀取目標的寬高和中心點位置 json_path: json文件的路徑 h: 原始圖像的高度 w: 原始圖像的寬度 scale; 特徵圖與原圖的比例,centernet爲1/4 """ myObject = [] with open(json_path, 'r', encoding='utf-8') as f: ret_dic = json.load(f) imgPath = ret_dic['path'] target_Obj['imgPath'] = imgPath object = (ret_dic['outputs']['object']) numObject = len(object) print(numObject) for i in range(0, numObject): obj = object[i]['bndbox'] xmin = obj['xmin'] ymin = obj['ymin'] xmax = obj['xmax'] ymax = obj['ymax'] obj_width = np.abs(xmax - xmin)*scale # 原圖中目標的寬度,原版論文無需歸一化 obj_height = np.abs(ymax - ymin)*scale # 原圖中目標的高度,原版論文無需歸一化 centerPoint = [(xmax+xmin)/2*scale, (ymax+ymin) / 2*scale] # 目標在特徵圖中的中心點座標 target_Obj['height'] = np.array(obj_height).copy() target_Obj['width'] = np.array(obj_width).copy() target_Obj['centerPoint'] = np.array(centerPoint).copy() myObject.append(target_Obj.copy()) return myObject
這一個可以多說一點,形變卷積可以學習到傳統卷積無法學下到的長距離信息。
class L1Loss(nn.Module): """ L1 loss,論文證明,該loss要比smooth L1 loss要好! """ def __init__(self): super(L1Loss, self).__init__() def forward(self, pred, mask, target): numPoint = mask[:, 0, :, :].float().sum() # 目標點個數 loss = F.l1_loss(pred * mask, target * mask, reduction='elementwise_mean') return loss/(numPoint+1e-4)
好吧,先寫到這裏,下一步我會來更新超大影像的目標檢測及相關工程應用上的精度 與效率如何,需要代碼請加qq 1044625113。
用一句話來總結我的想法,只做有用的東西,不做灌水的東西!大家共勉!