Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
望夜。星。希冀
Mace
提交
19089a52
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,发现更多精彩内容 >>
提交
19089a52
编写于
7月 15, 2020
作者:
B
Bin Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix ONNX output shape bug
上级
9b37c124
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
35 addition
and
23 deletion
+35
-23
mace/core/memory_optimizer.cc
mace/core/memory_optimizer.cc
+6
-3
tools/python/transform/onnx_converter.py
tools/python/transform/onnx_converter.py
+3
-1
tools/python/transform/transformer.py
tools/python/transform/transformer.py
+26
-19
未找到文件。
mace/core/memory_optimizer.cc
浏览文件 @
19089a52
...
...
@@ -114,9 +114,12 @@ void MemoryOptimizer::Optimize(
const
mace
::
OperatorDef
*
op_def
,
const
std
::
unordered_map
<
std
::
string
,
MemoryType
>
*
mem_types
)
{
MACE_LATENCY_LOGGER
(
2
,
"Optimize memory"
);
MACE_CHECK
(
op_def
->
output_size
()
==
op_def
->
output_shape_size
(),
op_def
->
name
(),
"The number of output shapes is"
" not equal to the number of outputs"
);
if
(
op_def
->
output_size
()
!=
op_def
->
output_shape_size
())
{
VLOG
(
1
)
<<
op_def
->
name
()
<<
": the number of output shape "
<<
"is not equal to the number of output"
;
return
;
}
auto
device
=
static_cast
<
DeviceType
>
(
op_def
->
device_type
());
DataType
op_dtype
=
static_cast
<
DataType
>
(
ProtoArgHelper
::
GetOptionalArg
(
...
...
tools/python/transform/onnx_converter.py
浏览文件 @
19089a52
...
...
@@ -38,7 +38,7 @@ import numpy as np
import
onnx
import
onnx.utils
from
onnx
import
mapping
,
numpy_helper
,
TensorProto
from
onnx
import
mapping
,
numpy_helper
,
shape_inference
,
TensorProto
from
numbers
import
Number
IS_PYTHON3
=
sys
.
version_info
>
(
3
,)
...
...
@@ -420,6 +420,8 @@ class OnnxConverter(base_converter.ConverterInterface):
onnx
.
checker
.
check_model
(
onnx_model
)
onnx_model
=
shape_inference
.
infer_shapes
(
onnx_model
)
self
.
_isKaldi
=
False
polish_available
=
True
...
...
tools/python/transform/transformer.py
浏览文件 @
19089a52
...
...
@@ -358,7 +358,7 @@ class Transformer(base_converter.ConverterInterface):
self
.
safe_remove_node
(
op
,
self
.
_producer
.
get
(
op
.
input
[
0
],
None
))
return
True
elif
op
.
type
==
'Reshape'
and
\
elif
op
.
type
==
'Reshape'
and
len
(
op
.
output_shape
)
==
1
and
\
op
.
output_shape
[
0
].
dims
==
\
self
.
get_tensor_shape
(
op
.
input
[
0
]):
print
(
"Remove useless reshape: %s(%s)"
%
(
op
.
name
,
op
.
type
))
...
...
@@ -1417,28 +1417,35 @@ class Transformer(base_converter.ConverterInterface):
if
op
.
type
==
MaceOp
.
Reshape
:
input_op
=
self
.
_producer
[
op
.
input
[
0
]]
input_dims
=
input_op
.
output_shape
[
0
].
dims
output_dims
=
op
.
output_shape
[
0
].
dims
if
len
(
input_op
.
output_shape
)
!=
1
or
\
len
(
input_dims
)
!=
4
or
len
(
output_dims
)
!=
4
:
if
len
(
input_op
.
output_shape
)
==
0
or
len
(
op
.
output_shape
)
==
0
:
transposable
=
False
else
:
in_b
,
in_h
,
in_w
,
in_c
=
self
.
sort_feature_map_shape
(
input_dims
,
ConverterUtil
.
data_format
(
input_op
))
ou_b
,
ou_h
,
ou_w
,
ou_c
=
self
.
sort_feature_map_shape
(
output_dims
,
ConverterUtil
.
data_format
(
op
))
transposable
=
(
in_b
==
ou_b
and
in_c
==
ou_c
)
input_dims
=
input_op
.
output_shape
[
0
].
dims
output_dims
=
op
.
output_shape
[
0
].
dims
if
len
(
input_op
.
output_shape
)
!=
1
or
\
len
(
input_dims
)
!=
4
or
len
(
output_dims
)
!=
4
:
transposable
=
False
else
:
in_b
,
in_h
,
in_w
,
in_c
=
self
.
sort_feature_map_shape
(
input_dims
,
ConverterUtil
.
data_format
(
input_op
))
ou_b
,
ou_h
,
ou_w
,
ou_c
=
self
.
sort_feature_map_shape
(
output_dims
,
ConverterUtil
.
data_format
(
op
))
transposable
=
(
in_b
==
ou_b
and
in_c
==
ou_c
)
elif
op
.
type
==
MaceOp
.
Squeeze
:
input_dims
=
self
.
_producer
[
op
.
input
[
0
]].
output_shape
[
0
].
dims
output_dims
=
op
.
output_shape
[
0
].
dims
src_df
=
ConverterUtil
.
data_format
(
self
.
_model
)
arg
=
ConverterUtil
.
get_arg
(
op
,
MaceKeyword
.
mace_axis_str
)
if
len
(
input_dims
)
==
4
and
len
(
output_dims
)
==
2
and
\
((
src_df
==
DataFormat
.
NCHW
and
arg
.
ints
==
[
2
,
3
])
or
(
src_df
==
DataFormat
.
NHWC
and
arg
.
ints
==
[
1
,
2
])):
transposable
=
True
else
:
input_op
=
self
.
_producer
[
op
.
input
[
0
]]
if
len
(
input_op
.
output_shape
)
==
0
or
len
(
op
.
output_shape
)
==
0
:
transposable
=
False
else
:
input_dims
=
input_op
.
output_shape
[
0
].
dims
output_dims
=
op
.
output_shape
[
0
].
dims
src_df
=
ConverterUtil
.
data_format
(
self
.
_model
)
arg
=
ConverterUtil
.
get_arg
(
op
,
MaceKeyword
.
mace_axis_str
)
if
len
(
input_dims
)
==
4
and
len
(
output_dims
)
==
2
and
\
((
src_df
==
DataFormat
.
NCHW
and
arg
.
ints
==
[
2
,
3
])
or
(
src_df
==
DataFormat
.
NHWC
and
arg
.
ints
==
[
1
,
2
])):
transposable
=
True
else
:
transposable
=
False
if
op
.
type
in
MaceTransposableDataFormatOps
and
not
transposable
:
print
(
"%s(%s) is not a transposable op in this model."
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录