Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Tc.小浩
yolov7-obb
提交
9cfb1889
Y
yolov7-obb
项目概览
Tc.小浩
/
yolov7-obb
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Y
yolov7-obb
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
9cfb1889
编写于
2月 11, 2023
作者:
_白鹭先生_
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
修复显示
上级
b3de457d
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
39 addition
and
23 deletion
+39
-23
utils/callbacks.py
utils/callbacks.py
+0
-2
utils/utils_bbox.py
utils/utils_bbox.py
+34
-1
utils/utils_rbox.py
utils/utils_rbox.py
+3
-16
yolo.py
yolo.py
+2
-4
未找到文件。
utils/callbacks.py
浏览文件 @
9cfb1889
...
...
@@ -149,8 +149,6 @@ class EvalCallback():
top_conf
=
results
[
0
][:,
5
]
*
results
[
0
][:,
6
]
top_rboxes
=
results
[
0
][:,
:
5
]
top_polys
=
rbox2poly
(
top_rboxes
)
top_polys
[:,
0
::
2
]
*=
image_shape
[
1
]
top_polys
[:,
1
::
2
]
*=
image_shape
[
0
]
top_hbbs
=
poly2hbb
(
top_polys
)
top_100
=
np
.
argsort
(
top_conf
)[::
-
1
][:
self
.
max_boxes
]
top_hbbs
=
top_hbbs
[
top_100
]
...
...
utils/utils_bbox.py
浏览文件 @
9cfb1889
import
numpy
as
np
import
torch
import
math
from
torchvision.ops
import
nms
from
utils.utils_rbox
import
*
from
utils.nms_rotated
import
obb_nms
class
DecodeBox
():
...
...
@@ -183,8 +183,41 @@ class DecodeBox():
if
output
[
i
]
is
not
None
:
output
[
i
]
=
output
[
i
].
cpu
().
numpy
()
output
[
i
][:,
:
5
]
=
self
.
yolo_correct_boxes
(
output
[
i
],
input_shape
,
image_shape
,
letterbox_image
)
return
output
def
yolo_correct_boxes
(
self
,
output
,
input_shape
,
image_shape
,
letterbox_image
):
#-----------------------------------------------------------------#
# 把y轴放前面是因为方便预测框和图像的宽高进行相乘
#-----------------------------------------------------------------#
box_xy
=
output
[...,
0
:
2
]
box_wh
=
output
[...,
2
:
4
]
angle
=
output
[...,
4
:
5
]
box_yx
=
box_xy
[...,
::
-
1
]
box_hw
=
box_wh
[...,
::
-
1
]
input_shape
=
np
.
array
(
input_shape
)
image_shape
=
np
.
array
(
image_shape
)
if
letterbox_image
:
#-----------------------------------------------------------------#
# 这里求出来的offset是图像有效区域相对于图像左上角的偏移情况
# new_shape指的是宽高缩放情况
#-----------------------------------------------------------------#
new_shape
=
np
.
round
(
image_shape
*
np
.
min
(
input_shape
/
image_shape
))
offset
=
(
input_shape
-
new_shape
)
/
2.
/
input_shape
scale
=
input_shape
/
new_shape
box_yx
=
(
box_yx
-
offset
)
*
scale
box_hw
*=
scale
box_xy
=
box_yx
[:,
::
-
1
]
box_hw
=
box_wh
[:,
::
-
1
]
rboxes
=
np
.
concatenate
([
box_xy
,
box_wh
,
angle
],
axis
=-
1
)
rboxes
[:,
[
0
,
2
]]
*=
image_shape
[
1
]
rboxes
[:,
[
1
,
3
]]
*=
image_shape
[
0
]
return
rboxes
if
__name__
==
"__main__"
:
import
matplotlib.pyplot
as
plt
import
numpy
as
np
...
...
utils/utils_rbox.py
浏览文件 @
9cfb1889
...
...
@@ -2,7 +2,7 @@
Author: [egrt]
Date: 2023-01-30 19:00:28
LastEditors: [egrt]
LastEditTime: 2023-02-10
14:16:06
LastEditTime: 2023-02-10
22:44:35
Description: Oriented Bounding Boxes utils
'''
...
...
@@ -198,18 +198,5 @@ def correct_rboxes(rboxes, image_shape):
nh
,
nw
=
image_shape
polys
[:,
[
0
,
2
,
4
,
6
]]
*=
nw
polys
[:,
[
1
,
3
,
5
,
7
]]
*=
nh
rboxes
=
poly2rbox
(
polys
)
correct_polys
=
[]
for
rbox
in
rboxes
:
xc
,
yc
,
h
,
w
,
ag
=
rbox
[:
5
]
wx
,
wy
=
-
w
/
2
*
math
.
sin
(
ag
),
w
/
2
*
math
.
cos
(
ag
)
hx
,
hy
=
h
/
2
*
math
.
cos
(
ag
),
h
/
2
*
math
.
sin
(
ag
)
point_x1
,
point_y1
=
xc
-
wx
-
hx
,
yc
-
wy
-
hy
point_x2
,
point_y2
=
xc
-
wx
+
hx
,
yc
-
wy
+
hy
point_x3
,
point_y3
=
xc
+
wx
+
hx
,
yc
+
wy
+
hy
point_x4
,
point_y4
=
xc
+
wx
-
hx
,
yc
+
wy
-
hy
poly
=
np
.
array
([
point_x1
,
point_y1
,
point_x2
,
point_y2
,
point_x3
,
point_y3
,
point_x4
,
point_y4
])
correct_polys
.
append
(
poly
)
correct_polys
=
np
.
array
(
correct_polys
)
return
correct_polys
return
polys
yolo.py
浏览文件 @
9cfb1889
...
...
@@ -55,7 +55,7 @@ class YOLO(object):
# 该变量用于控制是否使用letterbox_image对输入图像进行不失真的resize,
# 在多次测试后,发现关闭letterbox_image直接resize的效果更好
#---------------------------------------------------------------------#
"letterbox_image"
:
Fals
e
,
"letterbox_image"
:
Tru
e
,
#-------------------------------#
# 是否使用Cuda
# 没有GPU可以设置成False
...
...
@@ -157,7 +157,7 @@ class YOLO(object):
top_label
=
np
.
array
(
results
[
0
][:,
7
],
dtype
=
'int32'
)
top_conf
=
results
[
0
][:,
5
]
*
results
[
0
][:,
6
]
top_rboxes
=
results
[
0
][:,
:
5
]
top_polys
=
correct_rboxes
(
top_rboxes
,
image_shape
)
top_polys
=
rbox2poly
(
top_rboxes
)
#---------------------------------------------------------#
# 设置字体与边框厚度
#---------------------------------------------------------#
...
...
@@ -377,8 +377,6 @@ class YOLO(object):
top_conf
=
results
[
0
][:,
5
]
*
results
[
0
][:,
6
]
top_rboxes
=
results
[
0
][:,
:
5
]
top_polys
=
rbox2poly
(
top_rboxes
)
top_polys
[:,
0
::
2
]
*=
image_shape
[
1
]
top_polys
[:,
1
::
2
]
*=
image_shape
[
0
]
top_hbbs
=
poly2hbb
(
top_polys
)
for
i
,
c
in
list
(
enumerate
(
top_label
)):
predicted_class
=
self
.
class_names
[
int
(
c
)]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录