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

refine Huber loss, add huber_regression_cost #3571

Merged
merged 12 commits into from
Aug 29, 2017
Merged

refine Huber loss, add huber_regression_cost #3571

merged 12 commits into from
Aug 29, 2017

Conversation

luotao1
Copy link
Contributor

@luotao1 luotao1 commented Aug 18, 2017

fix #3390
Current huber_cost in Paddle is for classification, thus, rename it to huber_classification_cost, and add an extra cost layer: huber_regression_cost.

@luotao1
Copy link
Contributor Author

luotao1 commented Aug 21, 2017

book/01.fit_a_linemse_cost改成huber_regression_cost,Test的cost能正常收敛,详细见
log.txt

useGpu_ ? tmpCpuInput_[1].value->getData() : (*label.value).getData();
std::vector<real> cost(numSamples);
for (size_t i = 0; i < numSamples; ++i) {
real a = std::abs(lbl[i] - out[i]);
Copy link
Contributor

@guoshengCS guoshengCS Aug 22, 2017

Choose a reason for hiding this comment

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

看上文CHECK_EQ(output.getWidth(), (*label.value).getWidth())和test_LayerGrad中config.inputDefs.push_back({INPUT_DATA, "layer_0", 10, 0})是支持多维数据的,多维情况下这里在计算时只是顺序取出了output label的前numSamples 个值,这样取出的数据来计算loss应该会有些问题。

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

int* lbl = (*label.ids).getData();
real* out = useGpu_ ? tmpCpuInput_[0].value->getData() : output.getData();
int* lbl = useGpu_ ? tmpCpuInput_[1].ids->getData() : (*label.ids).getData();
real* grad = useGpu_ ? tmpCpuInput_[0].grad->getData() : outputG.getData();
for (size_t i = 0; i < numSamples; ++i) {
Copy link
Contributor

Choose a reason for hiding this comment

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

forwardImp ,多维情况下应该会有问题,可能因为forwardbackward中取数据用了相同的方式所以test_LayerGrad可以通过。

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

@FrankRouter FrankRouter mentioned this pull request Aug 29, 2017
grad[i] += -4 * y;
else if (y * out[i] < 1)
grad[i] += -2 * (1 - y * out[i]) * y;
for (size_t j = 0; j < dim; ++j) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Huber loss 针对分类问题的这种变种只会有一维输出,不应该出现多维。分类问题不需要修改为多维。

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,已经改成1维了。

Copy link
Contributor

@lcy-seso lcy-seso left a comment

Choose a reason for hiding this comment

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

LGTM.

@luotao1 luotao1 merged commit 47eb869 into PaddlePaddle:develop Aug 29, 2017
@luotao1 luotao1 deleted the huber_loss branch August 29, 2017 09:03
@FrankRouter
Copy link

新加的 huber_regression_cost,v1能用吗?

@luotao1
Copy link
Contributor Author

luotao1 commented Aug 29, 2017

v1也是可以用的

@FrankRouter
Copy link

需要更新 v1 的本地工具文件吗?

@luotao1
Copy link
Contributor Author

luotao1 commented Aug 29, 2017

本地工具文件是指?需要用最新的develop分支代码

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.

huber loss
4 participants