13.4.3 在训练数据中标注锚框
P421
anchors_bbox_map = torch.full((num_anchors,), -1, dtype=torch.long,
device=device)

max_ious, indices = torch.max(jaccard, dim=1)

anc_i = torch.nonzero(max_ious >= iou_threshold).reshape(-1)

注意,前面的操作不是徒劳的,循环前面的分配是在做第\((4)\)步,即分配剩余的\(n_a-n_b\)个锚框
P422
bbox_mask = ((anchors_bbox_map >= 0).float().unsqueeze(-1)).repeat(
1, 4)
在.unsqueeze(-1)之后,形状就变成了(num_anchors, 1),再.repeat就变成了(num_anchors, 4)
class_labels[indices_true] = label[bb_idx, 0].long() + 1
这里之所以需要+1,是因为参数labels是从-1开始的(表示背景),具体可以见下面的示例:狗的标签是0

浙公网安备 33010602011771号