Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
990818f7
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看板
未验证
提交
990818f7
编写于
11月 30, 2017
作者:
Y
Yang yaming
提交者:
GitHub
11月 30, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #6031 from pkuyym/fix-6016
Refine doc for smooth l1 loss op.
上级
00eceea0
a5236265
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
36 addition
and
26 deletion
+36
-26
paddle/operators/smooth_l1_loss_op.cc
paddle/operators/smooth_l1_loss_op.cc
+36
-26
未找到文件。
paddle/operators/smooth_l1_loss_op.cc
浏览文件 @
990818f7
...
@@ -22,22 +22,20 @@ class SmoothL1LossOp : public framework::OperatorWithKernel {
...
@@ -22,22 +22,20 @@ class SmoothL1LossOp : public framework::OperatorWithKernel {
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"X"
),
"
X must be initialized
."
);
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"X"
),
"
Input(X) should not be null
."
);
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"Y"
),
"
Y must be initialized
."
);
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"Y"
),
"
Input(Y) should not be null
."
);
auto
x_dims
=
ctx
->
GetInputDim
(
"X"
);
auto
x_dims
=
ctx
->
GetInputDim
(
"X"
);
auto
y_dims
=
ctx
->
GetInputDim
(
"Y"
);
auto
y_dims
=
ctx
->
GetInputDim
(
"Y"
);
PADDLE_ENFORCE_EQ
(
x_dims
,
y_dims
,
"The shape of X and Y must be the same."
);
PADDLE_ENFORCE_EQ
(
x_dims
,
y_dims
);
PADDLE_ENFORCE_GE
(
x_dims
.
size
(),
2
,
PADDLE_ENFORCE_GE
(
x_dims
.
size
(),
2
,
"The tensor rank of
X must be at least
2."
);
"The tensor rank of
Input(X) should not be less than
2."
);
if
(
ctx
->
HasInput
(
"InsideWeight"
))
{
if
(
ctx
->
HasInput
(
"InsideWeight"
))
{
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"OutsideWeight"
),
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"OutsideWeight"
),
"If weights are provided, must specify both "
"If weights are provided, must specify both "
"inside and outside weights."
);
"inside and outside weights."
);
PADDLE_ENFORCE_EQ
(
ctx
->
GetInputDim
(
"InsideWeight"
),
x_dims
,
PADDLE_ENFORCE_EQ
(
ctx
->
GetInputDim
(
"InsideWeight"
),
x_dims
);
"The shape of InsideWeight must be same as X."
);
PADDLE_ENFORCE_EQ
(
ctx
->
GetInputDim
(
"OutsideWeight"
),
x_dims
);
PADDLE_ENFORCE_EQ
(
ctx
->
GetInputDim
(
"OutsideWeight"
),
x_dims
,
"The shape of OutsideWeight must be same as X."
);
}
}
ctx
->
SetOutputDim
(
"Diff"
,
x_dims
);
ctx
->
SetOutputDim
(
"Diff"
,
x_dims
);
...
@@ -53,25 +51,29 @@ class SmoothL1LossOpMaker : public framework::OpProtoAndCheckerMaker {
...
@@ -53,25 +51,29 @@ class SmoothL1LossOpMaker : public framework::OpProtoAndCheckerMaker {
framework
::
OpAttrChecker
*
op_checker
)
framework
::
OpAttrChecker
*
op_checker
)
:
OpProtoAndCheckerMaker
(
proto
,
op_checker
)
{
:
OpProtoAndCheckerMaker
(
proto
,
op_checker
)
{
AddInput
(
"X"
,
AddInput
(
"X"
,
"
The input tensor of smooth l1 loss op.
"
"
(Tensor, default Tensor<float>) A tensor with rank at least 2.
"
"The
rank should be greater or equal to 2
with shape "
"The
input value of smooth l1 loss op
with shape "
"[batch_size,
value_dim1, value_dim2, ..., value_dimN]
"
);
"[batch_size,
dim1, ..., dimN].
"
);
AddInput
(
"Y"
,
AddInput
(
"Y"
,
"
The target tensor of smooth l1 loss op
"
"
(Tensor, default Tensor<float>) A tensor with rank at least 2.
"
"
with the
same shape as X."
);
"
The target value of smooth l1 loss op with
same shape as X."
);
AddInput
(
"InsideWeight"
,
AddInput
(
"InsideWeight"
,
"Optional input tensor of smooth l1 loss op with the same shape "
"(Tensor, default Tensor<float>) A tensor with rank at least 2. "
"as X. If provided, the result of (X - Y) will be multiplied "
"This input is optional and should have same shape with X. "
"If provided, the result of (X - Y) will be multiplied "
"by this tensor element by element."
)
"by this tensor element by element."
)
.
AsDispensable
();
.
AsDispensable
();
AddInput
(
"OutsideWeight"
,
AddInput
(
"OutsideWeight"
,
"Optinal input of smooth l1 loss op with the same shape as X."
"(Tensor, default Tensor<float>) A tensor with rank at least 2. "
"If provided, the output smooth l1 loss will be multiplied by "
"This input is optional and should have same shape with X. "
"this tensor element by element."
)
"If provided, the out smooth l1 loss will be multiplied by this "
"tensor element by element."
)
.
AsDispensable
();
.
AsDispensable
();
AddOutput
(
"Diff"
,
"Intermediate variable to cache InsideWeight
*(X-
Y)."
)
AddOutput
(
"Diff"
,
"Intermediate variable to cache InsideWeight
* (X -
Y)."
)
.
AsIntermediate
();
.
AsIntermediate
();
AddOutput
(
"Out"
,
"Smooth l1 loss."
);
AddOutput
(
"Out"
,
"(Tensor, default Tensor<float>) A tensor with rank be 2. "
"The output smooth l1 loss with shape [batch_size, 1]."
);
AddAttr
<
AttrType
>
(
"sigma"
,
AddAttr
<
AttrType
>
(
"sigma"
,
"Hyper parameter of smooth l1 loss op."
"Hyper parameter of smooth l1 loss op."
"A float scalar with default value 3.0."
)
"A float scalar with default value 3.0."
)
...
@@ -79,15 +81,23 @@ class SmoothL1LossOpMaker : public framework::OpProtoAndCheckerMaker {
...
@@ -79,15 +81,23 @@ class SmoothL1LossOpMaker : public framework::OpProtoAndCheckerMaker {
AddComment
(
R"DOC(
AddComment
(
R"DOC(
Smooth L1 Loss Operator.
Smooth L1 Loss Operator.
This operator computes the smooth l1 loss for
input and target
.
This operator computes the smooth l1 loss for
X and Y
.
The operator takes the first dimension of
input as the
batch size.
The operator takes the first dimension of
X and Y as
batch size.
For each instance, it computes the smooth l1 loss element by element first
For each instance, it computes the smooth l1 loss element by element first
and then sums all the losses. So the resulting output shape
and then sums all the losses. So the shape of Out is [batch_size, 1].
is [batch_size, 1].
The equation is:
The equation is:
loss = $$0.5 * (\sigma * (x-y))^2$$ if $$|x - y| < 1 /({\sigma}^2)$$
$$
$$\frac{|x - y| - 0.5}{{\sigma}^2}$$ otherwise
Out_{\sigma}(X, Y)_i = \begin{cases}
0.5 * (\sigma * (X_i - Y_i)) ^ 2
\quad |X_i - Y_i| \lt \frac{1} {{\sigma} ^ 2} \\
\frac{|X_i - Y_i| - 0.5}{{\sigma}^2},
\quad otherwise
\end{cases}
$$
In the above equation, $Out_{\sigma}(X, Y)_i$, $X_i$ and $Y_i$ represent the ith
element of Out, X and Y.
)DOC"
);
)DOC"
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录