<gh_stars>10-100
import torch

from .builder import IOU_CALCULATORS
from maskrcnn_benchmark.structures.rboxlist_ops import box_iou
from mmdet.core.bbox.bbox_dis import get_roi2align
@IOU_CALCULATORS.register_module()
class RboxOverlaps2D(object):
    """2D IoU Calculator."""

    def __call__(self, bboxes1, bboxes2, mode='iou', is_aligned=False):
        """Calculate IoU between 2D bboxes.

        Args:
            bboxes1 (Tensor): bboxes have shape (m, 4) in <x1, y1, x2, y2>
                format, or shape (m, 5) in <x1, y1, x2, y2, score> format.
            bboxes2 (Tensor): bboxes have shape (m, 4) in <x1, y1, x2, y2>
                format, shape (m, 5) in <x1, y1, x2, y2, score> format, or be
                empty. If is_aligned is ``True``, then m and n must be equal.
            mode (str): "iou" (intersection over union) or iof (intersection
                over foreground).

        Returns:
            ious(Tensor): shape (m, n) if is_aligned == False else shape (m, 1)
        """
        assert bboxes1.size(-1) in [0, 4, 5]
        assert bboxes2.size(-1) in [0, 4, 5]
        if bboxes2.size(-1) == 5:
            bboxes2 = bboxes2[..., :4]
        if bboxes1.size(-1) == 5:
            bboxes1 = bboxes1[..., :4]
        bboxes12align = get_roi2align(bboxes1, 590, 1640)
        bboxes22align = get_roi2align(bboxes2, 590, 1640)
        return box_iou(bboxes12align, bboxes22align)

    def __repr__(self):
        """str: a string describing the module"""
        repr_str = self.__class__.__name__ + '()'
        return repr_str

import torch

from .builder import IOU_CALCULATORS
from maskrcnn_benchmark.structures.rboxlist_ops import box_iou
from mmdet.core.bbox.bbox_dis import get_roi2align
@IOU_CALCULATORS.register_module()
class RboxOverlaps2D(object):
    """2D IoU Calculator."""

    def __call__(self, bboxes1, bboxes2, mode='iou', is_aligned=False):
        """Calculate IoU between 2D bboxes.

        Args:
            bboxes1 (Tensor): bboxes have shape (m, 4) in <x1, y1, x2, y2>
                format, or shape (m, 5) in <x1, y1, x2, y2, score> format.
            bboxes2 (Tensor): bboxes have shape (m, 4) in <x1, y1, x2, y2>
                format, shape (m, 5) in <x1, y1, x2, y2, score> format, or be
                empty. If is_aligned is ``True``, then m and n must be equal.
            mode (str): "iou" (intersection over union) or iof (intersection
                over foreground).

        Returns:
            ious(Tensor): shape (m, n) if is_aligned == False else shape (m, 1)
        """
        assert bboxes1.size(-1) in [0, 4, 5]
        assert bboxes2.size(-1) in [0, 4, 5]
        if bboxes2.size(-1) == 5:
            bboxes2 = bboxes2[..., :4]
        if bboxes1.size(-1) == 5:
            bboxes1 = bboxes1[..., :4]
        bboxes12align = get_roi2align(bboxes1, 590, 1640)
        bboxes22align = get_roi2align(bboxes2, 590, 1640)
        return box_iou(bboxes12align, bboxes22align)

    def __repr__(self):
        """str: a string describing the module"""
        repr_str = self.__class__.__name__ + '()'
        return repr_str
2D IoU Calculator. Calculate IoU between 2D bboxes.          Args:             bboxes1 (Tensor): bboxes have shape (m, 4) in <x1, y1, x2, y2>                 format, or shape (m, 5) in <x1, y1, x2, y2, score> format.             bboxes2 (Tensor): bboxes have shape (m, 4) in <x1, y1, x2, y2>                 format, shape (m, 5) in <x1, y1, x2, y2, score> format, or be                 empty. If is_aligned is ``True``, then m and n must be equal.             mode (str): "iou" (intersection over union) or iof (intersection                 over foreground).          Returns:             ious(Tensor): shape (m, n) if is_aligned == False else shape (m, 1) str: a string describing the module