-
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
Smoothl1 loss and Python API. #1870
Conversation
paddle/gserver/layers/CostLayer.h
Outdated
@@ -91,8 +91,8 @@ class MultiClassCrossEntropy : public CostLayer { | |||
* | |||
* [1] Jacob Devlin, Rabih Zbib, Zhongqiang Huang, Thomas Lamar, | |||
* Richard Schwartz, and John Makhoul. Fast and robust neural | |||
* network joint models for statistical machine translation. | |||
* In Proceedings of the ACL 2014 Conference. | |||
* network joint models for statistical machine translation. * In |
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.
revert了~
if (std::fabs(cost[j]) >= 1) cost[j] = (0 < cost[j]) - (cost[j] < 0); | ||
real val = out[j] - lbl[j]; | ||
if (std::fabs(val) < 1) { | ||
grad[j] += val; |
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.
这里是不是应该是grad[i] += val; 上面循环中去掉grad += dim grad的维度应该与numSamples的数量一致吧。之前在循环里加了dim,因为check了dim必须是1,如果dim不是1就错了。
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.
grad的大小为:numSamples * dim,代表第一个input对应的gradient.
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.
可以看https://github.com/PaddlePaddle/Paddle/blob/develop/paddle/gserver/layers/CostLayer.cpp 这个文件 60行->68行-> 227行 -> 244行。
grad和out的维度一致。
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.
嗯。。是我想错了。
@@ -1685,7 +1685,7 @@ TEST(Layer, smooth_l1) { | |||
config.layerConfig.add_inputs(); | |||
|
|||
for (auto useGpu : {false, true}) { | |||
testLayerGrad(config, "smooth_l1", 100, false, useGpu, false, 2.0); | |||
testLayerGrad(config, "smooth_l1", 100, false, useGpu, false); | |||
} | |||
} | |||
|
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.
Can you extend the loss test to have more than 1 dim output ?
config.inputDefs.push_back({INPUT_DATA, "layer_0", 1, 0});
config.inputDefs.push_back({INPUT_DATA_TARGET, "layer_1", 1, 0});
Change the size of input and label to be 10 in order to make sure it works with more than 1 dim
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. Thanks!
@@ -498,6 +498,12 @@ hsigmoid | |||
:members: hsigmoid | |||
:noindex: | |||
|
|||
smooth_l1 |
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.
请加到doc/api/v2/config/layer.rst里面,v1里面的不用改了。
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.
Fix #1859
@pengwangucla @gaoyuan please help to review. Thanks!