| 22 | |
| 23 | |
| 24 | def _iou(self, boxes, box): |
| 25 | iw = torch.clamp(boxes[:, 2], max=box[2]) - torch.clamp(boxes[:, 0], min=box[0]) |
| 26 | ih = torch.clamp(boxes[:, 3], max=box[3]) - torch.clamp(boxes[:, 1], min=box[1]) |
| 27 | |
| 28 | inter = torch.clamp(iw, min=0) * torch.clamp(ih, min=0) |
| 29 | |
| 30 | areas = (boxes[:, 2] - boxes[:, 0]) * (boxes[:, 3] - boxes[:, 1]) |
| 31 | area = (box[2] - box[0]) * (box[3] - box[1]) |
| 32 | |
| 33 | iou = inter / (areas + area - inter) |
| 34 | return iou |
| 35 | |
| 36 | def __call__(self, gt_boxes, anchors): |
| 37 | if len(gt_boxes) == 0: |