@@ -59,7 +59,7 @@ def multibox_prior(data, sizes, ratios):
59
59
ratio_tensor = d2l.tensor(ratios, ctx=device)
60
60
61
61
# 为了将锚点移动到像素的中心,需要设置偏移量。
62
- # 因为一个像素的的高为1且宽为1 ,我们选择偏移我们的中心0.5
62
+ # 因为一个像素的高为1且宽为1 ,我们选择偏移我们的中心0.5
63
63
offset_h, offset_w = 0.5, 0.5
64
64
steps_h = 1.0 / in_height # 在y轴上缩放步长
65
65
steps_w = 1.0 / in_width # 在x轴上缩放步长
@@ -101,15 +101,15 @@ def multibox_prior(data, sizes, ratios):
101
101
ratio_tensor = d2l.tensor(ratios, device=device)
102
102
103
103
# 为了将锚点移动到像素的中心,需要设置偏移量。
104
- # 因为一个像素的的高为1且宽为1 ,我们选择偏移我们的中心0.5
104
+ # 因为一个像素的高为1且宽为1 ,我们选择偏移我们的中心0.5
105
105
offset_h, offset_w = 0.5, 0.5
106
106
steps_h = 1.0 / in_height # 在y轴上缩放步长
107
107
steps_w = 1.0 / in_width # 在x轴上缩放步长
108
108
109
109
# 生成锚框的所有中心点
110
110
center_h = (torch.arange(in_height, device=device) + offset_h) * steps_h
111
111
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' )
113
113
shift_y, shift_x = shift_y.reshape(-1), shift_x.reshape(-1)
114
114
115
115
# 生成“boxes_per_pixel”个高和宽,
@@ -324,8 +324,8 @@ def assign_anchor_to_bbox(ground_truth, anchors, device, iou_threshold=0.5):
324
324
anchors_bbox_map = np.full((num_anchors,), -1, dtype=np.int32, ctx=device)
325
325
# 根据阈值,决定是否分配真实边界框
326
326
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 ]
329
329
anchors_bbox_map[anc_i] = box_j
330
330
col_discard = np.full((num_anchors,), -1)
331
331
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):
352
352
device=device)
353
353
# 根据阈值,决定是否分配真实边界框
354
354
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 ]
357
357
anchors_bbox_map[anc_i] = box_j
358
358
col_discard = torch.full((num_anchors,), -1)
359
359
row_discard = torch.full((num_gt_boxes,), -1)
0 commit comments