Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Xiaomi
Mace
提交
b79f9f5a
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看板
提交
b79f9f5a
编写于
3月 09, 2020
作者:
B
Bin Li
提交者:
Bin Li
3月 10, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Support mixing quantization-aware training and post-quantization ranges
上级
611338a0
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
26 addition
and
16 deletion
+26
-16
docs/user_guide/quantization_usage.rst
docs/user_guide/quantization_usage.rst
+13
-3
tools/python/transform/transformer.py
tools/python/transform/transformer.py
+13
-13
未找到文件。
docs/user_guide/quantization_usage.rst
浏览文件 @
b79f9f5a
...
...
@@ -6,9 +6,9 @@ MACE supports two kinds of quantization mechanisms, i.e.,
*
**
Quantization
-
aware
training
(
Recommend
)**
After
pre
-
training
model
using
float
point
,
insert
simulated
quantization
operations
into
the
model
.
Fine
tune
the
new
model
.
Refer to `Tensorflow quantization-aware training <https://github.com/tensorflow/tensorflow/tree/
master
/tensorflow/contrib/quantize>`__.
Refer
to
`
Tensorflow
quantization
-
aware
training
<
https
://
github
.
com
/
tensorflow
/
tensorflow
/
tree
/
r1
.15
/
tensorflow
/
contrib
/
quantize
>`
__
.
* **Post
training quantization**
*
**
Post
-
training
quantization
**
After
pre
-
training
model
using
float
point
,
estimate
output
range
of
each
activation
layer
using
sample
inputs
.
...
...
@@ -28,7 +28,7 @@ models, e.g., MobileNet. The only thing you need to make it run using MACE is to
2. `quantize`: set `quantize` to be 1.
Post
training quantization
Post
-
training quantization
---------------------------
MACE supports post-training quantization if you want to take a chance to quantize model directly without fine tuning.
This method requires developer to calculate tensor range of each activation layer statistically using sample inputs.
...
...
@@ -84,6 +84,16 @@ MACE provides tools to do statistics with following steps(using `inception-v3` f
`quantize` to `1` and `quantize_range_file` to the overall_range file path in yaml config).
Mixing usage
---------------------------
As `quantization-aware training` is still evolving, there are some operations that are not supported,
which leaves some activation layers without tensor range. In this case, `post-training quantization`
can be used to calculate these missing ranges. To mix the usage, just get a `quantization-aware training`
model and then go through all the steps of `post-training quantization`. MACE will use the tensor ranges
from the `overall_range` file of `post-training quantization` if the ranges are missing from the
`quantization-aware training` model.
Supported devices
-----------------
MACE supports running quantized models on ARM CPU and other acceleration devices, e.g., Qualcomm Hexagon DSP, MediaTek APU.
...
...
tools/python/transform/transformer.py
浏览文件 @
b79f9f5a
...
...
@@ -1758,20 +1758,14 @@ class Transformer(base_converter.ConverterInterface):
quantize_info
.
zero_point
=
info
.
zero_point
def
transform_fake_quantize
(
self
):
if
not
self
.
_option
.
quantize
:
return
False
# Quantize info from fixpoint fine tune
print
(
"Transform fake quantize"
)
range_file
=
self
.
_option
.
quantize_range_file
if
range_file
:
return
net
=
self
.
_model
for
op
in
net
.
op
:
if
op
.
type
==
'FakeQuantWithMinMaxVars'
or
\
op
.
type
==
'FakeQuantWithMinMaxArgs'
:
if
op
.
input
[
0
]
not
in
self
.
_consts
:
if
self
.
_option
.
quantize
and
op
.
input
[
0
]
not
in
self
.
_consts
:
producer_op
=
self
.
_producer
[
op
.
input
[
0
]]
minval
=
ConverterUtil
.
get_arg
(
op
,
'min'
).
f
maxval
=
ConverterUtil
.
get_arg
(
op
,
'max'
).
f
...
...
@@ -1842,6 +1836,7 @@ class Transformer(base_converter.ConverterInterface):
range_file
=
self
.
_option
.
quantize_range_file
if
range_file
:
print
(
"Add quantize tensor range"
)
post_quantize_info
=
{}
with
open
(
range_file
)
as
f
:
for
line
in
f
:
tensor_name
,
minmax
=
line
.
split
(
"@@"
)[:
2
]
...
...
@@ -1856,17 +1851,21 @@ class Transformer(base_converter.ConverterInterface):
activation_info
.
maxval
=
max_val
activation_info
.
scale
=
scale
activation_info
.
zero_point
=
zero
self
.
_quantize_activation_info
[
tensor_name
]
=
activation_info
# noqa
if
tensor_name
not
in
self
.
_quantize_activation_info
:
post_quantize_info
[
tensor_name
]
=
activation_info
for
op
in
self
.
_model
.
op
:
if
op
.
name
.
find
(
MaceKeyword
.
mace_output_node_name
)
>=
0
:
continue
for
output
in
op
.
output
:
mace_check
(
output
in
self
.
_quantize_activation_info
,
"%s does not have quantize activation info"
%
op
)
op
.
quantize_info
.
extend
([
self
.
_quantize_activation_info
[
output
]])
# Prefer quantize info from quantization-aware training
if
output
not
in
self
.
_quantize_activation_info
:
mace_check
(
output
in
post_quantize_info
,
"%s does not have quantize activation info"
%
op
)
op
.
quantize_info
.
extend
([
post_quantize_info
[
output
]])
self
.
_quantize_activation_info
[
output
]
=
\
post_quantize_info
[
output
]
if
not
self
.
_option
.
quantize
:
return
False
...
...
@@ -1979,6 +1978,7 @@ class Transformer(base_converter.ConverterInterface):
maxval
=
producer_op0
.
quantize_info
[
0
].
maxval
\
-
producer_op1
.
quantize_info
[
0
].
minval
else
:
print
(
op
)
mace_check
(
False
,
"Quantized Elementwise only support:"
" SUM and SUB without ranges now."
)
quantize_info
=
\
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录