Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
毕竟曾有刹那
Mace
提交
e9d3a319
Mace
项目概览
毕竟曾有刹那
/
Mace
与 Fork 源项目一致
Fork自
Xiaomi / Mace
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Mace
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e9d3a319
编写于
6月 24, 2019
作者:
L
liutuo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add onnx scalar elt
上级
ece5761c
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
32 addition
and
6 deletion
+32
-6
mace/python/tools/converter_tool/onnx_converter.py
mace/python/tools/converter_tool/onnx_converter.py
+27
-0
tools/onnx_optimizer.py
tools/onnx_optimizer.py
+5
-6
未找到文件。
mace/python/tools/converter_tool/onnx_converter.py
浏览文件 @
e9d3a319
...
@@ -941,6 +941,33 @@ class OnnxConverter(base_converter.ConverterInterface):
...
@@ -941,6 +941,33 @@ class OnnxConverter(base_converter.ConverterInterface):
coeff_arg
=
op
.
arg
.
add
()
coeff_arg
=
op
.
arg
.
add
()
coeff_arg
.
name
=
MaceKeyword
.
mace_coeff_str
coeff_arg
.
name
=
MaceKeyword
.
mace_coeff_str
coeff_arg
.
floats
.
extend
([
min_value
,
max_value
])
coeff_arg
.
floats
.
extend
([
min_value
,
max_value
])
elif
len
(
node
.
inputs
)
==
2
:
if
node
.
inputs
[
1
]
in
self
.
_consts
and
\
node
.
inputs
[
0
]
not
in
self
.
_consts
:
const_name
=
node
.
inputs
[
1
]
const_tensor
=
self
.
_consts
[
const_name
]
if
len
(
const_tensor
.
dims
)
==
0
:
value_arg
=
op
.
arg
.
add
()
value_arg
.
name
=
MaceKeyword
.
mace_scalar_input_str
value_arg
.
f
=
const_tensor
.
float_data
[
0
]
value_index_arg
=
op
.
arg
.
add
()
value_index_arg
.
name
=
\
MaceKeyword
.
mace_scalar_input_index_str
value_index_arg
.
i
=
1
del
op
.
input
[
1
]
elif
node
.
inputs
[
0
]
in
self
.
_consts
and
\
node
.
inputs
[
1
]
not
in
self
.
_consts
:
const_name
=
node
.
inputs
[
0
]
const_tensor
=
self
.
_consts
[
const_name
]
if
len
(
const_tensor
.
dims
)
==
0
:
value_arg
=
op
.
arg
.
add
()
value_arg
.
name
=
MaceKeyword
.
mace_scalar_input_str
value_arg
.
f
=
const_tensor
.
float_data
[
0
]
value_index_arg
=
op
.
arg
.
add
()
value_index_arg
.
name
=
\
MaceKeyword
.
mace_scalar_input_index_str
value_index_arg
.
i
=
0
del
op
.
input
[
0
]
@
staticmethod
@
staticmethod
def
copy_node_attr
(
op
,
node
,
attr_name
,
dtype
=
AttributeType
.
INT
,
def
copy_node_attr
(
op
,
node
,
attr_name
,
dtype
=
AttributeType
.
INT
,
...
...
tools/onnx_optimizer.py
浏览文件 @
e9d3a319
...
@@ -22,12 +22,12 @@ from onnx import optimizer
...
@@ -22,12 +22,12 @@ from onnx import optimizer
def
main
():
def
main
():
if
len
(
sys
.
argv
)
!=
3
:
if
len
(
sys
.
argv
)
!=
3
:
print
"Usage: python onnx_optimizer.py model.onnx model_opt.onnx"
print
(
"Usage: python onnx_optimizer.py model.onnx model_opt.onnx"
)
sys
.
exit
(
0
)
sys
.
exit
(
0
)
in_path
=
sys
.
argv
[
1
]
in_path
=
sys
.
argv
[
1
]
out_path
=
sys
.
argv
[
2
]
out_path
=
sys
.
argv
[
2
]
original_model
=
onnx
.
load
(
in_path
)
original_model
=
onnx
.
load
(
in_path
)
print
"Start optimize ONNX model for inference:"
print
(
"Start optimize ONNX model for inference:"
)
passes
=
[
'eliminate_identity'
,
passes
=
[
'eliminate_identity'
,
'fuse_consecutive_squeezes'
,
'fuse_consecutive_squeezes'
,
'fuse_consecutive_transposes'
,
'fuse_consecutive_transposes'
,
...
@@ -35,15 +35,14 @@ def main():
...
@@ -35,15 +35,14 @@ def main():
'eliminate_nop_transpose'
,
'eliminate_nop_transpose'
,
'eliminate_unused_initializer'
,
'eliminate_unused_initializer'
,
'extract_constant_to_initializer'
,
'extract_constant_to_initializer'
,
'fuse_add_bias_into_conv'
,
'fuse_bn_into_conv'
,
'fuse_bn_into_conv'
,
'fuse_transpose_into_gemm'
]
'fuse_transpose_into_gemm'
]
for
i
in
range
(
len
(
passes
)):
for
i
in
range
(
len
(
passes
)):
print
i
,
"."
,
passes
[
i
]
print
(
"%s.%s"
%
(
i
,
passes
[
i
]))
optimized_model
=
optimizer
.
optimize
(
original_model
,
passes
)
optimized_model
=
optimizer
.
optimize
(
original_model
,
passes
)
onnx
.
save_model
(
optimized_model
,
out_path
)
onnx
.
save_model
(
optimized_model
,
out_path
)
print
"Optimize Finished!"
print
(
"Optimize Finished!"
)
print
"Please check new model in:"
,
out_path
print
(
"Please check new model in:"
,
out_path
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录