meituan / YOLOv6

YOLOv6: a single-stage object detection framework dedicated to industrial applications.
GNU General Public License v3.0
5.72k stars 1.04k forks source link

标签分配代码实现逻辑咨询 #499

Closed rrjia closed 2 years ago

rrjia commented 2 years ago

https://github.com/meituan/YOLOv6/blob/main/yolov6/assigners/assigner_utils.py 66行

target_gt_idx = mask_pos.argmax(axis=-2)

mask_pos (Tensor): shape(bs, n_max_boxes, num_total_anchors),这里的目的应该是计算出,每个anchor与那个gt作为正样本匹配对,但是如果使用argmax,如果这个anchor与任何gt都不匹配,但是也要反正返回一个最大值的索引的,那岂不是每个anchor都要有gt,我看下下输出显示,所有的没有匹配上的anchor经过这一步都显示与第一个,也就是索引为0的gt匹配,这个逻辑感觉不太对劲,请大佬帮忙解答下

leedewdew commented 2 years ago

Don't worry, 'fg_mask' is there to handle this situation.

rrjia commented 2 years ago

谢谢提醒,在yolov6/models/loss.py中找到了相关实现

 target_labels = torch.where(fg_mask > 0, target_labels, torch.full_like(target_labels, self.num_classes))

利用fg_mask 进行了过滤,将0值替换成了backgroud_id值,但是我觉得将这部分代码放到label_assign中是不是更合适些?

leedewdew commented 2 years ago

yeah, two different implementations. Both are ok. You decide which one is better.