Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
7c9ce097
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看板
未验证
提交
7c9ce097
编写于
2月 07, 2020
作者:
T
Tao Luo
提交者:
GitHub
2月 07, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refine reshape_op shape error message (#22480)
test=develop
上级
2b1386b2
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
42 addition
and
36 deletion
+42
-36
paddle/fluid/operators/reshape_op.cc
paddle/fluid/operators/reshape_op.cc
+42
-36
未找到文件。
paddle/fluid/operators/reshape_op.cc
浏览文件 @
7c9ce097
...
...
@@ -29,10 +29,11 @@ inline std::vector<int> get_new_shape(
auto
tensor
=
list_new_shape_tensor
[
i
];
PADDLE_ENFORCE_EQ
(
tensor
->
dims
(),
framework
::
make_ddim
({
1
}),
"ShapeError: If the element type of 'shape' in ReshapeOp is Tensor, "
"the element's shape must be [1]. But received the element's shape "
"is [%s]"
,
tensor
->
dims
());
platform
::
errors
::
InvalidArgument
(
"If the element type of 'shape' in ReshapeOp is Tensor, "
"the element's shape must be [1]. But received the element's shape "
"is [%s]"
,
tensor
->
dims
()));
if
(
platform
::
is_gpu_place
(
tensor
->
place
()))
{
framework
::
Tensor
temp
;
TensorCopySync
(
*
tensor
,
platform
::
CPUPlace
(),
&
temp
);
...
...
@@ -64,10 +65,11 @@ class ReshapeOp : public framework::OperatorWithKernel {
auto
ShapeTensor
=
ctx
->
Inputs
(
"ShapeTensor"
);
PADDLE_ENFORCE_GT
(
ShapeTensor
.
size
(),
0
,
"ShapeError: When `shape` in ReshapeOp is a list or tuple "
"which contains Tensor, the shape's size can't be zero. "
"But received shape's size is %d."
,
ShapeTensor
.
size
());
platform
::
errors
::
InvalidArgument
(
"When `shape` in ReshapeOp is a list or tuple "
"which contains Tensor, the shape's size can't be zero. "
"But received shape's size is %d."
,
ShapeTensor
.
size
()));
auto
infer_shape
=
ctx
->
Attrs
().
Get
<
std
::
vector
<
int
>>
(
"shape"
);
const
int64_t
copy_dim_val
=
0
;
auto
in_dims
=
ctx
->
GetInputDim
(
"X"
);
...
...
@@ -75,10 +77,11 @@ class ReshapeOp : public framework::OperatorWithKernel {
if
(
infer_shape
[
i
]
==
copy_dim_val
)
{
PADDLE_ENFORCE_LT
(
static_cast
<
int
>
(
i
),
in_dims
.
size
(),
"ShapeError: The index of 0 in `shape` must be less than "
"the input tensor X's dimensions. But received shape[%d] "
"= 0, X's dimensions = %d, X's shape = [%s]."
,
i
,
in_dims
.
size
(),
in_dims
);
platform
::
errors
::
InvalidArgument
(
"The index of 0 in `shape` must be less than "
"the input tensor X's dimensions. But received shape[%d] "
"= 0, X's dimensions = %d, X's shape = [%s]."
,
i
,
in_dims
.
size
(),
in_dims
));
infer_shape
[
i
]
=
in_dims
[
i
];
}
}
...
...
@@ -108,10 +111,10 @@ class ReshapeOp : public framework::OperatorWithKernel {
return
;
}
PADDLE_ENFORCE_EQ
(
!
shape
.
empty
(),
true
,
"ShapeError:
The parameter 'shape' in ReshapeOp must be set. "
"But received 'shape' is empty."
);
PADDLE_ENFORCE_EQ
(
!
shape
.
empty
(),
true
,
platform
::
errors
::
InvalidArgument
(
"
The parameter 'shape' in ReshapeOp must be set. "
"But received 'shape' is empty."
)
);
auto
x_dims
=
ctx
->
GetInputDim
(
"X"
);
auto
out_dims
=
ValidateShape
(
shape
,
x_dims
);
ctx
->
SetOutputDim
(
"Out"
,
out_dims
);
...
...
@@ -140,25 +143,28 @@ class ReshapeOp : public framework::OperatorWithKernel {
if
(
shape
[
i
]
==
unk_dim_val
)
{
PADDLE_ENFORCE_EQ
(
unk_dim_idx
,
-
1
,
"ShapeError: Only one dimension value of 'shape' in ReshapeOp can "
"be -1. But received shape = [%s], shape[%d] is also -1."
,
framework
::
make_ddim
(
shape
),
i
);
platform
::
errors
::
InvalidArgument
(
"Only one dimension value of 'shape' in ReshapeOp can "
"be -1. But received shape = [%s], shape[%d] is also -1."
,
framework
::
make_ddim
(
shape
),
i
));
unk_dim_idx
=
i
;
}
else
if
(
shape
[
i
]
==
copy_dim_val
)
{
PADDLE_ENFORCE_LT
(
static_cast
<
int
>
(
i
),
in_dims
.
size
(),
"ShapeError: The index of 0 in `shape` must be less than "
"the input tensor X's dimensions. "
"But received shape = [%s], shape[%d] = 0, X's shape = [%s], "
"X's dimensions = %d."
,
framework
::
make_ddim
(
shape
),
i
,
in_dims
,
in_dims
.
size
());
platform
::
errors
::
InvalidArgument
(
"The index of 0 in `shape` must be less than "
"the input tensor X's dimensions. "
"But received shape = [%s], shape[%d] = 0, X's shape = [%s], "
"X's dimensions = %d."
,
framework
::
make_ddim
(
shape
),
i
,
in_dims
,
in_dims
.
size
()));
}
else
{
PADDLE_ENFORCE_GT
(
shape
[
i
],
0
,
"ShapeError: Each dimension value of 'shape' in ReshapeOp must not "
"be negtive except one unknown dimension. "
"But received shape = [%s], shape[%d] = %d."
,
framework
::
make_ddim
(
shape
),
i
,
shape
[
i
]);
platform
::
errors
::
InvalidArgument
(
"Each dimension value of 'shape' in ReshapeOp must not "
"be negtive except one unknown dimension. "
"But received shape = [%s], shape[%d] = %d."
,
framework
::
make_ddim
(
shape
),
i
,
shape
[
i
]));
}
capacity
*=
(
shape
[
i
]
?
shape
[
i
]
:
in_dims
[
i
]);
...
...
@@ -180,8 +186,7 @@ class ReshapeOp : public framework::OperatorWithKernel {
"The input tensor X'size must be divisible by known "
"capacity of 'shape'. "
"But received X's shape = [%s], X's size = %d, "
"'shape' is [%s], known "
"capacity of 'shape' is %d."
,
"'shape' is [%s], known capacity of 'shape' is %d."
,
in_dims
,
in_size
,
framework
::
make_ddim
(
shape
),
capacity
));
}
else
{
output_shape
[
unk_dim_idx
]
=
-
1
;
...
...
@@ -190,12 +195,13 @@ class ReshapeOp : public framework::OperatorWithKernel {
if
(
all_positive
)
{
PADDLE_ENFORCE_EQ
(
capacity
,
in_size
,
"ShapeError: The 'shape' in ReshapeOp is invalid. "
"The input tensor X'size must be equal to the capacity of 'shape'. "
"But received X's shape = [%s], X's size = %d, 'shape' is [%s], "
"the "
"capacity of 'shape' is %d."
,
in_dims
,
in_size
,
framework
::
make_ddim
(
shape
),
capacity
);
platform
::
errors
::
InvalidArgument
(
"The 'shape' in ReshapeOp is invalid. "
"The input tensor X'size must be equal to the capacity of "
"'shape'. "
"But received X's shape = [%s], X's size = %d, 'shape' is "
"[%s], the capacity of 'shape' is %d."
,
in_dims
,
in_size
,
framework
::
make_ddim
(
shape
),
capacity
));
}
}
return
framework
::
make_ddim
(
output_shape
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录