Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yolov5
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Administrator
yolov5
Commits
698a5d7f
Unverified
提交
698a5d7f
authored
4月 08, 2022
作者:
Glenn Jocher
提交者:
GitHub
4月 08, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add `python benchmarks.py --test` for export-only (#7350)
* Test exports * Fix precommit
上级
446e6f56
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
41 行增加
和
3 行删除
+41
-3
benchmarks.py
utils/benchmarks.py
+41
-3
没有找到文件。
utils/benchmarks.py
浏览文件 @
698a5d7f
...
@@ -52,20 +52,26 @@ def run(
...
@@ -52,20 +52,26 @@ def run(
data
=
ROOT
/
'data/coco128.yaml'
,
# dataset.yaml path
data
=
ROOT
/
'data/coco128.yaml'
,
# dataset.yaml path
device
=
''
,
# cuda device, i.e. 0 or 0,1,2,3 or cpu
device
=
''
,
# cuda device, i.e. 0 or 0,1,2,3 or cpu
half
=
False
,
# use FP16 half-precision inference
half
=
False
,
# use FP16 half-precision inference
test
=
False
,
# test exports only
):
):
y
,
t
=
[],
time
.
time
()
y
,
t
=
[],
time
.
time
()
formats
=
export
.
export_formats
()
formats
=
export
.
export_formats
()
device
=
select_device
(
device
)
device
=
select_device
(
device
)
for
i
,
(
name
,
f
,
suffix
,
gpu
)
in
formats
.
iterrows
():
# index, (name, file, suffix, gpu-capable)
for
i
,
(
name
,
f
,
suffix
,
gpu
)
in
formats
.
iterrows
():
# index, (name, file, suffix, gpu-capable)
try
:
try
:
assert
i
<
9
,
'Edge TPU and TF.js not supported'
assert
i
!=
9
,
'Edge TPU not supported'
assert
i
!=
10
,
'TF.js not supported'
if
device
.
type
!=
'cpu'
:
if
device
.
type
!=
'cpu'
:
assert
gpu
,
f
'{name} inference not supported on GPU'
assert
gpu
,
f
'{name} inference not supported on GPU'
# Export
if
f
==
'-'
:
if
f
==
'-'
:
w
=
weights
# PyTorch format
w
=
weights
# PyTorch format
else
:
else
:
w
=
export
.
run
(
weights
=
weights
,
imgsz
=
[
imgsz
],
include
=
[
f
],
device
=
device
,
half
=
half
)[
-
1
]
# all others
w
=
export
.
run
(
weights
=
weights
,
imgsz
=
[
imgsz
],
include
=
[
f
],
device
=
device
,
half
=
half
)[
-
1
]
# all others
assert
suffix
in
str
(
w
),
'export failed'
assert
suffix
in
str
(
w
),
'export failed'
# Validate
result
=
val
.
run
(
data
,
w
,
batch_size
,
imgsz
,
plots
=
False
,
device
=
device
,
task
=
'benchmark'
,
half
=
half
)
result
=
val
.
run
(
data
,
w
,
batch_size
,
imgsz
,
plots
=
False
,
device
=
device
,
task
=
'benchmark'
,
half
=
half
)
metrics
=
result
[
0
]
# metrics (mp, mr, map50, map, *losses(box, obj, cls))
metrics
=
result
[
0
]
# metrics (mp, mr, map50, map, *losses(box, obj, cls))
speeds
=
result
[
2
]
# times (preprocess, inference, postprocess)
speeds
=
result
[
2
]
# times (preprocess, inference, postprocess)
...
@@ -78,8 +84,39 @@ def run(
...
@@ -78,8 +84,39 @@ def run(
LOGGER
.
info
(
'
\n
'
)
LOGGER
.
info
(
'
\n
'
)
parse_opt
()
parse_opt
()
notebook_init
()
# print system info
notebook_init
()
# print system info
py
=
pd
.
DataFrame
(
y
,
columns
=
[
'Format'
,
'mAP@0.5:0.95'
,
'Inference time (ms)'
])
py
=
pd
.
DataFrame
(
y
,
columns
=
[
'Format'
,
'mAP@0.5:0.95'
,
'Inference time (ms)'
]
if
map
else
[
'Format'
,
'Export'
,
''
]
)
LOGGER
.
info
(
f
'
\n
Benchmarks complete ({time.time() - t:.2f}s)'
)
LOGGER
.
info
(
f
'
\n
Benchmarks complete ({time.time() - t:.2f}s)'
)
LOGGER
.
info
(
str
(
py
if
map
else
py
.
iloc
[:,
:
2
]))
return
py
def
test
(
weights
=
ROOT
/
'yolov5s.pt'
,
# weights path
imgsz
=
640
,
# inference size (pixels)
batch_size
=
1
,
# batch size
data
=
ROOT
/
'data/coco128.yaml'
,
# dataset.yaml path
device
=
''
,
# cuda device, i.e. 0 or 0,1,2,3 or cpu
half
=
False
,
# use FP16 half-precision inference
test
=
False
,
# test exports only
):
y
,
t
=
[],
time
.
time
()
formats
=
export
.
export_formats
()
device
=
select_device
(
device
)
for
i
,
(
name
,
f
,
suffix
,
gpu
)
in
formats
.
iterrows
():
# index, (name, file, suffix, gpu-capable)
try
:
w
=
weights
if
f
==
'-'
else
\
export
.
run
(
weights
=
weights
,
imgsz
=
[
imgsz
],
include
=
[
f
],
device
=
device
,
half
=
half
)[
-
1
]
# weights
assert
suffix
in
str
(
w
),
'export failed'
y
.
append
([
name
,
True
])
except
Exception
:
y
.
append
([
name
,
False
])
# mAP, t_inference
# Print results
LOGGER
.
info
(
'
\n
'
)
parse_opt
()
notebook_init
()
# print system info
py
=
pd
.
DataFrame
(
y
,
columns
=
[
'Format'
,
'Export'
])
LOGGER
.
info
(
f
'
\n
Exports complete ({time.time() - t:.2f}s)'
)
LOGGER
.
info
(
str
(
py
))
LOGGER
.
info
(
str
(
py
))
return
py
return
py
...
@@ -92,13 +129,14 @@ def parse_opt():
...
@@ -92,13 +129,14 @@ def parse_opt():
parser
.
add_argument
(
'--data'
,
type
=
str
,
default
=
ROOT
/
'data/coco128.yaml'
,
help
=
'dataset.yaml path'
)
parser
.
add_argument
(
'--data'
,
type
=
str
,
default
=
ROOT
/
'data/coco128.yaml'
,
help
=
'dataset.yaml path'
)
parser
.
add_argument
(
'--device'
,
default
=
''
,
help
=
'cuda device, i.e. 0 or 0,1,2,3 or cpu'
)
parser
.
add_argument
(
'--device'
,
default
=
''
,
help
=
'cuda device, i.e. 0 or 0,1,2,3 or cpu'
)
parser
.
add_argument
(
'--half'
,
action
=
'store_true'
,
help
=
'use FP16 half-precision inference'
)
parser
.
add_argument
(
'--half'
,
action
=
'store_true'
,
help
=
'use FP16 half-precision inference'
)
parser
.
add_argument
(
'--test'
,
action
=
'store_true'
,
help
=
'test exports only'
)
opt
=
parser
.
parse_args
()
opt
=
parser
.
parse_args
()
print_args
(
vars
(
opt
))
print_args
(
vars
(
opt
))
return
opt
return
opt
def
main
(
opt
):
def
main
(
opt
):
run
(
**
vars
(
opt
))
test
(
**
vars
(
opt
))
if
opt
.
test
else
run
(
**
vars
(
opt
))
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论