Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Xiaomi
Mace
提交
2f51ac3b
Mace
项目概览
Xiaomi
/
Mace
通知
107
Star
40
Fork
27
代码
文件
提交
分支
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看板
提交
2f51ac3b
编写于
10月 29, 2019
作者:
L
liutuo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix onnx converter datatype
上级
f9c99209
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
32 addition
and
22 deletion
+32
-22
tools/python/transform/onnx_converter.py
tools/python/transform/onnx_converter.py
+21
-11
tools/python/transform/shape_inference.py
tools/python/transform/shape_inference.py
+2
-2
tools/python/transform/transformer.py
tools/python/transform/transformer.py
+9
-9
未找到文件。
tools/python/transform/onnx_converter.py
浏览文件 @
2f51ac3b
...
...
@@ -191,9 +191,9 @@ OnnxOpType = Enum('OnnxOpType',
onnx_attr_translator
=
{
"axis"
:
lambda
x
:
int
(
x
),
"axes"
:
lambda
x
:
[
int
(
a
)
for
a
in
x
],
"dtype"
:
lambda
x
:
data_type
.
onnx2tf
(
x
),
"dtype"
:
lambda
x
:
onnx_dtype
(
x
),
"keepdims"
:
lambda
x
:
bool
(
x
),
"to"
:
lambda
x
:
data_type
.
onnx2tf
(
x
),
"to"
:
lambda
x
:
onnx_dtype
(
x
),
}
...
...
@@ -567,11 +567,7 @@ class OnnxConverter(base_converter.ConverterInterface):
tensor
.
data_type
=
mace_pb2
.
DT_FLOAT
tensor
.
float_data
.
extend
(
onnx_tensor
.
astype
(
np
.
float32
).
flat
)
elif
data_type
==
np
.
int32
:
tensor
.
data_type
=
mace_pb2
.
DT_INT32
tensor
.
int32_data
.
extend
(
onnx_tensor
.
astype
(
np
.
int32
).
flat
)
elif
data_type
==
np
.
int64
:
elif
data_type
==
np
.
int64
or
data_type
==
np
.
int32
:
tensor
.
data_type
=
mace_pb2
.
DT_INT32
tensor
.
int32_data
.
extend
(
onnx_tensor
.
astype
(
np
.
int32
).
flat
)
...
...
@@ -668,9 +664,9 @@ class OnnxConverter(base_converter.ConverterInterface):
if
'to'
in
node
.
attrs
:
dtype
=
node
.
attrs
[
'to'
]
if
dtype
==
TensorProto
.
FLOAT
:
if
dtype
==
np
.
float32
or
dtype
==
np
.
float64
:
op
.
output_type
.
extend
([
self
.
_option
.
data_type
])
elif
dtype
==
TensorProto
.
INT
:
elif
dtype
==
np
.
int64
or
dtype
==
np
.
int32
:
op
.
output_type
.
extend
([
mace_pb2
.
DT_INT32
])
else
:
mace_check
(
False
,
"data type %s not supported"
%
dtype
)
...
...
@@ -959,7 +955,14 @@ class OnnxConverter(base_converter.ConverterInterface):
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
]
if
const_tensor
.
data_type
==
mace_pb2
.
DT_INT32
:
value_arg
.
f
=
float
(
const_tensor
.
int32_data
[
0
])
elif
const_tensor
.
data_type
==
mace_pb2
.
DT_FLOAT
:
value_arg
.
f
=
const_tensor
.
float_data
[
0
]
else
:
mace_check
(
False
,
"Does not support param's data type %s"
%
const_tensor
.
data_type
)
value_index_arg
=
op
.
arg
.
add
()
value_index_arg
.
name
=
\
MaceKeyword
.
mace_scalar_input_index_str
...
...
@@ -972,7 +975,14 @@ class OnnxConverter(base_converter.ConverterInterface):
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
]
if
const_tensor
.
data_type
==
mace_pb2
.
DT_INT32
:
value_arg
.
f
=
float
(
const_tensor
.
int32_data
[
0
])
elif
const_tensor
.
data_type
==
mace_pb2
.
DT_FLOAT
:
value_arg
.
f
=
const_tensor
.
float_data
[
0
]
else
:
mace_check
(
False
,
"Does not support param's data type %s"
%
const_tensor
.
data_type
)
value_index_arg
=
op
.
arg
.
add
()
value_index_arg
.
name
=
\
MaceKeyword
.
mace_scalar_input_index_str
...
...
tools/python/transform/shape_inference.py
浏览文件 @
2f51ac3b
...
...
@@ -253,7 +253,7 @@ class ShapeInference(object):
aspect_ratio
=
ConverterUtil
.
get_arg
(
op
,
MaceKeyword
.
mace_aspect_ratio_str
).
floats
# noqa
num_prior
=
len
(
aspect_ratio
)
*
len
(
min_size
)
+
len
(
max_size
)
output_shape
[
2
]
=
num_prior
*
input_h
*
input_w
*
4
output_shape
[
2
]
=
int
(
num_prior
*
input_h
*
input_w
*
4
)
self
.
add_output_shape
(
op
,
[
output_shape
])
def
infer_shape_reshape
(
self
,
op
):
...
...
@@ -275,7 +275,7 @@ class ShapeInference(object):
output_shape
[
i
]
=
dim
[
i
]
product
*=
dim
[
i
]
if
idx
!=
-
1
:
output_shape
[
idx
]
=
in
put_size
/
product
output_shape
[
idx
]
=
in
t
(
input_size
/
product
)
self
.
add_output_shape
(
op
,
[
output_shape
])
else
:
output_shape
=
[]
...
...
tools/python/transform/transformer.py
浏览文件 @
2f51ac3b
...
...
@@ -1440,15 +1440,15 @@ class Transformer(base_converter.ConverterInterface):
arg
.
i
=
1
elif
arg
.
i
==
3
:
arg
.
i
=
2
producer
=
self
.
_producer
[
op
.
input
[
0
]]
input_shape
=
producer
.
output_shape
[
0
].
dims
if
producer
.
type
==
MaceOp
.
FullyConnected
.
name
and
\
len
(
input_shape
)
==
2
:
axis_arg
=
ConverterUtil
.
get_arg
(
op
,
MaceKeyword
.
mace_axis_str
)
if
axis_arg
.
i
==
1
:
axis_arg
.
i
=
3
if
op
.
input
[
0
]
in
self
.
_producer
:
producer
=
self
.
_producer
[
op
.
input
[
0
]]
input_shape
=
producer
.
output_shape
[
0
].
dims
if
(
producer
.
type
==
MaceOp
.
FullyConnected
.
name
and
len
(
input_shape
)
==
2
)
:
axis_arg
=
ConverterUtil
.
get_arg
(
op
,
MaceKeyword
.
mace_axis_str
)
if
axis_arg
.
i
==
1
:
axis_arg
.
i
=
3
elif
op
.
type
==
MaceOp
.
Squeeze
.
name
:
for
arg
in
op
.
arg
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录