当前位置:网站首页>Basis of target detection (IOU)
Basis of target detection (IOU)
2022-07-03 16:17:00 【victor_ gx】
Fundamentals of target detection (IoU)
What is? IOU?
IOU( Occurring simultaneously than Intersection over Union) It's a term , Used to describe the degree of overlap between two boxes . The larger the overlap area ,IOU The bigger it is .
IOU It is mainly used in applications related to object detection , In this application , Our training model outputs an external rectangle that completely surrounds the target . for example , In the diagram above , We have a green box and a blue box . The green box represents the real box , The blue box represents the prediction box of our model . The purpose of the training model is to continuously improve the output of its prediction frame , Until the blue and green boxes completely overlap , Between two boxes IOU be equal to 1.
IOU It is often used in non maximum suppression , Multiple prediction frames of the same object are eliminated based on the confidence of the detection frame , To ensure the prediction box with the highest retention reliability .
IOU Calculation formula
In target detection , Let's assume that the box 1 from [x1,y1,x2,y2] Express , Same box 2 from [x3,y3,x4,y4] Express , Here's the picture 1 Shown .
here IOU The calculation formula of is as follows :
I o U = A r e a o f I n t e r s e c t i o n o f t w o b o x e s A r e a o f U n i o n o f t w o b o x e s IoU=\frac{Area\ of\ Intersection\ of\ two\ boxes}{Area\ of\ Union\ of\ two\ boxes} IoU=Area of Union of two boxesArea of Intersection of two boxes
Use pictures 2 Shown by the following :
Next, we calculate the area corresponding to the intersection and union of the corresponding rectangular box step by step .
Calculate the intersection area
Intuitive to see , The intersection of two rectangular boxes has many situations , Let's intuitively observe the following figure 3, Obviously, the lower right two rectangular boxes completely coincide, and the intersection area is the largest .
First, we express the coordinates of the intersecting rectangles as [x_inter1,y_inter1,x_inter2,y_inter2], Represent the coordinates of the upper left corner and the lower right corner of the intersecting rectangle respectively .
Then start by defining the reference coordinate system . We use +X The axis is moving to the right ,+Y Computer graphics Convention for axial downward movement .
In order to calculate the coordinates of the upper left corner of the intersecting rectangle , We compare the upper left corner of each box . We can see from the example above ,x_inter1 You can find which box is closer to the right in the upper left corner . Similarly , You can find... By looking at which box's upper left corner is lower than the other box y_inter1. Mathematically speaking , They can be summarized as : x _ i n t e r 1 = m a x ( x 1 , x 3 ) x\_inter1=max(x1,x3) x_inter1=max(x1,x3), y y y_ i n t e r 1 = m a x ( y 1 , y 3 ) inter1=max(y1,y3) inter1=max(y1,y3)
To calculate the coordinates of the lower right corner of the intersecting rectangle , We compare the lower right corner of each box .
x_inter2 You can find by looking at which box's lower right corner is more left .
Similarly , You can find... By looking at which box's lower right corner is higher than the other box y_inter2.
Similarly , They can be summarized as : x _ i n t e r 2 = m a x ( x 2 , x 4 ) x\_inter2=max(x2,x4) x_inter2=max(x2,x4), y y y_ i n t e r 2 = m a x ( y 2 , y 4 ) inter2=max(y2,y4) inter2=max(y2,y4)
Now we have the coordinates of the intersecting rectangles , Then the area of the intersection is the area of the rectangle .( in application , We will use the absolute values of width and height , To ensure that even if the order of boxes changes , The width and height are still positive ; namely , If x_inter1>x_inter2, We will still get a positive value for the width )
w i d t h _ i n t e r = ( x _ i n t e r 2 − x _ i n t e r 1 ) h e i g h t _ i n t e r = ( y _ i n t e r 2 − y _ i n t e r 1 ) a r e a _ i n t e r = w i d t h _ i n t e r ∗ h e i g h t _ i n t e r width\_inter=(x\_inter2-x\_inter1) \\height\_inter=(y\_inter2-y\_inter1) \\area\_inter=width\_inter*height\_inter width_inter=(x_inter2−x_inter1)height_inter=(y_inter2−y_inter1)area_inter=width_inter∗height_inter
Calculate Union area
The union of boxes is the total area covered by two boxes , Pictured 2 Shown .
To find the total area , We first calculate the area of each rectangular box
w i d t h _ b o x 1 = ( x _ 2 − x _ 1 ) h e i g h t _ b o x 1 = ( y _ 2 − y _ 1 ) w i d t h _ b o x 2 = ( x _ 4 − x _ 3 ) h e i g h t _ b o x 2 = ( y _ 4 − y _ 3 ) a r e a _ b o x 1 = w i d t h _ b o x 1 ∗ h e i g h t _ b o x 1 a r e a _ b o x 2 = w i d t h _ b o x 2 ∗ h e i g h t _ b o x 2 width\_box1=(x\_2-x\_1) \\height\_box1=(y\_2-y\_1) \\width\_box2=(x\_4-x\_3) \\height\_box2=(y\_4-y\_3) \\area\_box1=width\_box1*height\_box1 \\area\_box2=width\_box2*height\_box2 width_box1=(x_2−x_1)height_box1=(y_2−y_1)width_box2=(x_4−x_3)height_box2=(y_4−y_3)area_box1=width_box1∗height_box1area_box2=width_box2∗height_box2
If we look at the total area covered by the two boxes , We will see that both boxes cover the part of the intersecting rectangle , That is, the area of the intersecting rectangle is included in box1 Areas and box2 In the region .
Because we only want to calculate the common intersection area once , We can subtract the intersection area we calculated from the total area of the two boxes . namely :
a r e a _ u n i o n = a r e a _ b o x 1 + a r e a _ b o x 2 − a r e a _ i n t e r s e c t i o n area\_union=area\_box1+area\_box2-area\_intersection area_union=area_box1+area_box2−area_intersection
Calculate the ratio of intersection and union
Through the above calculation formula , We calculate the area of the corresponding intersection and union of two rectangular boxes , At this time, the rectangle is IOU The calculation formula is as follows :
I o U = a r e a _ i n t e r a r e a _ u n i o n IoU=\frac{area\_inter}{area\_union} IoU=area_unionarea_inter
Observe the above formula , It can be concluded as follows :
- Two box IOU Can take 0 To 1 Any value between .
- If the two boxes do not intersect , Then their intersection area will be 0, therefore IOU Will also be 0.
- If two completely overlapping rectangular boxes , Then the area of the intersection will be equal to the area of its Union , therefore IOU Will be for 1
Code implementation
def IOU(box1, box2):
x1, y1, x2, y2 = box1
x3, y3, x4, y4 = box2
x_inter1 = max(x1, x3)
y_inter1 = max(y1, y3)
x_inter2 = min(x2, x4)
y_inter2 = min(y2, y4)
width_inter = abs(x_inter2 - x_inter1)
height_inter = abs(y_inter2 - y_inter1)
area_inter = width_inter * height_inter
width_box1 = abs(x2 - x1)
height_box1 = abs(y2 - y1)
width_box2 = abs(x4 - x3)
height_box2 = abs(y4 - y3)
area_box1 = width_box1 * height_box1
area_box2 = width_box2 * height_box2
area_union = area_box1 + area_box2 - area_inter
iou = area_inter / area_union
return iou
- function IOU Accept two boxes , namely box1 and box2 As input . The data in each box is a containing [x1,y1,x2,y2] A list of , It represents the coordinates of the upper left corner and the lower right corner .
- As mentioned earlier , Let's first calculate the area of intersecting rectangles , Then the area of the Union .
- abs The function is python The built-in function used to calculate the absolute value in . This ensures that we will never calculate the result with negative width or negative height .
- Back to IOU yes float Type value , Be situated between 0 and 1 Between .
The operation results are as follows :
边栏推荐
- 在ntpdate同步时间的时候出现“the NTP socket is in use, exiting”
- Microservice sentinel flow control degradation
- Go language self-study series | if else if statement in golang
- [proteus simulation] 74hc595+74ls154 drive display 16x16 dot matrix
- 【Proteus仿真】8×8LED点阵屏仿电梯数字滚动显示
- Is it safe to open an account with flush?
- Effect of ARP package on FTP dump under vxworks-6.6 system
- Pyinstaller is not an internal or external command, nor is it a runnable program or batch file
- 六月 致 -.-- -..- -
- Three dimensional reconstruction of deep learning
猜你喜欢
NSQ源码安装运行过程
Famous blackmail software stops operation and releases decryption keys. Most hospital IOT devices have security vulnerabilities | global network security hotspot on February 14
Asemi rectifier bridge umb10f parameters, umb10f specifications, umb10f package
TCP拥塞控制详解 | 3. 设计空间
Interviewer: how does the JVM allocate and recycle off heap memory
Brush questions -- sword finger offer
Create gradle project
Function introduction of JMeter thread group
Mb10m-asemi rectifier bridge mb10m
Unreal_DataTable 实现Id自增与设置RowName
随机推荐
首发!!lancet饿了么官方文档
[redis foundation] understand redis persistence mechanism together (rdb+aof graphic explanation)
Caching mechanism of Hibernate / session level caching mechanism
NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon
Golang 匿名函数使用
How can technology managers quickly improve leadership?
Extraction of the same pointcut
[system safety] 43 PowerShell malicious code detection series (5) automatic extraction of ten thousand words from abstract syntax tree
请求头不同国家和语言的表示
如何在本机搭建SVN服务器
SDNU_ ACM_ ICPC_ 2022_ Winter_ Practice_ 4th [individual]
0214-27100 a day with little fluctuation
【OpenCV 例程200篇】217. 鼠标交互获取多边形区域(ROI)
Slam learning notes - build a complete gazebo multi machine simulation slam from scratch (I)
Jmeter线程组功能介绍
[200 opencv routines] 217 Mouse interaction to obtain polygon area (ROI)
深入理解 SQL 中的 Grouping Sets 语句
App mobile terminal test [4] APK operation
【Proteus仿真】74HC595+74LS154驱动显示16X16点阵
利用MySQL中的乐观锁和悲观锁实现分布式锁