Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
146ed409
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
146ed409
编写于
2月 13, 2020
作者:
J
joanna.wozna.intel
提交者:
GitHub
2月 13, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add test with reused requantize op (#22482)
test=develop
上级
96770f51
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
57 addition
and
10 deletion
+57
-10
python/paddle/fluid/tests/unittests/mkldnn/test_requantize_mkldnn_op.py
...fluid/tests/unittests/mkldnn/test_requantize_mkldnn_op.py
+57
-10
未找到文件。
python/paddle/fluid/tests/unittests/mkldnn/test_requantize_mkldnn_op.py
浏览文件 @
146ed409
...
...
@@ -16,6 +16,8 @@ from __future__ import print_function
import
unittest
import
numpy
as
np
import
paddle.fluid
as
fluid
import
paddle.fluid.core
as
core
from
paddle.fluid.tests.unittests.op_test
import
OpTest
from
mkldnn_op_test
import
format_reorder
...
...
@@ -25,29 +27,31 @@ class TestReQuantizeOp(OpTest):
self
.
op_type
=
'requantize'
self
.
scale_in
=
2.0
self
.
scale_out
=
1.5
self
.
input_size
=
[
1
,
1
,
5
,
5
]
self
.
input_size
=
[
1
,
1
,
10
,
10
]
self
.
data_type
=
'int8'
self
.
set_scale
()
self
.
set_data_type
()
self
.
prepare_inputs
()
def
prepare_inputs
(
self
):
scale_shift
=
self
.
scale_out
/
self
.
scale_in
if
self
.
data_type
==
'int8'
:
input
=
(
np
.
random
.
randint
(
0
,
100
,
self
.
input_size
)
-
50
).
astype
(
self
.
data_type
)
output_tmp
=
np
.
round
(
input
.
astype
(
'float32'
)
*
self
.
input
=
(
np
.
random
.
randint
(
0
,
100
,
self
.
input_size
)
-
50
).
astype
(
self
.
data_type
)
output_tmp
=
np
.
round
(
self
.
input
.
astype
(
'float32'
)
*
scale_shift
).
astype
(
'int8'
)
else
:
input
=
(
np
.
random
.
randint
(
0
,
100
,
self
.
input_size
)).
astype
(
self
.
data_type
)
output_tmp
=
np
.
round
(
input
.
astype
(
'float32'
)
*
self
.
input
=
(
np
.
random
.
randint
(
0
,
100
,
self
.
input_size
)).
astype
(
self
.
data_type
)
output_tmp
=
np
.
round
(
self
.
input
.
astype
(
'float32'
)
*
scale_shift
).
astype
(
'uint8'
)
output
=
format_reorder
(
output_tmp
,
self
.
input_size
)
self
.
output
=
format_reorder
(
output_tmp
,
self
.
input_size
)
self
.
inputs
=
{
'Input'
:
OpTest
.
np_dtype_to_fluid_dtype
(
input
)}
self
.
inputs
=
{
'Input'
:
OpTest
.
np_dtype_to_fluid_dtype
(
self
.
input
)}
self
.
outputs
=
{
'Output'
:
output
}
self
.
outputs
=
{
'Output'
:
self
.
output
}
self
.
attrs
=
{
'Scale_in'
:
self
.
scale_in
,
'Scale_out'
:
self
.
scale_out
}
...
...
@@ -90,5 +94,48 @@ class TestReQuantizeOp4(TestReQuantizeOp2):
self
.
data_type
=
'uint8'
#-------------------test reused requantize op---------------------------
class
TestReQuantizeOpReused
(
TestReQuantizeOp
):
def
setUp
(
self
):
self
.
input_size
=
[
1
,
1
,
10
,
10
]
self
.
data_type
=
'int8'
self
.
set_scale
()
self
.
prepare_inputs
()
def
set_scale
(
self
):
self
.
scale_in
=
0.1
self
.
scale_out
=
0.2
def
test_check_output
(
self
):
variables
=
{
"input"
:
self
.
input
,
"output"
:
self
.
output
,
}
program
=
fluid
.
Program
()
with
fluid
.
program_guard
(
program
):
block
=
program
.
global_block
()
for
name
in
variables
:
block
.
create_var
(
name
=
name
,
dtype
=
"int8"
,
shape
=
variables
[
name
].
shape
)
requant_op
=
block
.
append_op
(
type
=
"requantize"
,
inputs
=
{
'Input'
:
block
.
var
(
'input'
),
},
outputs
=
{
"Output"
:
block
.
var
(
'output'
)},
attrs
=
{
'Scale_in'
:
self
.
scale_in
,
'Scale_out'
:
self
.
scale_out
})
place
=
core
.
CPUPlace
()
exe
=
fluid
.
Executor
(
place
)
for
i
in
range
(
2
):
out
=
exe
.
run
(
program
,
feed
=
{
'input'
:
variables
[
'input'
]},
fetch_list
=
[
'output'
])
self
.
assertTrue
(
np
.
allclose
(
variables
[
'output'
],
out
[
0
],
atol
=
1e-4
),
'output'
)
if
__name__
==
'__main__'
:
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录