Skip to content
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

Merged
merged 10 commits into from
Apr 25, 2017
Merged

Conversation

qingqing01
Copy link
Contributor

@qingqing01 qingqing01 commented Apr 24, 2017

  • fix smoothl1 loss implementation
  • fix the unit test
  • add Python API

Fix #1859

@pengwangucla @gaoyuan please help to review. Thanks!

@QiJune QiJune changed the title Smoothl1 loss and Pyathon API. Smoothl1 loss and Python API. Apr 24, 2017
@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

格式好像出错了

Copy link
Contributor Author

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;
Copy link
Contributor

@Noplz Noplz Apr 24, 2017

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就错了。

Copy link
Contributor Author

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.

Copy link
Contributor Author

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的维度一致。

Copy link
Contributor

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);
}
}

Copy link
Collaborator

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Thanks!

@qingqing01 qingqing01 requested a review from luotao1 April 25, 2017 02:50
@@ -498,6 +498,12 @@ hsigmoid
:members: hsigmoid
:noindex:

smooth_l1
Copy link
Contributor

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里面的不用改了。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@luotao1 luotao1 merged commit 59be92e into PaddlePaddle:develop Apr 25, 2017
@qingqing01 qingqing01 deleted the smoothl1_loss branch July 7, 2017 13:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Smooth l1 layer only allow size == 1 ?
4 participants