Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
码农StayUp
yolov7-obb
提交
4cf9745a
Y
yolov7-obb
项目概览
码农StayUp
/
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 搜索 >>
提交
4cf9745a
编写于
4月 01, 2023
作者:
E
Egrt
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
更新obb的map计算
上级
fc89ecf4
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
144 addition
and
57 deletion
+144
-57
.gitignore
.gitignore
+0
-1
get_map.py
get_map.py
+5
-10
model_data/ssdd_classes.txt
model_data/ssdd_classes.txt
+80
-0
utils/nms_rotated/nms_rotated_ext.cp38-win_amd64.pyd
utils/nms_rotated/nms_rotated_ext.cp38-win_amd64.pyd
+0
-0
utils/utils_map.py
utils/utils_map.py
+55
-37
yolo.py
yolo.py
+4
-9
未找到文件。
.gitignore
浏览文件 @
4cf9745a
...
...
@@ -6,7 +6,6 @@ datasets/
Medical_Datasets/
lfw/
logs/
model_data/
.temp_map_out/
2007_train.txt
2007_val.txt
...
...
get_map.py
浏览文件 @
4cf9745a
import
os
import
xml.etree.ElementTree
as
ET
import
cv2
from
PIL
import
Image
from
tqdm
import
tqdm
import
numpy
as
np
from
utils.utils
import
get_classes
from
utils.utils_map
import
get_coco_map
,
get_map
from
utils.utils_rbox
import
poly2hbb
from
yolo
import
YOLO
if
__name__
==
"__main__"
:
...
...
@@ -126,16 +125,12 @@ if __name__ == "__main__":
x4
=
bndbox
.
find
(
'x4'
).
text
y4
=
bndbox
.
find
(
'y4'
).
text
poly
=
np
.
array
([[
x1
,
y1
,
x2
,
y2
,
x3
,
y3
,
x4
,
y4
]],
dtype
=
np
.
int32
)
hbb
=
poly2hbb
(
poly
)
xc
,
yc
,
w
,
h
=
hbb
[
0
]
left
=
xc
-
w
/
2
top
=
yc
-
h
/
2
right
=
xc
+
w
/
2
bottom
=
yc
+
h
/
2
poly
=
poly
.
reshape
(
4
,
2
)
(
x
,
y
),
(
w
,
h
),
angle
=
cv2
.
minAreaRect
(
poly
)
# θ ∈ [0, 90]
if
difficult_flag
:
new_f
.
write
(
"%s %s %s %s %s
difficult
\n
"
%
(
obj_name
,
left
,
top
,
right
,
bottom
))
new_f
.
write
(
"%s %s %s %s %s
%s difficult
\n
"
%
(
obj_name
,
int
(
x
),
int
(
y
),
int
(
w
),
int
(
h
),
angle
))
else
:
new_f
.
write
(
"%s %s %s %s %s
\n
"
%
(
obj_name
,
left
,
top
,
right
,
bottom
))
new_f
.
write
(
"%s %s %s %s %s
%s
\n
"
%
(
obj_name
,
int
(
x
),
int
(
y
),
int
(
w
),
int
(
h
),
angle
))
print
(
"Get ground truth result done."
)
if
map_mode
==
0
or
map_mode
==
3
:
...
...
model_data/ssdd_classes.txt
0 → 100644
浏览文件 @
4cf9745a
person
bicycle
car
motorbike
aeroplane
bus
train
truck
boat
traffic light
fire hydrant
stop sign
parking meter
bench
bird
cat
dog
horse
sheep
cow
elephant
bear
zebra
giraffe
backpack
umbrella
handbag
tie
suitcase
frisbee
skis
snowboard
sports ball
kite
baseball bat
baseball glove
skateboard
surfboard
tennis racket
bottle
wine glass
cup
fork
knife
spoon
bowl
banana
apple
sandwich
orange
broccoli
carrot
hot dog
pizza
donut
cake
chair
sofa
pottedplant
bed
diningtable
toilet
tvmonitor
laptop
mouse
remote
keyboard
cell phone
microwave
oven
toaster
sink
refrigerator
book
clock
vase
scissors
teddy bear
hair drier
toothbrush
utils/nms_rotated/nms_rotated_ext.cp38-win_amd64.pyd
浏览文件 @
4cf9745a
无法预览此类型文件
utils/utils_map.py
浏览文件 @
4cf9745a
...
...
@@ -5,6 +5,7 @@ import operator
import
os
import
shutil
import
sys
try
:
from
pycocotools.coco
import
COCO
from
pycocotools.cocoeval
import
COCOeval
...
...
@@ -28,6 +29,24 @@ import numpy as np
(Right,Bottom)
'''
def
iou_rotate_calculate
(
boxes1
,
boxes2
):
"""
计算旋转面积
boxes1,boxes2格式为x,y,w,h,theta
"""
area1
=
boxes1
[
2
]
*
boxes1
[
3
]
area2
=
boxes2
[
2
]
*
boxes2
[
3
]
r1
=
((
boxes1
[
0
],
boxes1
[
1
]),
(
boxes1
[
2
],
boxes1
[
3
]),
boxes1
[
4
])
r2
=
((
boxes2
[
0
],
boxes2
[
1
]),
(
boxes2
[
2
],
boxes2
[
3
]),
boxes2
[
4
])
int_pts
=
cv2
.
rotatedRectangleIntersection
(
r1
,
r2
)[
1
]
if
int_pts
is
not
None
:
order_pts
=
cv2
.
convexHull
(
int_pts
,
returnPoints
=
True
)
int_area
=
cv2
.
contourArea
(
order_pts
)
ious
=
int_area
*
1.0
/
(
area1
+
area2
-
int_area
)
else
:
ious
=
0
return
ious
def
log_average_miss_rate
(
precision
,
fp_cumsum
,
num_images
):
"""
log-average miss rate:
...
...
@@ -209,7 +228,7 @@ def draw_plot_func(dictionary, n_classes, window_title, plot_title, x_label, out
"""
fig
=
plt
.
gcf
()
# gcf - get current figure
axes
=
plt
.
gca
()
r
=
fig
.
canvas
.
get_renderer
()
r
=
fig
.
canvas
.
manager
.
get_renderer
()
for
i
,
val
in
enumerate
(
sorted_values
):
fp_val
=
fp_sorted
[
i
]
tp_val
=
tp_sorted
[
i
]
...
...
@@ -238,7 +257,7 @@ def draw_plot_func(dictionary, n_classes, window_title, plot_title, x_label, out
if
i
==
(
len
(
sorted_values
)
-
1
):
# largest bar
adjust_axes
(
r
,
t
,
fig
,
axes
)
# set window title
fig
.
canvas
.
set_window_title
(
window_title
)
fig
.
canvas
.
manager
.
set_window_title
(
window_title
)
# write classes in y axis
tick_font_size
=
12
plt
.
yticks
(
range
(
n_classes
),
sorted_keys
,
fontsize
=
tick_font_size
)
...
...
@@ -328,35 +347,37 @@ def get_map(MINOVERLAP, draw_plot, score_threhold=0.5, path = './map_out'):
for
line
in
lines_list
:
try
:
if
"difficult"
in
line
:
class_name
,
left
,
top
,
right
,
bottom
,
_difficult
=
line
.
split
()
class_name
,
x
,
y
,
w
,
h
,
angle
,
_difficult
=
line
.
split
()
is_difficult
=
True
else
:
class_name
,
left
,
top
,
right
,
bottom
=
line
.
split
()
class_name
,
x
,
y
,
w
,
h
,
angle
=
line
.
split
()
except
:
if
"difficult"
in
line
:
line_split
=
line
.
split
()
_difficult
=
line_split
[
-
1
]
bottom
=
line_split
[
-
2
]
right
=
line_split
[
-
3
]
top
=
line_split
[
-
4
]
left
=
line_split
[
-
5
]
angle
=
line_split
[
-
2
]
h
=
line_split
[
-
3
]
w
=
line_split
[
-
4
]
y
=
line_split
[
-
5
]
x
=
line_split
[
-
6
]
class_name
=
""
for
name
in
line_split
[:
-
5
]:
for
name
in
line_split
[:
-
6
]:
class_name
+=
name
+
" "
class_name
=
class_name
[:
-
1
]
class_name
=
class_name
[:
-
1
]
is_difficult
=
True
else
:
line_split
=
line
.
split
()
bottom
=
line_split
[
-
1
]
right
=
line_split
[
-
2
]
top
=
line_split
[
-
3
]
left
=
line_split
[
-
4
]
angle
=
line_split
[
-
1
]
h
=
line_split
[
-
2
]
w
=
line_split
[
-
3
]
y
=
line_split
[
-
4
]
x
=
line_split
[
-
5
]
class_name
=
""
for
name
in
line_split
[:
-
4
]:
for
name
in
line_split
[:
-
5
]:
class_name
+=
name
+
" "
class_name
=
class_name
[:
-
1
]
bbox
=
left
+
" "
+
top
+
" "
+
right
+
" "
+
bottom
bbox
=
x
+
" "
+
y
+
" "
+
w
+
" "
+
h
+
" "
+
angle
if
is_difficult
:
bounding_boxes
.
append
({
"class_name"
:
class_name
,
"bbox"
:
bbox
,
"used"
:
False
,
"difficult"
:
True
})
is_difficult
=
False
...
...
@@ -396,21 +417,22 @@ def get_map(MINOVERLAP, draw_plot, score_threhold=0.5, path = './map_out'):
lines
=
file_lines_to_list
(
txt_file
)
for
line
in
lines
:
try
:
tmp_class_name
,
confidence
,
left
,
top
,
right
,
bottom
=
line
.
split
()
tmp_class_name
,
confidence
,
x
,
y
,
w
,
h
,
angle
=
line
.
split
()
except
:
line_split
=
line
.
split
()
bottom
=
line_split
[
-
1
]
right
=
line_split
[
-
2
]
top
=
line_split
[
-
3
]
left
=
line_split
[
-
4
]
confidence
=
line_split
[
-
5
]
angle
=
line_split
[
-
1
]
h
=
line_split
[
-
2
]
w
=
line_split
[
-
3
]
y
=
line_split
[
-
4
]
x
=
line_split
[
-
5
]
confidence
=
line_split
[
-
6
]
tmp_class_name
=
""
for
name
in
line_split
[:
-
5
]:
for
name
in
line_split
[:
-
6
]:
tmp_class_name
+=
name
+
" "
tmp_class_name
=
tmp_class_name
[:
-
1
]
if
tmp_class_name
==
class_name
:
bbox
=
left
+
" "
+
top
+
" "
+
right
+
" "
+
bottom
bbox
=
x
+
" "
+
y
+
" "
+
w
+
" "
+
h
+
" "
+
angle
bounding_boxes
.
append
({
"confidence"
:
confidence
,
"file_id"
:
file_id
,
"bbox"
:
bbox
})
bounding_boxes
.
sort
(
key
=
lambda
x
:
float
(
x
[
'confidence'
]),
reverse
=
True
)
...
...
@@ -464,17 +486,13 @@ def get_map(MINOVERLAP, draw_plot, score_threhold=0.5, path = './map_out'):
bb
=
[
float
(
x
)
for
x
in
detection
[
"bbox"
].
split
()]
for
obj
in
ground_truth_data
:
if
obj
[
"class_name"
]
==
class_name
:
bbgt
=
[
float
(
x
)
for
x
in
obj
[
"bbox"
].
split
()
]
bi
=
[
max
(
bb
[
0
],
bbgt
[
0
]),
max
(
bb
[
1
],
bbgt
[
1
]),
min
(
bb
[
2
],
bbgt
[
2
]),
min
(
bb
[
3
],
bbgt
[
3
])]
iw
=
bi
[
2
]
-
bi
[
0
]
+
1
ih
=
bi
[
3
]
-
bi
[
1
]
+
1
if
iw
>
0
and
ih
>
0
:
ua
=
(
bb
[
2
]
-
bb
[
0
]
+
1
)
*
(
bb
[
3
]
-
bb
[
1
]
+
1
)
+
(
bbgt
[
2
]
-
bbgt
[
0
]
+
1
)
*
(
bbgt
[
3
]
-
bbgt
[
1
]
+
1
)
-
iw
*
ih
ov
=
iw
*
ih
/
ua
if
ov
>
ovmax
:
ovmax
=
ov
gt_match
=
obj
bbgt
=
[
float
(
x
)
for
x
in
obj
[
"bbox"
].
split
()
]
box1
=
np
.
array
([
bb
[
0
],
bb
[
1
],
bb
[
2
],
bb
[
3
],
bb
[
4
]],
np
.
float32
)
box2
=
np
.
array
([
bbgt
[
0
],
bbgt
[
1
],
bbgt
[
2
],
bbgt
[
3
],
bbgt
[
4
]],
np
.
float32
)
ov
=
iou_rotate_calculate
(
box1
,
box2
)
if
ov
>
ovmax
:
ovmax
=
ov
gt_match
=
obj
if
show_animation
:
status
=
"NO MATCH FOUND!"
...
...
@@ -606,7 +624,7 @@ def get_map(MINOVERLAP, draw_plot, score_threhold=0.5, path = './map_out'):
plt
.
fill_between
(
area_under_curve_x
,
0
,
area_under_curve_y
,
alpha
=
0.2
,
edgecolor
=
'r'
)
fig
=
plt
.
gcf
()
fig
.
canvas
.
set_window_title
(
'AP '
+
class_name
)
fig
.
canvas
.
manager
.
set_window_title
(
'AP '
+
class_name
)
plt
.
title
(
'class: '
+
text
)
plt
.
xlabel
(
'Recall'
)
...
...
@@ -782,7 +800,7 @@ def get_map(MINOVERLAP, draw_plot, score_threhold=0.5, path = './map_out'):
plot_title
=
"mAP = {0:.2f}%"
.
format
(
mAP
*
100
)
x_label
=
"Average Precision"
output_path
=
RESULTS_FILES_PATH
+
"/mAP.png"
to_show
=
Tru
e
to_show
=
Fals
e
plot_color
=
'royalblue'
draw_plot_func
(
ap_dictionary
,
...
...
yolo.py
浏览文件 @
4cf9745a
...
...
@@ -376,22 +376,17 @@ 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
=
rbox2poly
(
top_rboxes
)
top_hbbs
=
poly2hbb
(
top_polys
)
for
i
,
c
in
list
(
enumerate
(
top_label
)):
predicted_class
=
self
.
class_names
[
int
(
c
)]
hbb
=
top_hbb
s
[
i
]
obb
=
top_rboxe
s
[
i
]
score
=
str
(
top_conf
[
i
])
xc
,
yc
,
w
,
h
=
hbb
left
=
xc
-
w
/
2
top
=
yc
-
h
/
2
right
=
xc
+
w
/
2
bottom
=
yc
+
h
/
2
xc
,
yc
,
w
,
h
,
angle
=
obb
if
predicted_class
not
in
class_names
:
continue
f
.
write
(
"%s %s %s %s %s %s
\n
"
%
(
predicted_class
,
score
[:
6
],
str
(
int
(
left
)),
str
(
int
(
top
)),
str
(
int
(
right
)),
str
(
int
(
bottom
))))
f
.
write
(
"%s %s %s %s %s %s
%s
\n
"
%
(
predicted_class
,
score
[:
6
],
str
(
int
(
xc
)),
str
(
int
(
yc
)),
str
(
int
(
w
)),
str
(
int
(
h
)),
str
(
math
.
degrees
(
angle
))))
f
.
close
()
return
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录