Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Xiaomi
Mace
提交
814f4324
Mace
项目概览
Xiaomi
/
Mace
通知
106
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
814f4324
编写于
3月 29, 2018
作者:
W
wuchenghui
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support QuantizedTanh
上级
1c6743fc
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
50 addition
and
0 deletion
+50
-0
mace/python/tools/dsp_ops.py
mace/python/tools/dsp_ops.py
+1
-0
mace/python/tools/tf_dsp_converter_lib.py
mace/python/tools/tf_dsp_converter_lib.py
+49
-0
未找到文件。
mace/python/tools/dsp_ops.py
浏览文件 @
814f4324
...
@@ -22,6 +22,7 @@ class DspOps(object):
...
@@ -22,6 +22,7 @@ class DspOps(object):
'QuantizedSpaceToBatchND'
:
'QuantizedSpaceToBatchND_8'
,
'QuantizedSpaceToBatchND'
:
'QuantizedSpaceToBatchND_8'
,
'QuantizedBatchToSpaceND'
:
'QuantizedBatchToSpaceND_8'
,
'QuantizedBatchToSpaceND'
:
'QuantizedBatchToSpaceND_8'
,
'QuantizedSoftmax'
:
'QuantizedSoftmax_8'
,
'QuantizedSoftmax'
:
'QuantizedSoftmax_8'
,
'QuantizedTanh'
:
'QuantizedTanh_8'
,
'Min'
:
'Min_f'
,
'Min'
:
'Min_f'
,
'Max'
:
'Max_f'
,
'Max'
:
'Max_f'
,
'QuantizeV2'
:
'Quantize'
,
'QuantizeV2'
:
'Quantize'
,
...
...
mace/python/tools/tf_dsp_converter_lib.py
浏览文件 @
814f4324
...
@@ -164,6 +164,55 @@ def convert_ops(unresolved_ops, resolved_ops, net_def, output_node, dsp_ops):
...
@@ -164,6 +164,55 @@ def convert_ops(unresolved_ops, resolved_ops, net_def, output_node, dsp_ops):
op_def
.
input
.
extend
([
input_tensor
.
name
,
min_tensor
.
name
,
max_tensor
.
name
])
op_def
.
input
.
extend
([
input_tensor
.
name
,
min_tensor
.
name
,
max_tensor
.
name
])
op_def
.
out_max_byte_size
.
extend
([
max_elem_size
(
out
)
for
out
in
quantize_reshape_op
.
outputs
])
op_def
.
out_max_byte_size
.
extend
([
max_elem_size
(
out
)
for
out
in
quantize_reshape_op
.
outputs
])
convert_op_outputs
(
op_def
,
quantize_reshape_op
)
convert_op_outputs
(
op_def
,
quantize_reshape_op
)
elif
len
(
first_op
.
outputs
)
>
0
and
first_op
.
type
==
'Dequantize'
\
and
len
(
first_op
.
outputs
[
0
].
consumers
())
>
0
\
and
first_op
.
outputs
[
0
].
consumers
()[
0
].
type
==
'Tanh'
:
input_tensor
=
first_op
.
inputs
[
0
]
min_tensor
=
first_op
.
inputs
[
1
]
max_tensor
=
first_op
.
inputs
[
2
]
tanh_op
=
first_op
.
outputs
[
0
].
consumers
()[
0
]
# if not last op
resolved_ops
.
add
(
tanh_op
.
name
)
if
tanh_op
.
outputs
[
0
].
consumers
():
reshape_op
=
tanh_op
.
outputs
[
0
].
consumers
()[
0
]
min_op
=
reshape_op
.
outputs
[
0
].
consumers
()[
0
]
max_op
=
reshape_op
.
outputs
[
0
].
consumers
()[
1
]
quantize_op
=
min_op
.
outputs
[
0
].
consumers
()[
0
]
resolved_ops
.
add
(
reshape_op
.
name
)
resolved_ops
.
add
(
min_op
.
name
)
resolved_ops
.
add
(
max_op
.
name
)
resolved_ops
.
add
(
quantize_op
.
name
)
op_def
.
name
=
quantize_op
.
name
op_def
.
type
=
dsp_ops
.
map_nn_op
(
'Quantized'
+
tanh_op
.
type
)
op_def
.
input
.
extend
([
input_tensor
.
name
,
min_tensor
.
name
,
max_tensor
.
name
])
op_def
.
out_max_byte_size
.
extend
([
max_elem_size
(
out
)
for
out
in
quantize_op
.
outputs
])
convert_op_outputs
(
op_def
,
quantize_op
)
# tanh is last op
else
:
op_def
.
name
=
tanh_op
.
name
+
'/QuantizedTanh'
op_def
.
type
=
dsp_ops
.
map_nn_op
(
'Quantized'
+
tanh_op
.
type
)
op_def
.
input
.
extend
([
input_tensor
.
name
,
min_tensor
.
name
,
max_tensor
.
name
])
op_def
.
out_max_byte_size
.
extend
([
max_elem_size
(
input_tensor
),
max_elem_size
(
min_tensor
),
max_elem_size
(
max_tensor
)])
op_def
.
output_type
.
extend
([
mace_pb2
.
DT_UINT8
,
mace_pb2
.
DT_FLOAT
,
mace_pb2
.
DT_FLOAT
])
output_shapes
=
[]
for
output
in
first_op
.
inputs
:
output_shape
=
mace_pb2
.
OutputShape
()
output_shape
.
dims
.
extend
(
output
.
shape
.
as_list
())
output_shapes
.
append
(
output_shape
)
op_def
.
output_shape
.
extend
(
output_shapes
)
new_tanh_op_def
=
net_def
.
op
.
add
()
new_tanh_op_def
.
name
=
tanh_op
.
name
new_tanh_op_def
.
type
=
dsp_ops
.
map_nn_op
(
'Dequantize'
)
new_tanh_op_def
.
input
.
extend
([
get_tensor_name_from_op
(
op_def
.
name
,
0
),
get_tensor_name_from_op
(
op_def
.
name
,
1
),
get_tensor_name_from_op
(
op_def
.
name
,
2
)])
new_tanh_op_def
.
out_max_byte_size
.
extend
([
max_elem_size
(
tanh_op
.
outputs
[
0
])])
convert_op_outputs
(
new_tanh_op_def
,
tanh_op
)
elif
has_padding_and_strides
(
first_op
):
elif
has_padding_and_strides
(
first_op
):
op_def
.
padding
=
padding_mode
[
first_op
.
get_attr
(
'padding'
)]
op_def
.
padding
=
padding_mode
[
first_op
.
get_attr
(
'padding'
)]
op_def
.
input
.
extend
([
t
.
name
for
t
in
first_op
.
inputs
])
op_def
.
input
.
extend
([
t
.
name
for
t
in
first_op
.
inputs
])
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录