CIoU损失函数是谁提出的
时间: 2025-06-03 14:59:58 浏览: 18
CIoU(Complete Intersection over Union)损失函数是由 Zheng et al. 在其论文《Distance-IoU Loss: Faster and Better Learning for Bounding Box Regression》中提出的[^3]。该团队通过分析 IoU 和 GIoU 的不足之处,进一步引入了距离因素以及宽高比例因子来提升边界框回归的效果。
以下是 CIoU 损失函数的核心概念及其优势:
- CIoU 不仅考虑了预测框与真实框之间的重叠面积(即 IoU),还加入了中心点的距离惩罚项和宽高比例一致性约束[^3]。
- 这种设计使得 CIoU 能够更全面地衡量两个框之间的差异,从而加速收敛并提高定位精度。
```python
import torch
def ciou_loss(pred_boxes, target_boxes, eps=1e-7):
"""
Compute the CIoU loss between predicted boxes and target boxes.
Args:
pred_boxes (Tensor): Predicted bounding boxes with shape [N, 4].
target_boxes (Tensor): Target bounding boxes with shape [N, 4].
eps (float): Epsilon to avoid division by zero.
Returns:
Tensor: The computed CIoU loss value.
"""
# Convert center-size format to top-left bottom-right coordinates
px1y1 = pred_boxes[:, :2] - pred_boxes[:, 2:] / 2
px2y2 = pred_boxes[:, :2] + pred_boxes[:, 2:] / 2
tx1y1 = target_boxes[:, :2] - target_boxes[:, 2:] / 2
tx2y2 = target_boxes[:, :2] + target_boxes[:, 2:] / 2
# Calculate intersection area
inter_x1y1 = torch.max(px1y1, tx1y1)
inter_x2y2 = torch.min(px2y2, tx2y2)
inter_area = torch.clamp((inter_x2y2 - inter_x1y1), min=0).prod(1)
# Calculate union area
pred_area = pred_boxes[:, 2:].prod(1)
target_area = target_boxes[:, 2:].prod(1)
union_area = pred_area + target_area - inter_area + eps
iou = inter_area / union_area
# Enclosing box dimensions
enclose_x1y1 = torch.min(px1y1, tx1y1)
enclose_x2y2 = torch.max(px2y2, tx2y2)
enclose_diagonal_sq = ((enclose_x2y2 - enclose_x1y1)**2).sum(dim=1)
# Center point distance squared
centers_distance_sq = ((pred_boxes[:, :2] - target_boxes[:, :2])**2).sum(dim=1)
diou_term = centers_distance_sq / (enclose_diagonal_sq + eps)
v = (4 / math.pi ** 2) * torch.pow(
torch.atan(target_boxes[:, 2] / (target_boxes[:, 3] + eps)) -
torch.atan(pred_boxes[:, 2] / (pred_boxes[:, 3] + eps)), 2
)
alpha = v / (1 - iou + v + eps)
ciou = iou - diou_term - alpha * v
return 1 - ciou.mean()
```
阅读全文
相关推荐


















