Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
PaddleDetection
提交
4db50fbc
P
PaddleDetection
项目概览
s920243400
/
PaddleDetection
与 Fork 源项目一致
Fork自
PaddlePaddle / PaddleDetection
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
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 {
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
protected:
void
InferShape
(
const
framework
::
InferShapeContext
&
ctx
)
const
override
{
void
InferShape
(
framework
::
InferShapeContextBase
*
ctx
)
const
override
{
// input check
PADDLE_ENFORCE_NOT_NULL
(
ctx
.
InputVar
(
"Label"
),
"Input(Label) shouldn't be null."
);
PADDLE_ENFORCE_NOT_NULL
(
ctx
.
InputVar
(
"X1"
),
"Input(X1) shouldn't be null."
);
PADDLE_ENFORCE_NOT_NULL
(
ctx
.
InputVar
(
"X2"
),
"Input(X2) shouldn't be null."
);
PADDLE_ENFORCE_NOT_NULL
(
ctx
.
OutputVar
(
"Out"
),
"Output(X2) shouldn't be null."
);
auto
label_dims
=
ctx
.
Input
<
framework
::
Tensor
>
(
"Label"
)
->
dims
();
auto
x1_dims
=
ctx
.
Input
<
framework
::
Tensor
>
(
"X1"
)
->
dims
();
auto
x2_dims
=
ctx
.
Input
<
framework
::
Tensor
>
(
"X2"
)
->
dims
();
PADDLE_ENFORCE
((
label_dims
==
x1_dims
)
&&
(
x1_dims
==
x2_dims
)
&&
(
label_dims
.
size
()
==
2
)
&&
(
label_dims
[
1
]
==
1
),
"All inputs must be vector with the same size."
);
auto
act_t
=
ctx
.
Output
<
framework
::
LoDTensor
>
(
"Activated"
);
auto
out_t
=
ctx
.
Output
<
framework
::
LoDTensor
>
(
"Out"
);
if
(
act_t
)
{
act_t
->
Resize
(
label_dims
);
}
if
(
out_t
)
{
out_t
->
Resize
(
label_dims
);
}
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"Label"
),
"Input(Label) shouldn't be null."
);
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"X1"
),
"Input(X1) shouldn't be null."
);
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"X2"
),
"Input(X2) shouldn't be null."
);
PADDLE_ENFORCE
(
ctx
->
HasOutput
(
"Out"
),
"Output(Out) shouldn't be null."
);
auto
label_dims
=
ctx
->
GetInputDim
(
"Label"
);
auto
x1_dims
=
ctx
->
GetInputDim
(
"X1"
);
auto
x2_dims
=
ctx
->
GetInputDim
(
"X2"
);
PADDLE_ENFORCE
(
(
label_dims
==
x1_dims
)
&&
(
x1_dims
==
x2_dims
)
&&
(
label_dims
.
size
()
==
2
)
&&
(
label_dims
[
1
]
==
1
),
"All inputs must be 2-D tensor with shape [batch_size x 1]."
);
ctx
->
SetOutputDim
(
"Activated"
,
label_dims
);
ctx
->
SetOutputDim
(
"Out"
,
label_dims
);
}
};
...
...
@@ -71,7 +64,7 @@ class MarginRankLossOpMaker : public framework::OpProtoAndCheckerMaker {
.
AsIntermediate
();
AddOutput
(
"Out"
,
"(2-D tensor with shape [batch_size x 1])"
"The output loss of MarginRankLoss operator"
);
"The output loss of MarginRankLoss operator
.
"
);
AddComment
(
R"DOC(
MarginRankLoss operator measures the loss given a pair of input {`X1`, `X2`}
...
...
@@ -96,26 +89,17 @@ class MarginRankLossGradOp : public framework::OperatorWithKernel {
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
protected:
void
InferShape
(
const
framework
::
InferShapeContext
&
ctx
)
const
override
{
PADDLE_ENFORCE_NOT_NULL
(
ctx
.
InputVar
(
"Label"
),
"Input(Label) shouldn't be null."
);
PADDLE_ENFORCE_NOT_NULL
(
ctx
.
InputVar
(
"X1"
),
"Input(X1) shouldn't be null."
);
PADDLE_ENFORCE_NOT_NULL
(
ctx
.
InputVar
(
"X2"
),
"Input(X2) shouldn't be null."
);
PADDLE_ENFORCE_NOT_NULL
(
ctx
.
InputVar
(
framework
::
GradVarName
(
"Out"
)),
"Input(Out@GRAD) shouldn't be null."
);
PADDLE_ENFORCE_NOT_NULL
(
ctx
.
InputVar
(
"Activated"
),
"Intermediate(Activated) shouldn't be null."
);
auto
dims
=
ctx
.
Input
<
framework
::
Tensor
>
(
"X1"
)
->
dims
();
auto
*
x1_grad
=
ctx
.
Output
<
framework
::
LoDTensor
>
(
framework
::
GradVarName
(
"X1"
));
auto
*
x2_grad
=
ctx
.
Output
<
framework
::
LoDTensor
>
(
framework
::
GradVarName
(
"X2"
));
if
(
x1_grad
)
{
x1_grad
->
Resize
(
dims
);
}
if
(
x2_grad
)
{
x2_grad
->
Resize
(
dims
);
}
void
InferShape
(
framework
::
InferShapeContextBase
*
ctx
)
const
override
{
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"Label"
),
"Input(Label) shouldn't be null."
);
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"X1"
),
"Input(X1) shouldn't be null."
);
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"X2"
),
"Input(X2) shouldn't be null."
);
PADDLE_ENFORCE
(
ctx
->
HasInput
(
framework
::
GradVarName
(
"Out"
)),
"Input(Out@GRAD) shouldn't be null."
);
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"Activated"
),
"Intermediate(Activated) shouldn't be null."
);
auto
dims
=
ctx
->
GetInputDim
(
"Label"
);
ctx
->
SetOutputDim
(
framework
::
GradVarName
(
"X1"
),
dims
);
ctx
->
SetOutputDim
(
framework
::
GradVarName
(
"X2"
),
dims
);
}
};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录