Comments (13)
@kevinghst
thank you for the issue! Yeah, it seems my dark magic didn't work. The true reason of the error was the vertices of the intersection polygon were duplicated (we only need 4, but would get 8) if the two boxes were exactly the same. In this case, the shoelace formula was broken. Also, there was still some numerically instability in my code.
I hope the bug is now properly fixed in commit 6267cef . This time I've modified the CUDA part and removed the magic. BTW, please remember to re-compile the CUDA extension.
from rotated_iou.
Probably this EPSILON
stuff is not the best idea here.
After replacing
t = den_t / (num + EPSILON)
mask_t = (t >= 0) * (t < 1)
...
u = - den_u / (num + EPSILON)
mask_u = (u >= 0) * (u < 1)
with
t = den_t / num
t[num == .0] = -1.
mask_t = (t >= 0) * (t <= 1)
...
u = -den_u / num
u[num == .0] = -1.
mask_u = (u >= 0) * (u <= 1)
everything looks fine.
from rotated_iou.
@filaPro
Hi, thank you for the issue and the example!
It's definitely a bug. It happens when two edges "perfectly" overlap. I've changed the box_1
in your code a little bit. With just a tiny offset, the function returns correct result. All following three values works.
EPSILON = 1e-6
device = torch.device('cuda:0')
box_0 = torch.tensor([.0, .0, 2., 2., .0], device=device)
box_1 = torch.tensor([EPSILON, 2, 2., 2., .0], device=device) # return 0
# box_1 = torch.tensor([.0, 2, 2-EPSILON, 2., .0], device=device) # return 0
# box_1 = torch.tensor([.0, 2, 2., 2., EPSILON], device=device) # return 5.960465e-08
print(cal_iou(box_0[None, None, ...], box_1[None, None, ...])[0].cpu().numpy())
It's probably not a big issue in practice because It's quite unlikely that the predicted bounding box and the ground truth would overlap in such a way.
But I'll still check my code again and let you know when I figure it out.
from rotated_iou.
Looks like this case:
box_0 = torch.tensor([.0, .0, 2., 2., .0], device=device)
box_1 = torch.tensor([.0, 1., 2., 2., .0], device=device)
is also incorrect for now. However the solution above helps.
from rotated_iou.
@filaPro
Nice catch! Thank you very much for the solution!
It fixed the incorrect IoU value but I got nan
when I ran the demo.py
. Perhaps there is still some numerical instability somewhere.
from rotated_iou.
@filaPro
I have fixed the IoU value bug and the stability issue in a new commit.
Thank you again!
from rotated_iou.
Thanks a lot!
Do you have an intuition why we need this t = den_t / (num + EPSILON)
? I see that it is unstable otherwise. But nan
values here was masked out by mask_t
...
from rotated_iou.
For this case:
box_0 = torch.tensor([.0, .0, 2., 2., .0], device=device)
box_1 = torch.tensor([.0, 0., 2., 2., .0], device=device)
the answer is inf
now. May be the problem is a little bit deeper.
from rotated_iou.
@filaPro
For the nan problem. If I remember it correctly, nan follows 0 * nan = nan
, according to the definition of IEEE.
I spent some time on this issue. The problem is how I formulate the problem. I split the problem to 4 sub-problems.
- find corners of one box located in anther box ("corners in box")
- find intersection points of edges ("intersection points")
- assume these corners in box and intersection points are the vertices of the intersection polygon, sort the vertices in clockwise or anti-clockwise order
- apply shoelace formula to get the area.
The trouble is, how to define "corner in box" and "intersection points", when two edges are collinear. For example, with following two boxes, how many "corners in box" should be counted? 0 or 2 ? Where is the intersection points? Or do they exist?
box_0 = torch.tensor([.0, .0, 2., 2., .0], device=device)
box_1 = torch.tensor([.0, 2., 2., 2., .0], device=device)
My previous code didn't cover these edge cases well so it delivered wrong value. I tried to fix it and the result seems good now.
But to be honest, I'm not sure if it's the best solution and if all corner cases are covered... Also, I am not very clear why current version works...
from rotated_iou.
Looks like 1st question can be answered easily. However to answer properly on the 2nd question we need more code to manually intersect 2 edges, in case they are collinear. Current version still doesn't cover the case of 2 equal boxes :(
from rotated_iou.
I committed several times. I think the most recent commit (a63b0fb) covers the case of 2 equal boxes. Did you try it?
from rotated_iou.
Sorry, now it's fine. Everything works on some kind of magic :)
from rotated_iou.
IOU still not working properly.
params1 = params2 = [38, 120, 1.3, 20, 50]
I get .333, instead of 1...
from rotated_iou.
Related Issues (20)
- box_intersection_2d 中的box1_in_box2存在bug, box1_in_box2(box1,box1), 在特定数据下返回的不是[true,true,true,true] HOT 1
- 在做批量的旋转iou计算时,计算的inter_area会出现nan值,导致loss变为nan,但是在把计算为nan的两个box的x,y,w,h,angle提出来单个计算的话就会出现正常的inter_area。请问这是什么原因导致的呢,还请解答 HOT 7
- is this result correct? HOT 2
- Inaccurate IoU in some cases HOT 8
- Wrong IoU calculation when corners are smaller than 0 HOT 6
- Yolact
- About the 2D coordinates (x, y, w, h, alpha) HOT 2
- 请教大佬代码实现问题 HOT 2
- Please Help HOT 1
- warning: missing return statement at end of non-void function "compare_vertices" HOT 6
- debug版本报错 HOT 3
- a problem when using 3d-giou for regression training HOT 2
- 大佬,求助,CUDA out of memory HOT 12
- inf bbox loss when using cal_giou_3d ( but the iou is right)
- Batch computation for IoU Loss HOT 1
- debug版本和老的版本计算结果不一致
- 为什么input shape是 B,N,4,2?
- Segmentation fault
- `np.bool` was a deprecated alias for the builtin `bool`.
- problems with the import of sort_vertices HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rotated_iou.