IoU(Intersection over Union,交并比)
IOU 衡量两个集合的重叠程度。
IOU 为 0 时,两个框不重叠,没有交集。
IOU 为 1 时,两个框完全重叠。
IOU 取值为 0 ~ 1 之间的值时,代表了两个框的重叠程度,数值越高,重叠程度越高
在Semantic segmentation中,计算真实值和预测值的交并比来判断预测水平
代码
#y:真实值,y_pred预测值
intersection = torch.logical_and(y, y_pred) # logical_and:与运算,交集
union = torch.logical_or(y, y_pred) # logical_or:并集
batch_iou = torch.true_divide(torch.sum(intersection), # 交集除以并集,true_divide(内置除法)
torch.sum(union)) #因为这两个是张量,张量除法用true_divide
epoch_iou.append(batch_iou)
张量除法用true_divide