Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
8b59ac3a
P
Paddle
项目概览
Crayon鑫
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
8b59ac3a
编写于
10月 28, 2019
作者:
C
Chen Weihang
提交者:
Tao Luo
10月 28, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
delete paddle infershape enforce marco (#20832)
上级
c8e49be2
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
58 addition
and
86 deletion
+58
-86
paddle/fluid/operators/linear_chain_crf_op.cc
paddle/fluid/operators/linear_chain_crf_op.cc
+20
-16
paddle/fluid/operators/metrics/accuracy_op.cc
paddle/fluid/operators/metrics/accuracy_op.cc
+14
-13
paddle/fluid/operators/metrics/auc_op.cc
paddle/fluid/operators/metrics/auc_op.cc
+9
-5
paddle/fluid/operators/smooth_l1_loss_op.cc
paddle/fluid/operators/smooth_l1_loss_op.cc
+7
-5
paddle/fluid/operators/squared_l2_distance_op.cc
paddle/fluid/operators/squared_l2_distance_op.cc
+8
-6
paddle/fluid/platform/enforce.h
paddle/fluid/platform/enforce.h
+0
-41
未找到文件。
paddle/fluid/operators/linear_chain_crf_op.cc
浏览文件 @
8b59ac3a
...
...
@@ -184,30 +184,34 @@ class LinearChainCRFOp : public framework::OperatorWithKernel {
true
,
"The Input(Label) should be a 3-D tensor with last "
"dimension fixed to 1 or a 2-D tensor in padding mode."
);
PADDLE_INFERSHAPE_ENFORCE_EQ
(
ctx
,
emission_dims
[
0
],
label_dims
[
0
],
"The batch size of Input(Emission) and Input(Label) "
"should be the same."
);
PADDLE_INFERSHAPE_ENFORCE_EQ
(
ctx
,
emission_dims
[
1
],
label_dims
[
1
],
"The max length of Input(Emission) and Input(Label) "
"should be the same."
);
if
(
ctx
->
IsRuntime
())
{
PADDLE_ENFORCE_EQ
(
emission_dims
[
0
],
label_dims
[
0
],
"The batch size of Input(Emission) and Input(Label) "
"should be the same."
);
PADDLE_ENFORCE_EQ
(
emission_dims
[
1
],
label_dims
[
1
],
"The max length of Input(Emission) and Input(Label) "
"should be the same."
);
}
}
else
{
PADDLE_ENFORCE_EQ
(
emission_dims
.
size
(),
2
,
"The Input(Emission) should be a 2-D tensor."
);
PADDLE_INFERSHAPE_ENFORCE_EQ
(
ctx
,
emission_dims
[
1
],
transition_dims
[
1
],
"The 2nd dimension of the Input(Emission) and the Input(Transition) "
"should be equal to the tag number."
);
if
(
ctx
->
IsRuntime
())
{
PADDLE_ENFORCE_EQ
(
emission_dims
[
1
],
transition_dims
[
1
],
"The 2nd dimension of the Input(Emission) and the "
"Input(Transition) "
"should be equal to the tag number."
);
}
auto
label_dims
=
ctx
->
GetInputDim
(
"Label"
);
PADDLE_ENFORCE_EQ
(
label_dims
.
size
(),
2
,
"The Input(Label) should be a 2-D tensor with the 2nd "
"dimensions fixed to 1."
);
PADDLE_INFERSHAPE_ENFORCE_EQ
(
ctx
,
emission_dims
[
0
],
label_dims
[
0
],
"The height of Input(Emission) and the height of Input(Label) "
"should be the same."
);
if
(
ctx
->
IsRuntime
())
{
PADDLE_ENFORCE_EQ
(
emission_dims
[
0
],
label_dims
[
0
],
"The height of Input(Emission) and the height of Input(Label) "
"should be the same."
);
}
}
ctx
->
SetOutputDim
(
"Alpha"
,
emission_dims
);
ctx
->
SetOutputDim
(
"EmissionExps"
,
emission_dims
);
...
...
paddle/fluid/operators/metrics/accuracy_op.cc
浏览文件 @
8b59ac3a
...
...
@@ -45,19 +45,20 @@ class AccuracyOp : public framework::OperatorWithKernel {
"ShapeError: label's dimensions of AccuracyOp must be 2. "
"But received label's dimensions = %d, label's shape = [%s]"
,
label_dim
.
size
(),
label_dim
);
PADDLE_INFERSHAPE_ENFORCE_EQ
(
ctx
,
label_dim
[
1
],
1
,
"ShapeError: label's second dimension of "
"AccuracyOp must be 1. But received label's "
"second dimension is = %d, label's shape = [%s]"
,
label_dim
[
1
],
label_dim
);
PADDLE_INFERSHAPE_ENFORCE_EQ
(
ctx
,
inference_dim
[
0
],
label_dim
[
0
],
"ShapeError: the output's num_rows of AccuracyOp must be"
" the same as label's num_rows. But received output's "
"shape = [%s], label's shape = [%s], output's num_rows = %d, label's "
"num_rows = %d"
,
inference_dim
,
label_dim
,
inference_dim
[
0
],
label_dim
[
0
]);
if
(
ctx
->
IsRuntime
())
{
PADDLE_ENFORCE_EQ
(
label_dim
[
1
],
1
,
"ShapeError: label's second dimension of "
"AccuracyOp must be 1. But received label's "
"second dimension is = %d, label's shape = [%s]"
,
label_dim
[
1
],
label_dim
);
PADDLE_ENFORCE_EQ
(
inference_dim
[
0
],
label_dim
[
0
],
"ShapeError: the output's num_rows of AccuracyOp must be"
" the same as label's num_rows. But received output's "
"shape = [%s], label's shape = [%s], output's num_rows = %d, label's "
"num_rows = %d"
,
inference_dim
,
label_dim
,
inference_dim
[
0
],
label_dim
[
0
]);
}
ctx
->
SetOutputDim
(
"Accuracy"
,
{
1
});
ctx
->
SetOutputDim
(
"Correct"
,
{
1
});
...
...
paddle/fluid/operators/metrics/auc_op.cc
浏览文件 @
8b59ac3a
...
...
@@ -28,14 +28,18 @@ class AucOp : public framework::OperatorWithKernel {
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"Label"
),
"Input of Label should not be null."
);
auto
predict_width
=
ctx
->
GetInputDim
(
"Predict"
)[
1
];
PADDLE_INFERSHAPE_ENFORCE_LE
(
ctx
,
predict_width
,
2
,
"Only support binary classification,"
"prediction dims[1] should be 1 or 2"
);
if
(
ctx
->
IsRuntime
())
{
PADDLE_ENFORCE_LE
(
predict_width
,
2
,
"Only support binary classification,"
"prediction dims[1] should be 1 or 2"
);
}
auto
predict_height
=
ctx
->
GetInputDim
(
"Predict"
)[
0
];
auto
label_height
=
ctx
->
GetInputDim
(
"Label"
)[
0
];
PADDLE_INFERSHAPE_ENFORCE_EQ
(
ctx
,
predict_height
,
label_height
,
"Out and Label should have same height."
);
if
(
ctx
->
IsRuntime
())
{
PADDLE_ENFORCE_EQ
(
predict_height
,
label_height
,
"Out and Label should have same height."
);
}
int
num_pred_buckets
=
ctx
->
Attrs
().
Get
<
int
>
(
"num_thresholds"
)
+
1
;
int
slide_steps
=
ctx
->
Attrs
().
Get
<
int
>
(
"slide_steps"
);
...
...
paddle/fluid/operators/smooth_l1_loss_op.cc
浏览文件 @
8b59ac3a
...
...
@@ -135,11 +135,13 @@ class SmoothL1LossGradOp : public framework::OperatorWithKernel {
PADDLE_ENFORCE_GE
(
out_dims
.
size
(),
2
,
"The tensor rank of Input(Out@Grad) should be 2."
);
PADDLE_INFERSHAPE_ENFORCE_EQ
(
ctx
,
out_dims
[
0
],
in_dims
[
0
],
"The 1st dimension of Input(Out@Grad) must be "
"same as input."
);
PADDLE_INFERSHAPE_ENFORCE_EQ
(
ctx
,
out_dims
[
1
],
1
,
"The 2nd dimension of Input(Out@Grad) must be 1."
);
if
(
ctx
->
IsRuntime
())
{
PADDLE_ENFORCE_EQ
(
out_dims
[
0
],
in_dims
[
0
],
"The 1st dimension of Input(Out@Grad) must be "
"same as input."
);
PADDLE_ENFORCE_EQ
(
out_dims
[
1
],
1
,
"The 2nd dimension of Input(Out@Grad) must be 1."
);
}
auto
x_grad_name
=
framework
::
GradVarName
(
"X"
);
auto
y_grad_name
=
framework
::
GradVarName
(
"Y"
);
...
...
paddle/fluid/operators/squared_l2_distance_op.cc
浏览文件 @
8b59ac3a
...
...
@@ -137,12 +137,14 @@ class SquaredL2DistanceGradOp : public framework::OperatorWithKernel {
auto
out_dims
=
ctx
->
GetInputDim
(
framework
::
GradVarName
(
"Out"
));
auto
x_dims
=
ctx
->
GetInputDim
(
"X"
);
auto
y_dims
=
ctx
->
GetInputDim
(
"Y"
);
PADDLE_INFERSHAPE_ENFORCE_EQ
(
ctx
,
out_dims
[
0
],
x_dims
[
0
],
"First dimension of output gradient and "
"input value must be equal."
);
PADDLE_INFERSHAPE_ENFORCE_EQ
(
ctx
,
out_dims
[
1
],
1
,
"Second dimension of output gradient "
"must be 1."
);
if
(
ctx
->
IsRuntime
())
{
PADDLE_ENFORCE_EQ
(
out_dims
[
0
],
x_dims
[
0
],
"First dimension of output gradient and "
"input value must be equal."
);
PADDLE_ENFORCE_EQ
(
out_dims
[
1
],
1
,
"Second dimension of output gradient "
"must be 1."
);
}
auto
x_grad_name
=
framework
::
GradVarName
(
"X"
);
auto
y_grad_name
=
framework
::
GradVarName
(
"Y"
);
if
(
ctx
->
HasOutput
(
x_grad_name
))
ctx
->
SetOutputDim
(
x_grad_name
,
x_dims
);
...
...
paddle/fluid/platform/enforce.h
浏览文件 @
8b59ac3a
...
...
@@ -484,46 +484,5 @@ struct BinaryCompareMessageConverter<false> {
#define PADDLE_ENFORCE_LE(__VAL0, __VAL1, ...) \
__PADDLE_BINARY_COMPARE(__VAL0, __VAL1, <=, >, __VA_ARGS__)
#define __PADDLE_INFERSHAPE_BINARY_COMPARE(__CTX, __VAL1, __VAL2, __CMP, \
__INV_CMP, ...) \
do { \
auto __val1 = (__VAL1); \
auto __val2 = (__VAL2); \
if (!__CTX->IsRuntime()) { \
if (__val1 == -1 || __val2 == -1) { \
break; \
} \
} \
using __TYPE1__ = decltype(__val1); \
using __TYPE2__ = decltype(__val2); \
using __COMMON_TYPE1__ = \
::paddle::platform::details::CommonType1<__TYPE1__, __TYPE2__>; \
using __COMMON_TYPE2__ = \
::paddle::platform::details::CommonType2<__TYPE1__, __TYPE2__>; \
bool __is_not_error = (static_cast<__COMMON_TYPE1__>(__val1))__CMP( \
static_cast<__COMMON_TYPE2__>(__val2)); \
if (UNLIKELY(!__is_not_error)) { \
PADDLE_THROW("Expected %s " #__CMP " %s, but received %s:%s " #__INV_CMP \
" %s:%s.\n%s", \
#__VAL1, #__VAL2, #__VAL1, \
::paddle::string::to_string(__val1), #__VAL2, \
::paddle::string::to_string(__val2), \
::paddle::string::Sprintf(__VA_ARGS__)); \
} \
} while (0)
#define PADDLE_INFERSHAPE_ENFORCE_EQ(__CTX, __VAL0, __VAL1, ...) \
__PADDLE_INFERSHAPE_BINARY_COMPARE(__CTX, __VAL0, __VAL1, ==, !=, __VA_ARGS__)
#define PADDLE_INFERSHAPE_ENFORCE_NE(__CTX, __VAL0, __VAL1, ...) \
__PADDLE_INFERSHAPE_BINARY_COMPARE(__CTX, __VAL0, __VAL1, !=, ==, __VA_ARGS__)
#define PADDLE_INFERSHAPE_ENFORCE_GT(__CTX, __VAL0, __VAL1, ...) \
__PADDLE_INFERSHAPE_BINARY_COMPARE(__CTX, __VAL0, __VAL1, >, <=, __VA_ARGS__)
#define PADDLE_INFERSHAPE_ENFORCE_GE(__CTX, __VAL0, __VAL1, ...) \
__PADDLE_INFERSHAPE_BINARY_COMPARE(__CTX, __VAL0, __VAL1, >=, <, __VA_ARGS__)
#define PADDLE_INFERSHAPE_ENFORCE_LT(__CTX, __VAL0, __VAL1, ...) \
__PADDLE_INFERSHAPE_BINARY_COMPARE(__CTX, __VAL0, __VAL1, <, >=, __VA_ARGS__)
#define PADDLE_INFERSHAPE_ENFORCE_LE(__CTX, __VAL0, __VAL1, ...) \
__PADDLE_INFERSHAPE_BINARY_COMPARE(__CTX, __VAL0, __VAL1, <=, >, __VA_ARGS__)
}
// namespace platform
}
// namespace paddle
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录