Comments (6)
hi,
it's because oriented_box_intersection_2d
expects the corner points are counter-clockwise ordered. But your points seem clockwise ordered. I only test my code with counter-clockwise order so it might have a strange behavior with the other orders.
I modify your test case by reordering the points. The results are then consistent.
import torch
import numpy as np
from box_intersection_2d import oriented_box_intersection_2d
device = torch.device("cuda:0")
# load 2 group of boxes, each group contains 9 boxes.
boxes1 = torch.from_numpy(np.load('boxes1.npy')).to(device).float()
boxes2 = torch.from_numpy(np.load('boxes2.npy')).to(device).float()
# reorder so that points are counter-clockwise ordered
boxes1[:, :, [0, 1, 2, 3], :] = boxes1[:, :, [3, 2, 1, 0], :].contiguous()
boxes2[:, :, [0, 1, 2, 3], :] = boxes2[:, :, [3, 2, 1, 0], :].contiguous()
area, _ = oriented_box_intersection_2d(boxes1,boxes2)
print(area)
# calculate intersetion of boxes in the center
box1 = boxes1[1,1].reshape(1,1,4,2)
box2 = boxes2[1,1].reshape(1,1,4,2)
area1, _ = oriented_box_intersection_2d(box1,box2)
print(area1)
# calculate intersetion of boxes in the center row
box_row1 = boxes1[1,:].reshape(3,1,4,2)
box_row2 = boxes2[1,:].reshape(3,1,4,2)
area_row, _ = oriented_box_intersection_2d(box_row1,box_row2)
print(area_row)
# calculate intersetion of boxes in the center column
box_col1 = boxes1[:,1].reshape(1,3,4,2)
box_col2 = boxes2[:,1].reshape(1,3,4,2)
area_col, _ = oriented_box_intersection_2d(box_col1,box_col2)
print(area_col)
The results are:
tensor([[1920.7974, 221.0000, 0.0000],
[1980.3770, 221.0000, 0.0000],
[ 570.9585, 32.7373, 0.0000]], device='cuda:0')
tensor([[221.]], device='cuda:0')
tensor([[1980.3770],
[ 221.0000],
[ 0.0000]], device='cuda:0')
tensor([[221.0000, 221.0000, 32.7373]], device='cuda:0')
from rotated_iou.
Got it! Thanks a lot for your help.
from rotated_iou.
大佬你好,我切换为逆时针后测试了一会发现还是有问题,总结如下:
- 大部分情况下,逆时针顺时针计算所得结果是一样的,而且是正确的
- 两者偶尔都会出现错误值,体现在计算出来的intersection过大(过大的会导致iou大于1,很容易看出来,不知道会不会偏小)
- 存在两者一个错一个对的情况,也存在都错的情况,整体来看逆时针相对较稳定些.
我觉得这不太合理,如果真的是这么不稳定的话就没法用了,所以我考虑是不是我哪里搞错了,麻烦您有时间帮忙看一下,这是我选的一组两个结果都不对的数据,这次载入的数据就是逆时针的,后面改成顺时针又重复计算了一次:
import torch
import numpy as np
from box_intersection_2d import oriented_box_intersection_2d
device = torch.device("cuda:0")
# load 2 group of boxes, each group contains 9 boxes.
print('载入的框角点顺序已修改为逆时针')
boxes1 = torch.from_numpy(np.load('boxes1.npy')).to(device).float()
boxes2 = torch.from_numpy(np.load('boxes2.npy')).to(device).float()
area, _ = oriented_box_intersection_2d(boxes1,boxes2)
print(area)
# calculate intersetion of boxes in the center
box1 = boxes1[1,1].reshape(1,1,4,2).float()
box2 = boxes2[1,1].reshape(1,1,4,2).float()
area1, _ = oriented_box_intersection_2d(box1,box2)
print(area1)
# calculate intersetion of boxes in the center row
box_row1 = boxes1[1,:].reshape(3,1,4,2)
box_row2 = boxes2[1,:].reshape(3,1,4,2)
area_row, _ = oriented_box_intersection_2d(box_row1,box_row2)
print(area_row)
# calculate intersetion of boxes in the center column
box_col1 = boxes1[:,1].reshape(1,3,4,2)
box_col2 = boxes2[:,1].reshape(1,3,4,2)
area_col, _ = oriented_box_intersection_2d(box_col1,box_col2)
print(area_col)
# 把点的顺序切换回顺时针
print('把点的顺序切换回顺时针再计算')
boxes1[:, :, [0, 1, 2, 3], :] = boxes1[:, :, [3, 2, 1, 0], :].contiguous()
boxes2[:, :, [0, 1, 2, 3], :] = boxes2[:, :, [3, 2, 1, 0], :].contiguous()
area, _ = oriented_box_intersection_2d(boxes1,boxes2)
print(area)
# calculate intersetion of boxes in the center
box1 = boxes1[1,1].reshape(1,1,4,2)
box2 = boxes2[1,1].reshape(1,1,4,2)
area1, _ = oriented_box_intersection_2d(box1,box2)
print(area1)
# calculate intersetion of boxes in the center row
box_row1 = boxes1[1,:].reshape(3,1,4,2)
box_row2 = boxes2[1,:].reshape(3,1,4,2)
area_row, _ = oriented_box_intersection_2d(box_row1,box_row2)
print(area_row)
# calculate intersetion of boxes in the center column
box_col1 = boxes1[:,1].reshape(1,3,4,2)
box_col2 = boxes2[:,1].reshape(1,3,4,2)
area_col, _ = oriented_box_intersection_2d(box_col1,box_col2)
print(area_col)
下面是程序的输出
载入的框角点顺序已修改为逆时针
tensor([[1086.5820, 1474.9424, 315.2656],
[1020.2642, 2082.3574, 318.6777],
[ 960.2954, 1356.2568, 327.6221]], device='cuda:0')
tensor([[2082.3574]], device='cuda:0')
tensor([[1020.2642],
[2082.3574],
[2905.8066]], device='cuda:0')
tensor([[1474.9424, 2082.3574, 1356.2568]], device='cuda:0')
把点的顺序切换回顺时针再计算
tensor([[1086.5820, 1474.9424, 315.2656],
[1020.2651, 1872.7114, 318.6777],
[ 960.2939, 1356.2573, 327.6230]], device='cuda:0')
tensor([[1872.7114]], device='cuda:0')
tensor([[1020.2651],
[1872.7114],
[ 169.1211]], device='cuda:0')
tensor([[1474.9424, 1872.7114, 1356.2573]], device='cuda:0')
经过我画图实测,中间位置的两个box iou应该是1382左右,顺时针和逆时针的计算结果一个是2082,一个是1872,都是错误的.下面是相关文件链接,拜托您有时间帮忙看一下,不胜感激.
boxes1
boxes2
iou figure
from rotated_iou.
你好,你数据里有的图形好像不是严格的矩形。比如 boxes1[1,1] 的四个顶点分别是
A = [144, 170]
B = [92, 130]
C = [111, 106]
D = [162, 145]
理论上应该存在严格的 x_A - x_B = x_D - x_C 和 y_A - y_B = y_D - y_C。 但是在这个数据里稍微偏离了一些。我的代码在判断一些几何关系的时候利用了矩形的性质(例如直角,平行),对于不严格的数据,结果就不对了(虽然结果差这么多我也挺意外的)。我的建议是不要直接输入四个坐标点,而是输入中心坐标,长宽和旋转角,通过box2corners_th
函数计算四个角的坐标。这样可以保证四个角点是严格的矩形。
另外我自己用这个代码train过目标检测的网络,还没有遇到过IoU大于1的情况,所以我感觉输入数据有异常的可能性比较大。
from rotated_iou.
好的,感觉应该是就是这个原因了,我明天输入中心坐标,长宽和旋转角,使用您的函数反求再测试一下,感谢您的回复与帮助。
from rotated_iou.
使用box2corners_th
函数反求坐标点之后,测试了这么几天都没有再出现过问题了,再次感谢您的帮助
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.