Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yolov5
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Administrator
yolov5
Commits
5948f20a
Unverified
提交
5948f20a
authored
6月 09, 2021
作者:
Glenn Jocher
提交者:
GitHub
6月 09, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update test.py profiling (#3555)
* Update test.py profiling * half_precision to half * inplace
上级
8b5086c2
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
39 行增加
和
34 行删除
+39
-34
test.py
test.py
+17
-13
train.py
train.py
+13
-13
plots.py
utils/plots.py
+9
-8
没有找到文件。
test.py
浏览文件 @
5948f20a
...
...
@@ -38,7 +38,7 @@ def test(data,
plots
=
True
,
wandb_logger
=
None
,
compute_loss
=
None
,
half
_precision
=
True
,
half
=
True
,
opt
=
None
):
# Initialize/load model and set device
training
=
model
is
not
None
...
...
@@ -63,7 +63,7 @@ def test(data,
# model = nn.DataParallel(model)
# Half
half
=
device
.
type
!=
'cpu'
and
half_precision
# half precision only supported on CUDA
half
&=
device
.
type
!=
'cpu'
# half precision only supported on CUDA
if
half
:
model
.
half
()
...
...
@@ -95,20 +95,22 @@ def test(data,
names
=
{
k
:
v
for
k
,
v
in
enumerate
(
model
.
names
if
hasattr
(
model
,
'names'
)
else
model
.
module
.
names
)}
coco91class
=
coco80_to_coco91_class
()
s
=
(
'
%20
s'
+
'
%11
s'
*
6
)
%
(
'Class'
,
'Images'
,
'Labels'
,
'P'
,
'R'
,
'mAP@.5'
,
'mAP@.5:.95'
)
p
,
r
,
f1
,
mp
,
mr
,
map50
,
map
,
t0
,
t1
=
0.
,
0.
,
0.
,
0.
,
0.
,
0.
,
0.
,
0.
,
0.
p
,
r
,
f1
,
mp
,
mr
,
map50
,
map
,
t0
,
t1
,
t2
=
0.
,
0.
,
0.
,
0.
,
0.
,
0.
,
0.
,
0.
,
0.
,
0.
loss
=
torch
.
zeros
(
3
,
device
=
device
)
jdict
,
stats
,
ap
,
ap_class
,
wandb_images
=
[],
[],
[],
[],
[]
for
batch_i
,
(
img
,
targets
,
paths
,
shapes
)
in
enumerate
(
tqdm
(
dataloader
,
desc
=
s
)):
t_
=
time_synchronized
()
img
=
img
.
to
(
device
,
non_blocking
=
True
)
img
=
img
.
half
()
if
half
else
img
.
float
()
# uint8 to fp16/32
img
/=
255.0
# 0 - 255 to 0.0 - 1.0
targets
=
targets
.
to
(
device
)
nb
,
_
,
height
,
width
=
img
.
shape
# batch size, channels, height, width
t
=
time_synchronized
()
t0
+=
t
-
t_
# Run model
t
=
time_synchronized
()
out
,
train_out
=
model
(
img
,
augment
=
augment
)
# inference and training outputs
t
0
+=
time_synchronized
()
-
t
t
1
+=
time_synchronized
()
-
t
# Compute loss
if
compute_loss
:
...
...
@@ -119,7 +121,7 @@ def test(data,
lb
=
[
targets
[
targets
[:,
0
]
==
i
,
1
:]
for
i
in
range
(
nb
)]
if
save_hybrid
else
[]
# for autolabelling
t
=
time_synchronized
()
out
=
non_max_suppression
(
out
,
conf_thres
,
iou_thres
,
labels
=
lb
,
multi_label
=
True
,
agnostic
=
single_cls
)
t
1
+=
time_synchronized
()
-
t
t
2
+=
time_synchronized
()
-
t
# Statistics per image
for
si
,
pred
in
enumerate
(
out
):
...
...
@@ -236,9 +238,10 @@ def test(data,
print
(
pf
%
(
names
[
c
],
seen
,
nt
[
c
],
p
[
i
],
r
[
i
],
ap50
[
i
],
ap
[
i
]))
# Print speeds
t
=
tuple
(
x
/
seen
*
1E3
for
x
in
(
t0
,
t1
,
t
0
+
t1
))
+
(
imgsz
,
imgsz
,
batch_size
)
# tupl
e
t
=
tuple
(
x
/
seen
*
1E3
for
x
in
(
t0
,
t1
,
t
2
))
# speeds per imag
e
if
not
training
:
print
(
'Speed:
%.1
f/
%.1
f/
%.1
f ms inference/NMS/total per
%
gx
%
g image at batch-size
%
g'
%
t
)
shape
=
(
batch_size
,
3
,
imgsz
,
imgsz
)
print
(
f
'Speed:
%.1
fms pre-process,
%.1
fms inference,
%.1
fms NMS per image at shape {shape}'
%
t
)
# Plots
if
plots
:
...
...
@@ -327,24 +330,25 @@ if __name__ == '__main__':
save_txt
=
opt
.
save_txt
|
opt
.
save_hybrid
,
save_hybrid
=
opt
.
save_hybrid
,
save_conf
=
opt
.
save_conf
,
half
_precision
=
opt
.
half
,
half
=
opt
.
half
,
opt
=
opt
)
elif
opt
.
task
==
'speed'
:
# speed benchmarks
for
w
in
opt
.
weights
:
test
(
opt
.
data
,
w
,
opt
.
batch_size
,
opt
.
img_size
,
0.25
,
0.45
,
save_json
=
False
,
plots
=
False
,
opt
=
opt
)
for
w
in
opt
.
weights
if
isinstance
(
opt
.
weights
,
list
)
else
[
opt
.
weights
]:
test
(
opt
.
data
,
w
,
opt
.
batch_size
,
opt
.
img_size
,
0.25
,
0.45
,
save_json
=
False
,
plots
=
False
,
half
=
True
,
opt
=
opt
)
elif
opt
.
task
==
'study'
:
# run over a range of settings and save/plot
# python test.py --task study --data coco.yaml --iou 0.7 --weights yolov5s.pt yolov5m.pt yolov5l.pt yolov5x.pt
x
=
list
(
range
(
256
,
1536
+
128
,
128
))
# x axis (image sizes)
for
w
in
opt
.
weights
:
for
w
in
opt
.
weights
if
isinstance
(
opt
.
weights
,
list
)
else
[
opt
.
weights
]
:
f
=
f
'study_{Path(opt.data).stem}_{Path(w).stem}.txt'
# filename to save to
y
=
[]
# y axis
for
i
in
x
:
# img-size
print
(
f
'
\n
Running {f} point {i}...'
)
r
,
_
,
t
=
test
(
opt
.
data
,
w
,
opt
.
batch_size
,
i
,
opt
.
conf_thres
,
opt
.
iou_thres
,
opt
.
save_json
,
plots
=
False
,
opt
=
opt
)
plots
=
False
,
half
=
True
,
opt
=
opt
)
y
.
append
(
r
+
t
)
# results and times
np
.
savetxt
(
f
,
y
,
fmt
=
'
%10.4
g'
)
# save
os
.
system
(
'zip -r study.zip study_*.txt'
)
...
...
train.py
浏览文件 @
5948f20a
...
...
@@ -74,7 +74,7 @@ def train(hyp, opt, device, tb_writer=None):
loggers
[
'wandb'
]
=
wandb_logger
.
wandb
data_dict
=
wandb_logger
.
data_dict
if
wandb_logger
.
wandb
:
weights
,
epochs
,
hyp
=
opt
.
weights
,
opt
.
epochs
,
opt
.
hyp
#
WandbLogger might
update weights, epochs if resuming
weights
,
epochs
,
hyp
=
opt
.
weights
,
opt
.
epochs
,
opt
.
hyp
#
may
update weights, epochs if resuming
nc
=
1
if
single_cls
else
int
(
data_dict
[
'nc'
])
# number of classes
names
=
[
'item'
]
if
single_cls
and
len
(
data_dict
[
'names'
])
!=
1
else
data_dict
[
'names'
]
# class names
...
...
@@ -354,18 +354,18 @@ def train(hyp, opt, device, tb_writer=None):
final_epoch
=
epoch
+
1
==
epochs
if
not
opt
.
notest
or
final_epoch
:
# Calculate mAP
wandb_logger
.
current_epoch
=
epoch
+
1
results
,
maps
,
times
=
test
.
test
(
data_dict
,
batch_size
=
batch_size
*
2
,
imgsz
=
imgsz_test
,
model
=
ema
.
ema
,
single_cls
=
single_cls
,
dataloader
=
testloader
,
save_dir
=
save_dir
,
save_json
=
is_coco
and
final_epoch
,
verbose
=
nc
<
50
and
final_epoch
,
plots
=
plots
and
final_epoch
,
wandb_logger
=
wandb_logger
,
compute_loss
=
compute_loss
)
results
,
maps
,
_
=
test
.
test
(
data_dict
,
batch_size
=
batch_size
*
2
,
imgsz
=
imgsz_test
,
model
=
ema
.
ema
,
single_cls
=
single_cls
,
dataloader
=
testloader
,
save_dir
=
save_dir
,
save_json
=
is_coco
and
final_epoch
,
verbose
=
nc
<
50
and
final_epoch
,
plots
=
plots
and
final_epoch
,
wandb_logger
=
wandb_logger
,
compute_loss
=
compute_loss
)
# Write
with
open
(
results_file
,
'a'
)
as
f
:
...
...
utils/plots.py
浏览文件 @
5948f20a
...
...
@@ -3,7 +3,6 @@
import
glob
import
math
import
os
import
random
from
copy
import
copy
from
pathlib
import
Path
...
...
@@ -252,21 +251,23 @@ def plot_targets_txt(): # from utils.plots import *; plot_targets_txt()
def
plot_study_txt
(
path
=
''
,
x
=
None
):
# from utils.plots import *; plot_study_txt()
# Plot study.txt generated by test.py
fig
,
ax
=
plt
.
subplots
(
2
,
4
,
figsize
=
(
10
,
6
),
tight_layout
=
True
)
# ax = ax.ravel()
plot2
=
False
# plot additional results
if
plot2
:
ax
=
plt
.
subplots
(
2
,
4
,
figsize
=
(
10
,
6
),
tight_layout
=
True
)[
1
]
.
ravel
()
fig2
,
ax2
=
plt
.
subplots
(
1
,
1
,
figsize
=
(
8
,
4
),
tight_layout
=
True
)
# for f in [Path(path) / f'study_coco_{x}.txt' for x in ['yolov5s6', 'yolov5m6', 'yolov5l6', 'yolov5x6']]:
for
f
in
sorted
(
Path
(
path
)
.
glob
(
'study*.txt'
)):
y
=
np
.
loadtxt
(
f
,
dtype
=
np
.
float32
,
usecols
=
[
0
,
1
,
2
,
3
,
7
,
8
,
9
],
ndmin
=
2
)
.
T
x
=
np
.
arange
(
y
.
shape
[
1
])
if
x
is
None
else
np
.
array
(
x
)
s
=
[
'P'
,
'R'
,
'mAP@.5'
,
'mAP@.5:.95'
,
't_inference (ms/img)'
,
't_NMS (ms/img)'
,
't_total (ms/img)'
]
# for i in range(7):
# ax[i].plot(x, y[i], '.-', linewidth=2, markersize=8)
# ax[i].set_title(s[i])
if
plot2
:
s
=
[
'P'
,
'R'
,
'mAP@.5'
,
'mAP@.5:.95'
,
't_preprocess (ms/img)'
,
't_inference (ms/img)'
,
't_NMS (ms/img)'
]
for
i
in
range
(
7
):
ax
[
i
]
.
plot
(
x
,
y
[
i
],
'.-'
,
linewidth
=
2
,
markersize
=
8
)
ax
[
i
]
.
set_title
(
s
[
i
])
j
=
y
[
3
]
.
argmax
()
+
1
ax2
.
plot
(
y
[
6
,
1
:
j
],
y
[
3
,
1
:
j
]
*
1E2
,
'.-'
,
linewidth
=
2
,
markersize
=
8
,
ax2
.
plot
(
y
[
5
,
1
:
j
],
y
[
3
,
1
:
j
]
*
1E2
,
'.-'
,
linewidth
=
2
,
markersize
=
8
,
label
=
f
.
stem
.
replace
(
'study_coco_'
,
''
)
.
replace
(
'yolo'
,
'YOLO'
))
ax2
.
plot
(
1E3
/
np
.
array
([
209
,
140
,
97
,
58
,
35
,
18
]),
[
34.6
,
40.5
,
43.0
,
47.5
,
49.7
,
51.5
],
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论