-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix paddle.nn.loss.L1Loss OP, add paddle.nn.functional.l1_loss OP for API2.0, test=develop #26040
Conversation
Thanks for your contribution! |
✅ This PR's description meets the template requirements! |
This operator computes the L1 Loss of Tensor ``x`` and ``label`` as follows. | ||
|
||
If :attr:`reduction` set to ``'none'``, the loss is: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是否需要多一行?none mean下面都空了一行
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
python/paddle/nn/functional/loss.py
Outdated
|
||
if reduction == 'sum': | ||
unreduced = paddle.elementwise_sub(x, label, act='abs') | ||
return paddle.reduce_sum(unreduced, name=name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
建议在2.0中将paddel.reduce_sum 改成paddel.sum paddle.reduce_mean改成paddle.mean
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
elif reduction == 'mean': | ||
unreduced = paddle.elementwise_sub(x, label, act='abs') | ||
return paddle.reduce_mean(unreduced, name=name) | ||
else: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
动态图是使用core.ops
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
output = l1_loss(input,label) | ||
print(output.numpy()) | ||
""" | ||
if reduction not in ['sum', 'mean', 'none']: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
最前面是动态图的代码,使用core.ops
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
2c8fc55
to
23214ac
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
b873ff7
to
c81047e
Compare
If :attr:`reduction` set to ``'sum'``, the reduced sum loss is: | ||
Out = MEAN(\lvert x - label\rvert) | ||
|
||
If :attr:`reduction` set to ``'sum'``, the loss is: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
此处下面公式,应空一行
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -279,63 +275,53 @@ class L1Loss(fluid.dygraph.Layer): | |||
If :attr:`reduction` is ``'mean'``, the reduced mean loss is returned. | |||
If :attr:`reduction` is ``'sum'``, the reduced sum loss is returned. | |||
Default is ``'mean'``. | |||
Returns: | |||
A callable object of L1Loss. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
各个小节之间,目测也应空一行
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
… API2.0, test=develop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -279,63 +276,55 @@ class L1Loss(fluid.dygraph.Layer): | |||
If :attr:`reduction` is ``'mean'``, the reduced mean loss is returned. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
【If :attr:reduction
is 'mean'
】->【If reduction
is 'mean'
】
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
经查看,两者显示效果相同
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
PR types
New features
PR changes
APIs
Describe
fix paddle.nn.loss.L1Loss OP, add paddle.nn.functional.l1_loss OP for API2.0