qq_30037793 2019-10-17 13:59 采纳率: 0%
浏览 1573

pytorch版本的YOLOV3计算IOU的公式中为什么有+1?

def bbox_iou(box1, box2, x1y1x2y2=True):

if not x1y1x2y2:
    # Transform from center and width to exact coordinates
    b1_x1, b1_x2 = box1[:, 0] - box1[:, 2] / 2, box1[:, 0] + box1[:, 2] / 2
    b1_y1, b1_y2 = box1[:, 1] - box1[:, 3] / 2, box1[:, 1] + box1[:, 3] / 2
    b2_x1, b2_x2 = box2[:, 0] - box2[:, 2] / 2, box2[:, 0] + box2[:, 2] / 2
    b2_y1, b2_y2 = box2[:, 1] - box2[:, 3] / 2, box2[:, 1] + box2[:, 3] / 2
else:
    # Get the coordinates of bounding boxes
    b1_x1, b1_y1, b1_x2, b1_y2 = box1[:, 0], box1[:, 1], box1[:, 2], box1[:, 3]
    b2_x1, b2_y1, b2_x2, b2_y2 = box2[:, 0], box2[:, 1], box2[:, 2], box2[:, 3]

# get the corrdinates of the intersection rectangle
inter_rect_x1 = torch.max(b1_x1, b2_x1)
inter_rect_y1 = torch.max(b1_y1, b2_y1)
inter_rect_x2 = torch.min(b1_x2, b2_x2)
inter_rect_y2 = torch.min(b1_y2, b2_y2)
# Intersection area
inter_area = torch.clamp(inter_rect_x2 - inter_rect_x1 + 1, min=0) * torch.clamp(
    inter_rect_y2 - inter_rect_y1 + 1, min=0
)
# Union Area
b1_area = (b1_x2 - b1_x1 + 1) * (b1_y2 - b1_y1 + 1)
b2_area = (b2_x2 - b2_x1 + 1) * (b2_y2 - b2_y1 + 1)

iou = inter_area / (b1_area + b2_area - inter_area + 1e-16)

return iou

这是pytorch版本的yolov3中计算IOU的代码,想问一下为什么inter_area和b1_area的计算公式中都有+1,还有计算iou时最后为什么要加e的-16次方

  • 写回答

3条回答 默认 最新

  • aiking2020 2020-06-10 12:58
    关注

    This module uses a convention that may seem strange at first: the width of a box
    is computed as x2 - x1 + 1 (likewise for height). The "+ 1" dates back to old
    object detection days when the coordinates were integer pixel indices, rather
    than floating point coordinates in a subpixel coordinate frame. A box with x2 =
    x1 and y2 = y1 was taken to include a single pixel, having a width of 1, and
    hence requiring the "+ 1". Now, most datasets will likely provide boxes with
    floating point coordinates and the width should be more reasonably computed as
    x2 - x1.

    In practice, as long as a model is trained and tested with a consistent
    convention either decision seems to be ok (at least in our experience on COCO).
    Since we have a long history of training models with the "+ 1" convention, we
    are reluctant to change it even if our modern tastes prefer not to use it.

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器