@@ -59,7 +59,7 @@ def multibox_prior(data, sizes, ratios):
5959 ratio_tensor = d2l.tensor(ratios, ctx=device)
6060
6161 # 为了将锚点移动到像素的中心,需要设置偏移量。
62- # 因为一个像素的的高为1且宽为1 ,我们选择偏移我们的中心0.5
62+ # 因为一个像素的高为1且宽为1 ,我们选择偏移我们的中心0.5
6363 offset_h, offset_w = 0.5, 0.5
6464 steps_h = 1.0 / in_height # 在y轴上缩放步长
6565 steps_w = 1.0 / in_width # 在x轴上缩放步长
@@ -101,15 +101,15 @@ def multibox_prior(data, sizes, ratios):
101101 ratio_tensor = d2l.tensor(ratios, device=device)
102102
103103 # 为了将锚点移动到像素的中心,需要设置偏移量。
104- # 因为一个像素的的高为1且宽为1 ,我们选择偏移我们的中心0.5
104+ # 因为一个像素的高为1且宽为1 ,我们选择偏移我们的中心0.5
105105 offset_h, offset_w = 0.5, 0.5
106106 steps_h = 1.0 / in_height # 在y轴上缩放步长
107107 steps_w = 1.0 / in_width # 在x轴上缩放步长
108108
109109 # 生成锚框的所有中心点
110110 center_h = (torch.arange(in_height, device=device) + offset_h) * steps_h
111111 center_w = (torch.arange(in_width, device=device) + offset_w) * steps_w
112- shift_y, shift_x = torch.meshgrid(center_h, center_w)
112+ shift_y, shift_x = torch.meshgrid(center_h, center_w, indexing='ij' )
113113 shift_y, shift_x = shift_y.reshape(-1), shift_x.reshape(-1)
114114
115115 # 生成“boxes_per_pixel”个高和宽,
@@ -324,8 +324,8 @@ def assign_anchor_to_bbox(ground_truth, anchors, device, iou_threshold=0.5):
324324 anchors_bbox_map = np.full((num_anchors,), -1, dtype=np.int32, ctx=device)
325325 # 根据阈值,决定是否分配真实边界框
326326 max_ious, indices = np.max(jaccard, axis=1), np.argmax(jaccard, axis=1)
327- anc_i = np.nonzero(max_ious >= 0.5 )[0]
328- box_j = indices[max_ious >= 0.5 ]
327+ anc_i = np.nonzero(max_ious >= iou_threshold )[0]
328+ box_j = indices[max_ious >= iou_threshold ]
329329 anchors_bbox_map[anc_i] = box_j
330330 col_discard = np.full((num_anchors,), -1)
331331 row_discard = np.full((num_gt_boxes,), -1)
@@ -352,8 +352,8 @@ def assign_anchor_to_bbox(ground_truth, anchors, device, iou_threshold=0.5):
352352 device=device)
353353 # 根据阈值,决定是否分配真实边界框
354354 max_ious, indices = torch.max(jaccard, dim=1)
355- anc_i = torch.nonzero(max_ious >= 0.5 ).reshape(-1)
356- box_j = indices[max_ious >= 0.5 ]
355+ anc_i = torch.nonzero(max_ious >= iou_threshold ).reshape(-1)
356+ box_j = indices[max_ious >= iou_threshold ]
357357 anchors_bbox_map[anc_i] = box_j
358358 col_discard = torch.full((num_anchors,), -1)
359359 row_discard = torch.full((num_gt_boxes,), -1)
0 commit comments