Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Calabaza amarga
yolo3-pytorch
提交
bca67afa
Y
yolo3-pytorch
项目概览
Calabaza amarga
/
yolo3-pytorch
与 Fork 源项目一致
从无法访问的项目Fork
通知
5
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Y
yolo3-pytorch
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
bca67afa
编写于
11月 02, 2020
作者:
B
Bubbliiiing
提交者:
GitHub
11月 02, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add files via upload
上级
44bb18af
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
75 addition
and
15 deletion
+75
-15
get_gt_txt.py
get_gt_txt.py
+8
-4
get_map.py
get_map.py
+59
-7
voc_annotation.py
voc_annotation.py
+8
-4
未找到文件。
get_gt_txt.py
浏览文件 @
bca67afa
...
...
@@ -7,7 +7,6 @@ import sys
import
os
import
glob
import
xml.etree.ElementTree
as
ET
from
tqdm
import
tqdm
image_ids
=
open
(
'VOCdevkit/VOC2007/ImageSets/Main/test.txt'
).
read
().
strip
().
split
()
...
...
@@ -16,19 +15,24 @@ if not os.path.exists("./input"):
if
not
os
.
path
.
exists
(
"./input/ground-truth"
):
os
.
makedirs
(
"./input/ground-truth"
)
for
image_id
in
tqdm
(
image_ids
)
:
for
image_id
in
image_ids
:
with
open
(
"./input/ground-truth/"
+
image_id
+
".txt"
,
"w"
)
as
new_f
:
root
=
ET
.
parse
(
"VOCdevkit/VOC2007/Annotations/"
+
image_id
+
".xml"
).
getroot
()
for
obj
in
root
.
findall
(
'object'
):
difficult_flag
=
False
if
obj
.
find
(
'difficult'
)
!=
None
:
difficult
=
obj
.
find
(
'difficult'
).
text
if
int
(
difficult
)
==
1
:
contin
ue
difficult_flag
=
Tr
ue
obj_name
=
obj
.
find
(
'name'
).
text
bndbox
=
obj
.
find
(
'bndbox'
)
left
=
bndbox
.
find
(
'xmin'
).
text
top
=
bndbox
.
find
(
'ymin'
).
text
right
=
bndbox
.
find
(
'xmax'
).
text
bottom
=
bndbox
.
find
(
'ymax'
).
text
new_f
.
write
(
"%s %s %s %s %s
\n
"
%
(
obj_name
,
left
,
top
,
right
,
bottom
))
if
difficult_flag
:
new_f
.
write
(
"%s %s %s %s %s difficult
\n
"
%
(
obj_name
,
left
,
top
,
right
,
bottom
))
else
:
new_f
.
write
(
"%s %s %s %s %s
\n
"
%
(
obj_name
,
left
,
top
,
right
,
bottom
))
print
(
"Conversion completed!"
)
get_map.py
浏览文件 @
bca67afa
...
...
@@ -346,7 +346,10 @@ if os.path.exists(results_files_path): # if it exist already
os
.
makedirs
(
results_files_path
)
if
draw_plot
:
os
.
makedirs
(
os
.
path
.
join
(
results_files_path
,
"classes"
))
os
.
makedirs
(
os
.
path
.
join
(
results_files_path
,
"AP"
))
os
.
makedirs
(
os
.
path
.
join
(
results_files_path
,
"F1"
))
os
.
makedirs
(
os
.
path
.
join
(
results_files_path
,
"Recall"
))
os
.
makedirs
(
os
.
path
.
join
(
results_files_path
,
"Precision"
))
if
show_animation
:
os
.
makedirs
(
os
.
path
.
join
(
results_files_path
,
"images"
,
"detections_one_by_one"
))
...
...
@@ -503,6 +506,7 @@ lamr_dictionary = {}
with
open
(
results_files_path
+
"/results.txt"
,
'w'
)
as
results_file
:
results_file
.
write
(
"# AP and precision/recall per class
\n
"
)
count_true_positives
=
{}
for
class_index
,
class_name
in
enumerate
(
gt_classes
):
count_true_positives
[
class_name
]
=
0
"""
...
...
@@ -517,8 +521,14 @@ with open(results_files_path + "/results.txt", 'w') as results_file:
nd
=
len
(
dr_data
)
tp
=
[
0
]
*
nd
# creates an array of zeros of size nd
fp
=
[
0
]
*
nd
score
=
[
0
]
*
nd
score05_idx
=
0
for
idx
,
detection
in
enumerate
(
dr_data
):
file_id
=
detection
[
"file_id"
]
score
[
idx
]
=
float
(
detection
[
"confidence"
])
if
score
[
idx
]
>
0.5
:
score05_idx
=
idx
if
show_animation
:
# find ground truth image
ground_truth_img
=
glob
.
glob1
(
IMG_PATH
,
file_id
+
".*"
)
...
...
@@ -652,7 +662,6 @@ with open(results_files_path + "/results.txt", 'w') as results_file:
# save the image with all the objects drawn to it
cv2
.
imwrite
(
img_cumulative_path
,
img_cumulative
)
#print(tp)
# compute precision/recall
cumsum
=
0
for
idx
,
val
in
enumerate
(
fp
):
...
...
@@ -664,6 +673,7 @@ with open(results_files_path + "/results.txt", 'w') as results_file:
cumsum
+=
val
#print(tp)
rec
=
tp
[:]
for
idx
,
val
in
enumerate
(
tp
):
rec
[
idx
]
=
float
(
tp
[
idx
])
/
gt_counter_per_class
[
class_name
]
#print(rec)
...
...
@@ -671,10 +681,20 @@ with open(results_files_path + "/results.txt", 'w') as results_file:
for
idx
,
val
in
enumerate
(
tp
):
prec
[
idx
]
=
float
(
tp
[
idx
])
/
(
fp
[
idx
]
+
tp
[
idx
])
#print(prec)
ap
,
mrec
,
mprec
=
voc_ap
(
rec
[:],
prec
[:])
F1
=
np
.
array
(
rec
)
*
np
.
array
(
prec
)
/
(
np
.
array
(
prec
)
+
np
.
array
(
rec
))
*
2
sum_AP
+=
ap
text
=
"{0:.2f}%"
.
format
(
ap
*
100
)
+
" = "
+
class_name
+
" AP "
#class_name + " AP = {0:.2f}%".format(ap*100)
if
len
(
prec
)
>
0
:
F1_text
=
"{0:.2f}"
.
format
(
F1
[
score05_idx
])
+
" = "
+
class_name
+
" F1 "
Recall_text
=
"{0:.2f}%"
.
format
(
rec
[
score05_idx
]
*
100
)
+
" = "
+
class_name
+
" Recall "
Precision_text
=
"{0:.2f}%"
.
format
(
prec
[
score05_idx
]
*
100
)
+
" = "
+
class_name
+
" Precision "
else
:
F1_text
=
"0.00"
+
" = "
+
class_name
+
" F1 "
Recall_text
=
"0.00%"
+
" = "
+
class_name
+
" Recall "
Precision_text
=
"0.00%"
+
" = "
+
class_name
+
" Precision "
"""
Write to results.txt
"""
...
...
@@ -682,7 +702,8 @@ with open(results_files_path + "/results.txt", 'w') as results_file:
rounded_rec
=
[
'%.2f'
%
elem
for
elem
in
rec
]
results_file
.
write
(
text
+
"
\n
Precision: "
+
str
(
rounded_prec
)
+
"
\n
Recall :"
+
str
(
rounded_rec
)
+
"
\n\n
"
)
if
not
args
.
quiet
:
print
(
text
)
print
(
text
+
"
\t
||
\t
score_threhold=0.5 : "
+
"F1="
+
"{0:.2f}"
.
format
(
F1
[
score05_idx
])
\
+
" ; Recall="
+
"{0:.2f}%"
.
format
(
rec
[
score05_idx
]
*
100
)
+
" ; Precision="
+
"{0:.2f}%"
.
format
(
prec
[
score05_idx
]
*
100
))
ap_dictionary
[
class_name
]
=
ap
n_images
=
counter_images_per_class
[
class_name
]
...
...
@@ -713,11 +734,42 @@ with open(results_files_path + "/results.txt", 'w') as results_file:
axes
.
set_xlim
([
0.0
,
1.0
])
axes
.
set_ylim
([
0.0
,
1.05
])
# .05 to give some extra space
# Alternative option -> wait for button to be pressed
#while not plt.waitforbuttonpress(): pass # wait for key display
#
while not plt.waitforbuttonpress(): pass # wait for key display
# Alternative option -> normal display
#plt.show()
# plt.show()
# save the plot
fig
.
savefig
(
results_files_path
+
"/classes/"
+
class_name
+
".png"
)
fig
.
savefig
(
results_files_path
+
"/AP/"
+
class_name
+
".png"
)
plt
.
cla
()
# clear axes for next plot
plt
.
plot
(
score
,
F1
,
"-"
,
color
=
'orangered'
)
plt
.
title
(
'class: '
+
F1_text
+
"
\n
score_threhold=0.5"
)
plt
.
xlabel
(
'Score_Threhold'
)
plt
.
ylabel
(
'F1'
)
axes
=
plt
.
gca
()
# gca - get current axes
axes
.
set_xlim
([
0.0
,
1.0
])
axes
.
set_ylim
([
0.0
,
1.05
])
# .05 to give some extra space
fig
.
savefig
(
results_files_path
+
"/F1/"
+
class_name
+
".png"
)
plt
.
cla
()
# clear axes for next plot
plt
.
plot
(
score
,
rec
,
"-H"
,
color
=
'gold'
)
plt
.
title
(
'class: '
+
Recall_text
+
"
\n
score_threhold=0.5"
)
plt
.
xlabel
(
'Score_Threhold'
)
plt
.
ylabel
(
'Recall'
)
axes
=
plt
.
gca
()
# gca - get current axes
axes
.
set_xlim
([
0.0
,
1.0
])
axes
.
set_ylim
([
0.0
,
1.05
])
# .05 to give some extra space
fig
.
savefig
(
results_files_path
+
"/Recall/"
+
class_name
+
".png"
)
plt
.
cla
()
# clear axes for next plot
plt
.
plot
(
score
,
prec
,
"-s"
,
color
=
'palevioletred'
)
plt
.
title
(
'class: '
+
Precision_text
+
"
\n
score_threhold=0.5"
)
plt
.
xlabel
(
'Score_Threhold'
)
plt
.
ylabel
(
'Precision'
)
axes
=
plt
.
gca
()
# gca - get current axes
axes
.
set_xlim
([
0.0
,
1.0
])
axes
.
set_ylim
([
0.0
,
1.05
])
# .05 to give some extra space
fig
.
savefig
(
results_files_path
+
"/Precision/"
+
class_name
+
".png"
)
plt
.
cla
()
# clear axes for next plot
if
show_animation
:
...
...
voc_annotation.py
浏览文件 @
bca67afa
...
...
@@ -3,16 +3,18 @@ from os import getcwd
sets
=
[(
'2007'
,
'train'
),
(
'2007'
,
'val'
),
(
'2007'
,
'test'
)]
wd
=
getcwd
()
classes
=
[
"aeroplane"
,
"bicycle"
,
"bird"
,
"boat"
,
"bottle"
,
"bus"
,
"car"
,
"cat"
,
"chair"
,
"cow"
,
"diningtable"
,
"dog"
,
"horse"
,
"motorbike"
,
"person"
,
"pottedplant"
,
"sheep"
,
"sofa"
,
"train"
,
"tvmonitor"
]
def
convert_annotation
(
year
,
image_id
,
list_file
):
in_file
=
open
(
'VOCdevkit/VOC%s/Annotations/%s.xml'
%
(
year
,
image_id
))
tree
=
ET
.
parse
(
in_file
)
root
=
tree
.
getroot
()
list_file
.
write
(
'%s/VOCdevkit/VOC%s/JPEGImages/%s.jpg'
%
(
wd
,
year
,
image_id
))
for
obj
in
root
.
iter
(
'object'
):
difficult
=
obj
.
find
(
'difficult'
).
text
difficult
=
0
if
obj
.
find
(
'difficult'
)
!=
None
:
difficult
=
obj
.
find
(
'difficult'
).
text
cls
=
obj
.
find
(
'name'
).
text
if
cls
not
in
classes
or
int
(
difficult
)
==
1
:
continue
...
...
@@ -21,11 +23,13 @@ def convert_annotation(year, image_id, list_file):
b
=
(
int
(
xmlbox
.
find
(
'xmin'
).
text
),
int
(
xmlbox
.
find
(
'ymin'
).
text
),
int
(
xmlbox
.
find
(
'xmax'
).
text
),
int
(
xmlbox
.
find
(
'ymax'
).
text
))
list_file
.
write
(
" "
+
","
.
join
([
str
(
a
)
for
a
in
b
])
+
','
+
str
(
cls_id
))
list_file
.
write
(
'
\n
'
)
wd
=
getcwd
(
)
for
year
,
image_set
in
sets
:
image_ids
=
open
(
'VOCdevkit/VOC%s/ImageSets/Main/%s.txt'
%
(
year
,
image_set
)).
read
().
strip
().
split
()
list_file
=
open
(
'%s_%s.txt'
%
(
year
,
image_set
),
'w'
)
for
image_id
in
image_ids
:
list_file
.
write
(
'%s/VOCdevkit/VOC%s/JPEGImages/%s.jpg'
%
(
wd
,
year
,
image_id
))
convert_annotation
(
year
,
image_id
,
list_file
)
list_file
.
write
(
'
\n
'
)
list_file
.
close
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录