Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
闹闹不闹!
Mace
提交
5b69b26b
Mace
项目概览
闹闹不闹!
/
Mace
与 Fork 源项目一致
Fork自
Xiaomi / Mace
通知
1
Star
1
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,发现更多精彩内容 >>
提交
5b69b26b
编写于
9月 26, 2018
作者:
B
Bin Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Convert quantized concat to the same range
上级
416a7885
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
46 addition
and
22 deletion
+46
-22
mace/kernels/concat.h
mace/kernels/concat.h
+5
-2
mace/kernels/resize_bilinear.h
mace/kernels/resize_bilinear.h
+2
-1
mace/python/tools/converter_tool/transformer.py
mace/python/tools/converter_tool/transformer.py
+39
-19
未找到文件。
mace/kernels/concat.h
浏览文件 @
5b69b26b
...
...
@@ -44,8 +44,8 @@ struct ConcatFunctor : ConcatFunctorBase {
:
ConcatFunctorBase
(
context
,
axis
)
{}
MaceStatus
operator
()(
const
std
::
vector
<
const
Tensor
*>
&
input_list
,
Tensor
*
output
,
StatsFuture
*
future
)
{
Tensor
*
output
,
StatsFuture
*
future
)
{
MACE_UNUSED
(
future
);
const
Tensor
*
input0
=
input_list
.
front
();
const
size_t
inputs_count
=
input_list
.
size
();
...
...
@@ -59,6 +59,9 @@ struct ConcatFunctor : ConcatFunctorBase {
outer_sizes
[
0
]
=
input0
->
size
()
/
inner_size
;
for
(
size_t
i
=
1
;
i
<
inputs_count
;
++
i
)
{
const
Tensor
*
input
=
input_list
[
i
];
MACE_CHECK
(
input
->
scale
()
==
output
->
scale
()
&&
input
->
zero_point
()
==
output
->
zero_point
(),
"Inputs and output must have the same scale and zero_point."
);
MACE_CHECK
(
input
->
dim_size
()
==
input0
->
dim_size
(),
"Ranks of all input tensors must be same."
);
for
(
int
j
=
0
;
j
<
input
->
dim_size
();
++
j
)
{
...
...
mace/kernels/resize_bilinear.h
浏览文件 @
5b69b26b
...
...
@@ -22,6 +22,7 @@
#include "mace/core/future.h"
#include "mace/core/tensor.h"
#include "mace/kernels/kernel.h"
#include "mace/utils/quantize.h"
#ifdef MACE_ENABLE_OPENCL
#include "mace/core/runtime/opencl/cl2_header.h"
...
...
@@ -90,7 +91,7 @@ inline uint8_t ComputeLerp<uint8_t>(const uint8_t top_left,
const
float
y_lerp
)
{
const
float
top
=
top_left
+
(
top_right
-
top_left
)
*
x_lerp
;
const
float
bottom
=
bottom_left
+
(
bottom_right
-
bottom_left
)
*
x_lerp
;
return
static_cast
<
uint8_t
>
(
roundf
(
top
+
(
bottom
-
top
)
*
y_lerp
));
return
Saturate
<
uint8_t
>
(
roundf
(
top
+
(
bottom
-
top
)
*
y_lerp
));
}
template
<
typename
T
>
...
...
mace/python/tools/converter_tool/transformer.py
浏览文件 @
5b69b26b
...
...
@@ -1674,10 +1674,12 @@ class Transformer(base_converter.ConverterInterface):
"""Assume biasadd has been already folded with convolution and fc"""
if
tensor
.
data_type
==
mace_pb2
.
DT_FLOAT
:
ops
=
self
.
_consumers
.
get
(
tensor
.
name
,
None
)
if
len
(
ops
)
==
1
and
ops
[
0
].
type
in
[
MaceOp
.
Conv2D
.
name
,
MaceOp
.
Deconv2D
.
name
,
MaceOp
.
DepthwiseConv2d
.
name
,
MaceOp
.
FullyConnected
.
name
]
\
if
ops
is
not
None
\
and
len
(
ops
)
==
1
\
and
ops
[
0
].
type
in
[
MaceOp
.
Conv2D
.
name
,
MaceOp
.
Deconv2D
.
name
,
MaceOp
.
DepthwiseConv2d
.
name
,
MaceOp
.
FullyConnected
.
name
]
\
and
len
(
ops
[
0
].
input
)
>=
3
\
and
ops
[
0
].
input
[
2
]
==
tensor
.
name
:
conv_op
=
ops
[
0
]
...
...
@@ -1723,6 +1725,13 @@ class Transformer(base_converter.ConverterInterface):
return
quantize_info
def
copy_quantize_info
(
self
,
op
,
info
):
quantize_info
=
op
.
quantize_info
.
add
()
quantize_info
.
minval
=
info
.
minval
quantize_info
.
maxval
=
info
.
maxval
quantize_info
.
scale
=
info
.
scale
quantize_info
.
zero_point
=
info
.
zero_point
def
transform_fake_quantize
(
self
):
if
not
self
.
_option
.
quantize
:
return
False
...
...
@@ -1833,19 +1842,34 @@ class Transformer(base_converter.ConverterInterface):
for
op
in
self
.
_model
.
op
:
if
op
.
type
in
[
MaceOp
.
Pooling
.
name
,
MaceOp
.
Squeeze
.
name
,
MaceOp
.
Concat
.
name
,
MaceOp
.
ResizeBilinear
.
name
,
MaceOp
.
BatchToSpaceND
.
name
,
MaceOp
.
SpaceToBatchND
.
name
]:
del
op
.
quantize_info
[:]
producer_op
=
self
.
_producer
[
op
.
input
[
0
]]
quantize_info
=
op
.
quantize_info
.
add
()
quantize_info
.
minval
=
producer_op
.
quantize_info
[
0
].
minval
quantize_info
.
maxval
=
producer_op
.
quantize_info
[
0
].
maxval
quantize_info
.
scale
=
producer_op
.
quantize_info
[
0
].
scale
quantize_info
.
zero_point
=
\
producer_op
.
quantize_info
[
0
].
zero_point
self
.
copy_quantize_info
(
op
,
producer_op
.
quantize_info
[
0
])
self
.
_quantize_activation_info
[
op
.
output
[
0
]]
=
\
op
.
quantize_info
[
0
]
elif
op
.
type
==
MaceOp
.
Concat
.
name
:
if
op
.
quantize_info
:
maxval
=
op
.
quantize_info
[
0
].
maxval
minval
=
op
.
quantize_info
[
0
].
minval
del
op
.
quantize_info
[:]
else
:
maxval
=
float
(
"-inf"
)
minval
=
float
(
"inf"
)
for
i
in
range
(
len
(
op
.
input
)):
minval
=
min
(
minval
,
self
.
_producer
[
op
.
input
[
i
]].
quantize_info
[
0
].
minval
)
# noqa
maxval
=
max
(
maxval
,
self
.
_producer
[
op
.
input
[
i
]].
quantize_info
[
0
].
maxval
)
# noqa
quantize_info
=
\
self
.
add_quantize_info
(
op
,
minval
,
maxval
)
self
.
_quantize_activation_info
[
op
.
output
[
0
]]
=
quantize_info
for
i
in
range
(
len
(
op
.
input
)):
producer_op
=
self
.
_producer
[
op
.
input
[
i
]]
del
producer_op
.
quantize_info
[:]
self
.
copy_quantize_info
(
producer_op
,
quantize_info
)
self
.
_quantize_activation_info
[
producer_op
.
output
[
0
]]
=
\
producer_op
.
quantize_info
[
0
]
elif
op
.
type
==
MaceOp
.
Softmax
.
name
:
del
op
.
quantize_info
[:]
quantize_info
=
\
...
...
@@ -1860,16 +1884,12 @@ class Transformer(base_converter.ConverterInterface):
del
op
.
quantize_info
[:]
producer_op0
=
self
.
_producer
[
op
.
input
[
0
]]
producer_op1
=
self
.
_producer
[
op
.
input
[
1
]]
quantize_info
=
op
.
quantize_info
.
add
()
quantize_info
.
minval
=
producer_op0
.
quantize_info
[
0
].
minval
\
minval
=
producer_op0
.
quantize_info
[
0
].
minval
\
+
producer_op1
.
quantize_info
[
0
].
minval
quantize_info
.
maxval
=
producer_op0
.
quantize_info
[
0
].
maxval
\
maxval
=
producer_op0
.
quantize_info
[
0
].
maxval
\
+
producer_op1
.
quantize_info
[
0
].
maxval
scale
,
zero
=
quantize_util
.
adjust_range
(
quantize_info
.
minval
,
quantize_info
.
maxval
,
non_zero
=
False
)
quantize_info
.
scale
=
scale
quantize_info
.
zero_point
=
zero
quantize_info
=
\
self
.
add_quantize_info
(
op
,
minval
,
maxval
)
self
.
_quantize_activation_info
[
op
.
output
[
0
]]
=
quantize_info
print
(
"Add default quantize info for input"
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录