Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yolov5
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Administrator
yolov5
Commits
a03adb5a
提交
a03adb5a
authored
7月 02, 2020
作者:
Glenn Jocher
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'origin/master'
上级
1fca7a7f
5323ad22
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
15 行增加
和
15 行删除
+15
-15
detect.py
detect.py
+3
-3
export.py
models/export.py
+12
-12
没有找到文件。
detect.py
浏览文件 @
a03adb5a
...
@@ -158,7 +158,7 @@ if __name__ == '__main__':
...
@@ -158,7 +158,7 @@ if __name__ == '__main__':
with
torch
.
no_grad
():
with
torch
.
no_grad
():
detect
()
detect
()
# Update all models
#
#
Update all models
# for opt.weights in ['yolov5s.pt', 'yolov5m.pt', 'yolov5l.pt', 'yolov5x.pt', 'yolov3-spp.pt']:
# for opt.weights in ['yolov5s.pt', 'yolov5m.pt', 'yolov5l.pt', 'yolov5x.pt', 'yolov3-spp.pt']:
# detect()
#
detect()
# create_pretrained(opt.weights, opt.weights)
#
create_pretrained(opt.weights, opt.weights)
models/export.py
浏览文件 @
a03adb5a
"""Exports a YOLOv5 *.pt model to
*.onnx and *.torchs
cript formats
"""Exports a YOLOv5 *.pt model to
ONNX and TorchS
cript formats
Usage:
Usage:
$ export PYTHONPATH="$PWD" && python models/export.py --weights ./weights/yolov5s.pt --img 640 --batch 1
$ export PYTHONPATH="$PWD" && python models/export.py --weights ./weights/yolov5s.pt --img 640 --batch 1
...
@@ -6,8 +6,6 @@ Usage:
...
@@ -6,8 +6,6 @@ Usage:
import
argparse
import
argparse
import
onnx
from
models.common
import
*
from
models.common
import
*
from
utils
import
google_utils
from
utils
import
google_utils
...
@@ -21,7 +19,7 @@ if __name__ == '__main__':
...
@@ -21,7 +19,7 @@ if __name__ == '__main__':
print
(
opt
)
print
(
opt
)
# Input
# Input
img
=
torch
.
zeros
((
opt
.
batch_size
,
3
,
*
opt
.
img_size
))
# image size
, (1, 3, 320,
192) iDetection
img
=
torch
.
zeros
((
opt
.
batch_size
,
3
,
*
opt
.
img_size
))
# image size
(1,3,320,
192) iDetection
# Load PyTorch model
# Load PyTorch model
google_utils
.
attempt_download
(
opt
.
weights
)
google_utils
.
attempt_download
(
opt
.
weights
)
...
@@ -30,20 +28,22 @@ if __name__ == '__main__':
...
@@ -30,20 +28,22 @@ if __name__ == '__main__':
model
.
model
[
-
1
]
.
export
=
True
# set Detect() layer export=True
model
.
model
[
-
1
]
.
export
=
True
# set Detect() layer export=True
_
=
model
(
img
)
# dry run
_
=
model
(
img
)
# dry run
#
Export to torchscrip
t
#
TorchScript expor
t
try
:
try
:
f
=
opt
.
weights
.
replace
(
'.pt'
,
'.torchscript'
)
# filename
f
=
opt
.
weights
.
replace
(
'.pt'
,
'.torchscript'
)
# filename
ts
=
torch
.
jit
.
trace
(
model
,
img
)
ts
=
torch
.
jit
.
trace
(
model
,
img
)
ts
.
save
(
f
)
ts
.
save
(
f
)
print
(
'Torch
s
cript export success, saved as
%
s'
%
f
)
print
(
'Torch
S
cript export success, saved as
%
s'
%
f
)
except
:
except
Exception
as
e
:
print
(
'Torch
script export failed.'
)
print
(
'Torch
Script export failed:
%
s'
%
e
)
#
Export to ONNX
#
ONNX export
try
:
try
:
import
onnx
f
=
opt
.
weights
.
replace
(
'.pt'
,
'.onnx'
)
# filename
f
=
opt
.
weights
.
replace
(
'.pt'
,
'.onnx'
)
# filename
model
.
fuse
()
# only for ONNX
model
.
fuse
()
# only for ONNX
torch
.
onnx
.
export
(
model
,
img
,
f
,
verbose
=
False
,
opset_version
=
1
1
,
input_names
=
[
'images'
],
torch
.
onnx
.
export
(
model
,
img
,
f
,
verbose
=
False
,
opset_version
=
1
2
,
input_names
=
[
'images'
],
output_names
=
[
'output'
])
# output_names=['classes', 'boxes']
output_names
=
[
'output'
])
# output_names=['classes', 'boxes']
# Checks
# Checks
...
@@ -51,5 +51,5 @@ if __name__ == '__main__':
...
@@ -51,5 +51,5 @@ if __name__ == '__main__':
onnx
.
checker
.
check_model
(
onnx_model
)
# check onnx model
onnx
.
checker
.
check_model
(
onnx_model
)
# check onnx model
print
(
onnx
.
helper
.
printable_graph
(
onnx_model
.
graph
))
# print a human readable representation of the graph
print
(
onnx
.
helper
.
printable_graph
(
onnx_model
.
graph
))
# print a human readable representation of the graph
print
(
'ONNX export success, saved as
%
s
\n
View with https://github.com/lutzroeder/netron'
%
f
)
print
(
'ONNX export success, saved as
%
s
\n
View with https://github.com/lutzroeder/netron'
%
f
)
except
:
except
Exception
as
e
:
print
(
'ONNX export failed
.'
)
print
(
'ONNX export failed
:
%
s'
%
e
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论