Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
582c0a04
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
582c0a04
编写于
11月 25, 2020
作者:
J
joejiong
提交者:
GitHub
11月 25, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add uint8 for reshape op (#28996)
add uint8 for reshape operator
上级
f0e614fe
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
46 addition
and
8 deletion
+46
-8
paddle/fluid/operators/reshape_op.cc
paddle/fluid/operators/reshape_op.cc
+9
-2
python/paddle/fluid/tests/unittests/test_reshape_op.py
python/paddle/fluid/tests/unittests/test_reshape_op.py
+37
-6
未找到文件。
paddle/fluid/operators/reshape_op.cc
100644 → 100755
浏览文件 @
582c0a04
...
@@ -627,12 +627,14 @@ REGISTER_OP_CPU_KERNEL_FUNCTOR(reshape2, float, ops::ReshapeKernel, double,
...
@@ -627,12 +627,14 @@ REGISTER_OP_CPU_KERNEL_FUNCTOR(reshape2, float, ops::ReshapeKernel, double,
REGISTER_OP_CPU_KERNEL_FUNCTOR
(
reshape2_grad
,
float
,
ops
::
ReshapeGradKernel
,
REGISTER_OP_CPU_KERNEL_FUNCTOR
(
reshape2_grad
,
float
,
ops
::
ReshapeGradKernel
,
double
,
ops
::
ReshapeGradKernel
,
int
,
double
,
ops
::
ReshapeGradKernel
,
int
,
ops
::
ReshapeGradKernel
,
uint8_t
,
ops
::
ReshapeGradKernel
,
int64_t
,
ops
::
ReshapeGradKernel
,
int64_t
,
ops
::
ReshapeGradKernel
,
bool
,
ops
::
ReshapeGradKernel
,
bool
,
ops
::
ReshapeGradKernel
);
ops
::
ReshapeGradKernel
);
REGISTER_OP_CPU_KERNEL_FUNCTOR
(
reshape2_grad_grad
,
float
,
REGISTER_OP_CPU_KERNEL_FUNCTOR
(
reshape2_grad_grad
,
float
,
ops
::
ReshapeDoubleGradKernel
,
double
,
ops
::
ReshapeDoubleGradKernel
,
double
,
ops
::
ReshapeDoubleGradKernel
,
int
,
ops
::
ReshapeDoubleGradKernel
,
int
,
ops
::
ReshapeDoubleGradKernel
,
uint8_t
,
ops
::
ReshapeDoubleGradKernel
,
int64_t
,
ops
::
ReshapeDoubleGradKernel
,
int64_t
,
ops
::
ReshapeDoubleGradKernel
,
bool
,
ops
::
ReshapeDoubleGradKernel
,
bool
,
ops
::
ReshapeDoubleGradKernel
);
ops
::
ReshapeDoubleGradKernel
);
...
@@ -640,20 +642,24 @@ REGISTER_OP_CPU_KERNEL_FUNCTOR(reshape2_grad_grad, float,
...
@@ -640,20 +642,24 @@ REGISTER_OP_CPU_KERNEL_FUNCTOR(reshape2_grad_grad, float,
#ifdef PADDLE_WITH_CUDA
#ifdef PADDLE_WITH_CUDA
REGISTER_OP_CUDA_KERNEL_FUNCTOR
(
reshape
,
float
,
ops
::
ReshapeKernel
,
double
,
REGISTER_OP_CUDA_KERNEL_FUNCTOR
(
reshape
,
float
,
ops
::
ReshapeKernel
,
double
,
ops
::
ReshapeKernel
,
int
,
ops
::
ReshapeKernel
,
ops
::
ReshapeKernel
,
int
,
ops
::
ReshapeKernel
,
int64_t
,
ops
::
ReshapeKernel
,
plat
::
float16
,
uint8_t
,
ops
::
ReshapeKernel
,
int64_t
,
ops
::
ReshapeKernel
,
plat
::
float16
,
ops
::
ReshapeKernel
);
ops
::
ReshapeKernel
);
REGISTER_OP_CUDA_KERNEL_FUNCTOR
(
reshape_grad
,
float
,
ops
::
ReshapeGradKernel
,
REGISTER_OP_CUDA_KERNEL_FUNCTOR
(
reshape_grad
,
float
,
ops
::
ReshapeGradKernel
,
double
,
ops
::
ReshapeGradKernel
,
int
,
double
,
ops
::
ReshapeGradKernel
,
int
,
ops
::
ReshapeGradKernel
,
int64_t
,
ops
::
ReshapeGradKernel
,
int64_t
,
ops
::
ReshapeGradKernel
,
uint8_t
,
ops
::
ReshapeGradKernel
,
plat
::
float16
,
ops
::
ReshapeGradKernel
,
plat
::
float16
,
ops
::
ReshapeGradKernel
);
ops
::
ReshapeGradKernel
);
REGISTER_OP_CUDA_KERNEL_FUNCTOR
(
reshape2
,
float
,
ops
::
ReshapeKernel
,
double
,
REGISTER_OP_CUDA_KERNEL_FUNCTOR
(
reshape2
,
float
,
ops
::
ReshapeKernel
,
double
,
ops
::
ReshapeKernel
,
int
,
ops
::
ReshapeKernel
,
ops
::
ReshapeKernel
,
int
,
ops
::
ReshapeKernel
,
int64_t
,
ops
::
ReshapeKernel
,
plat
::
float16
,
uint8_t
,
ops
::
ReshapeKernel
,
int64_t
,
ops
::
ReshapeKernel
,
plat
::
float16
,
ops
::
ReshapeKernel
,
bool
,
ops
::
ReshapeKernel
);
ops
::
ReshapeKernel
,
bool
,
ops
::
ReshapeKernel
);
REGISTER_OP_CUDA_KERNEL_FUNCTOR
(
reshape2_grad
,
float
,
ops
::
ReshapeGradKernel
,
REGISTER_OP_CUDA_KERNEL_FUNCTOR
(
reshape2_grad
,
float
,
ops
::
ReshapeGradKernel
,
double
,
ops
::
ReshapeGradKernel
,
int
,
double
,
ops
::
ReshapeGradKernel
,
int
,
ops
::
ReshapeGradKernel
,
uint8_t
,
ops
::
ReshapeGradKernel
,
int64_t
,
ops
::
ReshapeGradKernel
,
int64_t
,
ops
::
ReshapeGradKernel
,
plat
::
float16
,
ops
::
ReshapeGradKernel
,
plat
::
float16
,
ops
::
ReshapeGradKernel
,
bool
,
ops
::
ReshapeGradKernel
,
bool
,
...
@@ -662,6 +668,7 @@ REGISTER_OP_CUDA_KERNEL_FUNCTOR(reshape2_grad, float, ops::ReshapeGradKernel,
...
@@ -662,6 +668,7 @@ REGISTER_OP_CUDA_KERNEL_FUNCTOR(reshape2_grad, float, ops::ReshapeGradKernel,
REGISTER_OP_CUDA_KERNEL_FUNCTOR
(
reshape2_grad_grad
,
float
,
REGISTER_OP_CUDA_KERNEL_FUNCTOR
(
reshape2_grad_grad
,
float
,
ops
::
ReshapeDoubleGradKernel
,
double
,
ops
::
ReshapeDoubleGradKernel
,
double
,
ops
::
ReshapeDoubleGradKernel
,
int
,
ops
::
ReshapeDoubleGradKernel
,
int
,
ops
::
ReshapeDoubleGradKernel
,
uint8_t
,
ops
::
ReshapeDoubleGradKernel
,
int64_t
,
ops
::
ReshapeDoubleGradKernel
,
int64_t
,
ops
::
ReshapeDoubleGradKernel
,
plat
::
float16
,
ops
::
ReshapeDoubleGradKernel
,
plat
::
float16
,
ops
::
ReshapeDoubleGradKernel
,
bool
,
ops
::
ReshapeDoubleGradKernel
,
bool
,
...
...
python/paddle/fluid/tests/unittests/test_reshape_op.py
100644 → 100755
浏览文件 @
582c0a04
...
@@ -20,7 +20,8 @@ import numpy as np
...
@@ -20,7 +20,8 @@ import numpy as np
from
op_test
import
OpTest
from
op_test
import
OpTest
import
paddle
import
paddle
import
paddle.fluid
as
fluid
import
paddle.fluid
as
fluid
from
paddle.fluid
import
compiler
,
Program
,
program_guard
from
paddle.fluid
import
compiler
from
paddle.static
import
Program
,
program_guard
# situation 1: have shape( list, no tensor), no actual shape(Tensor)
# situation 1: have shape( list, no tensor), no actual shape(Tensor)
...
@@ -248,16 +249,17 @@ class TestReshapeOpBool(TestReshapeOp):
...
@@ -248,16 +249,17 @@ class TestReshapeOpBool(TestReshapeOp):
class
TestReshapeAPI
(
unittest
.
TestCase
):
class
TestReshapeAPI
(
unittest
.
TestCase
):
def
_set_paddle_api
(
self
):
def
_set_paddle_api
(
self
):
self
.
fill_constant
=
paddle
.
fluid
.
layers
.
fill_constant
self
.
fill_constant
=
paddle
.
fluid
.
layers
.
fill_constant
self
.
data
=
paddle
.
fluid
.
data
self
.
data
=
paddle
.
static
.
data
self
.
reshape
=
paddle
.
reshape
self
.
reshape
=
paddle
.
reshape
self
.
to_tensor
=
paddle
.
to_tensor
self
.
to_tensor
=
paddle
.
to_tensor
def
_set_fluid_api
(
self
):
def
_set_fluid_api
(
self
):
self
.
fill_constant
=
fluid
.
layers
.
fill_constant
self
.
fill_constant
=
fluid
.
layers
.
fill_constant
self
.
data
=
fluid
.
data
self
.
data
=
paddle
.
static
.
data
self
.
reshape
=
fluid
.
layers
.
reshape
self
.
reshape
=
fluid
.
layers
.
reshape
def
_test_api
(
self
):
def
_test_api
(
self
):
paddle
.
enable_static
()
input
=
np
.
random
.
random
([
2
,
25
]).
astype
(
"float32"
)
input
=
np
.
random
.
random
([
2
,
25
]).
astype
(
"float32"
)
shape
=
[
2
,
5
,
5
]
shape
=
[
2
,
5
,
5
]
main_prog
=
Program
()
main_prog
=
Program
()
...
@@ -280,7 +282,7 @@ class TestReshapeAPI(unittest.TestCase):
...
@@ -280,7 +282,7 @@ class TestReshapeAPI(unittest.TestCase):
# Situation 4: have shape(Tensor), no actual shape(Tensor)
# Situation 4: have shape(Tensor), no actual shape(Tensor)
out_4
=
self
.
reshape
(
x
,
shape
=
actual_shape
)
out_4
=
self
.
reshape
(
x
,
shape
=
actual_shape
)
exe
=
fluid
.
Executor
(
place
=
fluid
.
CPUPlace
())
exe
=
paddle
.
static
.
Executor
(
place
=
paddle
.
CPUPlace
())
res_1
,
res_2
,
res_3
,
res_4
=
exe
.
run
(
res_1
,
res_2
,
res_3
,
res_4
=
exe
.
run
(
main_prog
,
main_prog
,
feed
=
{
"x"
:
input
,
feed
=
{
"x"
:
input
,
...
@@ -323,7 +325,7 @@ class TestReshapeAPI(unittest.TestCase):
...
@@ -323,7 +325,7 @@ class TestReshapeAPI(unittest.TestCase):
# Test Input Error
# Test Input Error
class
TestReshapeOpError
(
unittest
.
TestCase
):
class
TestReshapeOpError
(
unittest
.
TestCase
):
def
_set_paddle_api
(
self
):
def
_set_paddle_api
(
self
):
self
.
data
=
paddle
.
fluid
.
data
self
.
data
=
paddle
.
static
.
data
self
.
reshape
=
paddle
.
reshape
self
.
reshape
=
paddle
.
reshape
def
_set_fluid_api
(
self
):
def
_set_fluid_api
(
self
):
...
@@ -335,7 +337,7 @@ class TestReshapeOpError(unittest.TestCase):
...
@@ -335,7 +337,7 @@ class TestReshapeOpError(unittest.TestCase):
# The x type of reshape_op must be Variable.
# The x type of reshape_op must be Variable.
def
test_x_type
():
def
test_x_type
():
x1
=
fluid
.
create_lod_tensor
(
x1
=
fluid
.
create_lod_tensor
(
np
.
array
([[
-
1
]]),
[[
1
]],
fluid
.
CPUPlace
())
np
.
array
([[
-
1
]]),
[[
1
]],
paddle
.
CPUPlace
())
self
.
reshape
(
x1
,
shape
=
[
1
])
self
.
reshape
(
x1
,
shape
=
[
1
])
self
.
assertRaises
(
TypeError
,
test_x_type
)
self
.
assertRaises
(
TypeError
,
test_x_type
)
...
@@ -395,5 +397,34 @@ class TestReshapeOpError(unittest.TestCase):
...
@@ -395,5 +397,34 @@ class TestReshapeOpError(unittest.TestCase):
self
.
_test_errors
()
self
.
_test_errors
()
class
API_TestDygraphReshape
(
unittest
.
TestCase
):
def
test_out
(
self
):
paddle
.
disable_static
()
input_1
=
np
.
random
.
random
([
5
,
1
,
10
]).
astype
(
"int32"
)
input
=
paddle
.
to_tensor
(
input_1
)
output
=
paddle
.
reshape
(
x
=
input
,
shape
=
[
5
,
10
])
out_np
=
output
.
numpy
()
expected_out
=
np
.
reshape
(
input_1
,
newshape
=
[
5
,
10
])
self
.
assertTrue
(
np
.
allclose
(
expected_out
,
out_np
))
def
test_out_uint8
(
self
):
paddle
.
disable_static
()
input_1
=
np
.
random
.
random
([
5
,
1
,
10
]).
astype
(
"uint8"
)
input
=
paddle
.
to_tensor
(
input_1
)
output
=
paddle
.
reshape
(
x
=
input
,
shape
=
[
5
,
10
])
out_np
=
output
.
numpy
()
expected_out
=
np
.
reshape
(
input_1
,
newshape
=
[
5
,
10
])
self
.
assertTrue
(
np
.
allclose
(
expected_out
,
out_np
))
def
test_out_float32
(
self
):
paddle
.
disable_static
()
input_1
=
np
.
random
.
random
([
5
,
1
,
10
]).
astype
(
"float32"
)
input
=
paddle
.
to_tensor
(
input_1
)
output
=
paddle
.
reshape
(
x
=
input
,
shape
=
[
5
,
10
])
out_np
=
output
.
numpy
()
expected_out
=
np
.
reshape
(
input_1
,
newshape
=
[
5
,
10
])
self
.
assertTrue
(
np
.
allclose
(
expected_out
,
out_np
))
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
unittest
.
main
()
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录