Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
4db50fbc
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 2 年 前同步成功
通知
2325
Star
20933
Fork
5424
代码
文件
提交
分支
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看板
提交
4db50fbc
编写于
9月 28, 2017
作者:
Y
Yibing Liu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
adapt to the new infershape interface
上级
e303897f
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
26 addition
and
42 deletion
+26
-42
paddle/operators/margin_rank_loss_op.cc
paddle/operators/margin_rank_loss_op.cc
+26
-42
未找到文件。
paddle/operators/margin_rank_loss_op.cc
浏览文件 @
4db50fbc
...
@@ -22,28 +22,21 @@ class MarginRankLossOp : public framework::OperatorWithKernel {
...
@@ -22,28 +22,21 @@ class MarginRankLossOp : public framework::OperatorWithKernel {
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
protected:
protected:
void
InferShape
(
const
framework
::
InferShapeContext
&
ctx
)
const
override
{
void
InferShape
(
framework
::
InferShapeContextBase
*
ctx
)
const
override
{
// input check
// input check
PADDLE_ENFORCE_NOT_NULL
(
ctx
.
InputVar
(
"Label"
),
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"Label"
),
"Input(Label) shouldn't be null."
);
"Input(Label) shouldn't be null."
);
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"X1"
),
"Input(X1) shouldn't be null."
);
PADDLE_ENFORCE_NOT_NULL
(
ctx
.
InputVar
(
"X1"
),
"Input(X1) shouldn't be null."
);
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"X2"
),
"Input(X2) shouldn't be null."
);
PADDLE_ENFORCE_NOT_NULL
(
ctx
.
InputVar
(
"X2"
),
"Input(X2) shouldn't be null."
);
PADDLE_ENFORCE
(
ctx
->
HasOutput
(
"Out"
),
"Output(Out) shouldn't be null."
);
PADDLE_ENFORCE_NOT_NULL
(
ctx
.
OutputVar
(
"Out"
),
auto
label_dims
=
ctx
->
GetInputDim
(
"Label"
);
"Output(X2) shouldn't be null."
);
auto
x1_dims
=
ctx
->
GetInputDim
(
"X1"
);
auto
label_dims
=
ctx
.
Input
<
framework
::
Tensor
>
(
"Label"
)
->
dims
();
auto
x2_dims
=
ctx
->
GetInputDim
(
"X2"
);
auto
x1_dims
=
ctx
.
Input
<
framework
::
Tensor
>
(
"X1"
)
->
dims
();
PADDLE_ENFORCE
(
auto
x2_dims
=
ctx
.
Input
<
framework
::
Tensor
>
(
"X2"
)
->
dims
();
(
label_dims
==
x1_dims
)
&&
(
x1_dims
==
x2_dims
)
&&
PADDLE_ENFORCE
((
label_dims
==
x1_dims
)
&&
(
x1_dims
==
x2_dims
)
&&
(
label_dims
.
size
()
==
2
)
&&
(
label_dims
[
1
]
==
1
),
(
label_dims
.
size
()
==
2
)
&&
(
label_dims
[
1
]
==
1
),
"All inputs must be vector with the same size."
);
"All inputs must be 2-D tensor with shape [batch_size x 1]."
);
auto
act_t
=
ctx
.
Output
<
framework
::
LoDTensor
>
(
"Activated"
);
ctx
->
SetOutputDim
(
"Activated"
,
label_dims
);
auto
out_t
=
ctx
.
Output
<
framework
::
LoDTensor
>
(
"Out"
);
ctx
->
SetOutputDim
(
"Out"
,
label_dims
);
if
(
act_t
)
{
act_t
->
Resize
(
label_dims
);
}
if
(
out_t
)
{
out_t
->
Resize
(
label_dims
);
}
}
}
};
};
...
@@ -71,7 +64,7 @@ class MarginRankLossOpMaker : public framework::OpProtoAndCheckerMaker {
...
@@ -71,7 +64,7 @@ class MarginRankLossOpMaker : public framework::OpProtoAndCheckerMaker {
.
AsIntermediate
();
.
AsIntermediate
();
AddOutput
(
"Out"
,
AddOutput
(
"Out"
,
"(2-D tensor with shape [batch_size x 1])"
"(2-D tensor with shape [batch_size x 1])"
"The output loss of MarginRankLoss operator"
);
"The output loss of MarginRankLoss operator
.
"
);
AddComment
(
R"DOC(
AddComment
(
R"DOC(
MarginRankLoss operator measures the loss given a pair of input {`X1`, `X2`}
MarginRankLoss operator measures the loss given a pair of input {`X1`, `X2`}
...
@@ -96,26 +89,17 @@ class MarginRankLossGradOp : public framework::OperatorWithKernel {
...
@@ -96,26 +89,17 @@ class MarginRankLossGradOp : public framework::OperatorWithKernel {
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
protected:
protected:
void
InferShape
(
const
framework
::
InferShapeContext
&
ctx
)
const
override
{
void
InferShape
(
framework
::
InferShapeContextBase
*
ctx
)
const
override
{
PADDLE_ENFORCE_NOT_NULL
(
ctx
.
InputVar
(
"Label"
),
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"Label"
),
"Input(Label) shouldn't be null."
);
"Input(Label) shouldn't be null."
);
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"X1"
),
"Input(X1) shouldn't be null."
);
PADDLE_ENFORCE_NOT_NULL
(
ctx
.
InputVar
(
"X1"
),
"Input(X1) shouldn't be null."
);
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"X2"
),
"Input(X2) shouldn't be null."
);
PADDLE_ENFORCE_NOT_NULL
(
ctx
.
InputVar
(
"X2"
),
"Input(X2) shouldn't be null."
);
PADDLE_ENFORCE
(
ctx
->
HasInput
(
framework
::
GradVarName
(
"Out"
)),
PADDLE_ENFORCE_NOT_NULL
(
ctx
.
InputVar
(
framework
::
GradVarName
(
"Out"
)),
"Input(Out@GRAD) shouldn't be null."
);
"Input(Out@GRAD) shouldn't be null."
);
PADDLE_ENFORCE
_NOT_NULL
(
ctx
.
InputVar
(
"Activated"
),
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"Activated"
),
"Intermediate(Activated) shouldn't be null."
);
"Intermediate(Activated) shouldn't be null."
);
auto
dims
=
ctx
.
Input
<
framework
::
Tensor
>
(
"X1"
)
->
dims
();
auto
dims
=
ctx
->
GetInputDim
(
"Label"
);
auto
*
x1_grad
=
ctx
->
SetOutputDim
(
framework
::
GradVarName
(
"X1"
),
dims
);
ctx
.
Output
<
framework
::
LoDTensor
>
(
framework
::
GradVarName
(
"X1"
));
ctx
->
SetOutputDim
(
framework
::
GradVarName
(
"X2"
),
dims
);
auto
*
x2_grad
=
ctx
.
Output
<
framework
::
LoDTensor
>
(
framework
::
GradVarName
(
"X2"
));
if
(
x1_grad
)
{
x1_grad
->
Resize
(
dims
);
}
if
(
x2_grad
)
{
x2_grad
->
Resize
(
dims
);
}
}
}
};
};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录