10.5.5 计算交并比
文件metrics.py定义了基于 PyTorch 的交并比(IoU)度量类和 IoU 度量的子类,用于计算预测与标签之间的交并比,并可以根据给定阈值和可见度遮罩进行计算。
class BaseIoUMetric(Metric):
"""
计算给定阈值下的交并比
"""
def __init__(self, thresholds=[0.4, 0.5]):
super().__init__(dist_sync_on_step=False, compute_on_step=False)
thresholds = torch.FloatTensor(thresholds)
self.add_state('thresholds', default=thresholds, dist_reduce_fx='mean')
self.add_state('tp', de