GithubHelp home page GithubHelp logo

Comments (6)

Eralien avatar Eralien commented on June 29, 2024

I have a simple solution for the corners problem: simply add a translation to all boxes if any of their corners coordinates is negative.

def cal_iou(box1: torch.Tensor, box2: torch.Tensor):
    """calculate iou
    Args:
        box1 (torch.Tensor): (B, N, 5) with x, y, w, h, alpha
        box2 (torch.Tensor): (B, N, 5) with x, y, w, h, alpha

    Returns:
        iou (torch.Tensor): (B, N)
        corners1 (torch.Tensor): (B, N, 4, 2)
        corners1 (torch.Tensor): (B, N, 4, 2)
        U (torch.Tensor): (B, N) area1 + area2 - inter_area
    """
    corners1 = box2corners_th(box1)
    corners2 = box2corners_th(box2)

    # calculate the min corner coordinates
    corners_min = torch.minimum(corners1, corners2).amin(-2) - 1e-5   # eps
    # if any element is negative, translate all coordinates to positive number
    if corners_min.lt(0).any():
        corners1_positive = corners1 - corners_min
        corners2_positive = corners2 - corners_min
        inter_area, _ = oriented_box_intersection_2d(corners1_positive, corners2_positive)    # (B, N)
    else:
        # if not, directly calculate the intersection area
        inter_area, _ = oriented_box_intersection_2d(corners1, corners2)    # (B, N)
    area1 = box1[:, :, 2] * box1[:, :, 3]
    area2 = box2[:, :, 2] * box2[:, :, 3]
    u = area1 + area2 - inter_area
    iou = inter_area / u
    return iou, corners1, corners2, u

I tested the results against the one implemented in detectron2, and the results difference for 1000 random tests are within 1e-3.

from rotated_iou.

rubbish001 avatar rubbish001 commented on June 29, 2024

代码有问题,不知道怎么改,求作者更新代码

from rotated_iou.

lilanxiao avatar lilanxiao commented on June 29, 2024

hi, thank you for the issue and workaround.
I've just updated my code in the debug branch. I think the new version is probably more stable.
Please let me know if the problem persists.

from rotated_iou.

Eralien avatar Eralien commented on June 29, 2024

hi, thank you for the issue and workaround. I've just updated my code in the debug branch. I think the new version is probably more stable. Please let me know if the problem persists.

Thanks! Will test soon.

from rotated_iou.

rubbish001 avatar rubbish001 commented on June 29, 2024

还是会出现nan

from rotated_iou.

xiazhiyi99 avatar xiazhiyi99 commented on June 29, 2024

same problem
Can we simply add a constant big value to the corners at the beginning like this?

def cal_iou(box1:Tensor, box2:Tensor):
    corners1 = box2corners_th(box1) + 100
    corners2 = box2corners_th(box2) + 100
    ...

I tried it and it seems fine.

from rotated_iou.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.