Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
tensorflow
提交
f0d6424d
T
tensorflow
项目概览
xxadev
/
tensorflow
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
tensorflow
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
f0d6424d
编写于
7月 17, 2019
作者:
J
Jian Li
提交者:
TensorFlower Gardener
7月 17, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add int16 support to Quant.
PiperOrigin-RevId: 258563058
上级
4fd66235
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
26 addition
and
6 deletion
+26
-6
tensorflow/lite/kernels/quantize.cc
tensorflow/lite/kernels/quantize.cc
+10
-3
tensorflow/lite/kernels/quantize_test.cc
tensorflow/lite/kernels/quantize_test.cc
+11
-0
tensorflow/lite/kernels/register.cc
tensorflow/lite/kernels/register.cc
+3
-1
tensorflow/lite/tools/optimize/operator_property.cc
tensorflow/lite/tools/optimize/operator_property.cc
+1
-1
tensorflow/lite/tools/optimize/quantize_model_test.cc
tensorflow/lite/tools/optimize/quantize_model_test.cc
+1
-1
未找到文件。
tensorflow/lite/kernels/quantize.cc
浏览文件 @
f0d6424d
...
...
@@ -55,7 +55,8 @@ TfLiteStatus Prepare(TfLiteContext* context, TfLiteNode* node) {
OpContext
op_context
(
context
,
node
);
TF_LITE_ENSURE
(
context
,
op_context
.
output
->
type
==
kTfLiteUInt8
||
op_context
.
output
->
type
==
kTfLiteInt8
);
op_context
.
output
->
type
==
kTfLiteInt8
||
op_context
.
output
->
type
==
kTfLiteInt16
);
// TODO(b/128934713): Add support for fixed-point per-channel quantization.
// Currently this only support affine per-layer quantization.
...
...
@@ -69,9 +70,11 @@ TfLiteStatus Prepare(TfLiteContext* context, TfLiteNode* node) {
// For requantize use case.
const
bool
is_requantize
=
(
op_context
.
input
->
type
==
kTfLiteUInt8
||
op_context
.
input
->
type
==
kTfLiteInt8
)
&&
op_context
.
input
->
type
==
kTfLiteInt8
||
op_context
.
input
->
type
==
kTfLiteInt16
)
&&
(
op_context
.
output
->
type
==
kTfLiteUInt8
||
op_context
.
output
->
type
==
kTfLiteInt8
);
op_context
.
output
->
type
==
kTfLiteInt8
||
op_context
.
output
->
type
==
kTfLiteInt16
);
if
(
is_requantize
)
{
const
double
effective_output_scale
=
static_cast
<
double
>
(
op_context
.
input
->
params
.
scale
)
/
...
...
@@ -104,6 +107,10 @@ TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) {
optimized_ops
::
AffineQuantize
(
op_params
,
GetTensorShape
(
input
),
GetTensorData
<
float
>
(
input
),
GetTensorShape
(
output
),
GetTensorData
<
uint8_t
>
(
output
));
}
else
if
(
output
->
type
==
kTfLiteInt16
)
{
optimized_ops
::
AffineQuantize
(
op_params
,
GetTensorShape
(
input
),
GetTensorData
<
float
>
(
input
),
GetTensorShape
(
output
),
GetTensorData
<
int16_t
>
(
output
));
}
else
{
context
->
ReportError
(
context
,
...
...
tensorflow/lite/kernels/quantize_test.cc
浏览文件 @
f0d6424d
...
...
@@ -79,6 +79,17 @@ TEST(QuantizeOpTest, INT8) {
{
-
128
,
-
127
,
-
126
,
-
125
,
-
124
,
123
,
124
,
125
,
126
,
127
}));
}
TEST
(
QuantizeOpTest
,
INT16
)
{
QuantizeOpModel
m
({
TensorType_FLOAT32
,
{
2
,
5
}},
{
TensorType_INT16
,
{
2
,
5
},
0
,
0
,
0.005
,
0
});
m
.
SetInput
({
-
63.5
,
-
63
,
-
3
,
-
2
,
-
1
,
1
,
2
,
3
,
63.5
,
64
});
m
.
Invoke
();
EXPECT_THAT
(
m
.
GetOutput
<
int16_t
>
(),
ElementsAreArray
({
-
12700
,
-
12600
,
-
600
,
-
400
,
-
200
,
200
,
400
,
600
,
12700
,
12800
}));
}
// Input scale 0.500000, output scale 0.500000, input zeropoint -1, output
// zeropoint -1
TEST
(
QuantizeOpTest
,
Int8Int8SameScale
)
{
...
...
tensorflow/lite/kernels/register.cc
浏览文件 @
f0d6424d
...
...
@@ -376,7 +376,9 @@ BuiltinOpResolver::BuiltinOpResolver() {
AddBuiltin
(
BuiltinOperator_ELU
,
Register_ELU
());
AddBuiltin
(
BuiltinOperator_REVERSE_SEQUENCE
,
Register_REVERSE_SEQUENCE
());
AddBuiltin
(
BuiltinOperator_MATRIX_DIAG
,
Register_MATRIX_DIAG
());
AddBuiltin
(
BuiltinOperator_QUANTIZE
,
Register_QUANTIZE
());
AddBuiltin
(
BuiltinOperator_QUANTIZE
,
Register_QUANTIZE
(),
/* min_version */
1
,
/* max_version */
2
);
AddBuiltin
(
BuiltinOperator_MATRIX_SET_DIAG
,
Register_MATRIX_SET_DIAG
());
// TODO(andrewharp, ahentz): Move these somewhere more appropriate so that
...
...
tensorflow/lite/tools/optimize/operator_property.cc
浏览文件 @
f0d6424d
...
...
@@ -169,7 +169,7 @@ OperatorProperty GetOperatorProperty(const BuiltinOperator& op) {
case
BuiltinOperator_QUANTIZE
:
property
.
inputs
=
{{
0
,
{}}};
property
.
outputs
=
{{
0
,
{}}};
property
.
version
=
1
;
property
.
version
=
2
;
break
;
case
BuiltinOperator_RESHAPE
:
property
.
inputs
=
{{
0
,
{}}};
...
...
tensorflow/lite/tools/optimize/quantize_model_test.cc
浏览文件 @
f0d6424d
...
...
@@ -370,7 +370,7 @@ TEST_F(QuantizeConcatModelTest, AddRequantBeforeConcat) {
BuiltinOperator_CONCATENATION
);
EXPECT_EQ
(
model_
.
operator_codes
[
0
]
->
version
,
2
);
EXPECT_EQ
(
model_
.
operator_codes
[
1
]
->
builtin_code
,
BuiltinOperator_QUANTIZE
);
EXPECT_EQ
(
model_
.
operator_codes
[
1
]
->
version
,
1
);
EXPECT_EQ
(
model_
.
operator_codes
[
1
]
->
version
,
2
);
}
class
QuantizeConvModel1Test
:
public
QuantizeModelTest
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录