-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Conversation
将book/01.fit_a_line的 |
paddle/gserver/layers/CostLayer.cpp
Outdated
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]); |
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.
看上文CHECK_EQ(output.getWidth(), (*label.value).getWidth())
和test_LayerGrad中config.inputDefs.push_back({INPUT_DATA, "layer_0", 10, 0})
是支持多维数据的,多维情况下这里在计算时只是顺序取出了output
和label
的前numSamples
个值,这样取出的数据来计算loss应该会有些问题。
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
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) { |
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.
同forwardImp
,多维情况下应该会有问题,可能因为forward
和backward
中取数据用了相同的方式所以test_LayerGrad可以通过。
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
paddle/gserver/layers/CostLayer.cpp
Outdated
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) { |
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.
Huber loss 针对分类问题的这种变种只会有一维输出,不应该出现多维。分类问题不需要修改为多维。
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,已经改成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.
LGTM.
新加的 huber_regression_cost,v1能用吗? |
v1也是可以用的 |
需要更新 v1 的本地工具文件吗? |
本地工具文件是指?需要用最新的develop分支代码 |
fix #3390
Current
huber_cost
in Paddle is for classification, thus, rename it tohuber_classification_cost
, and add an extra cost layer:huber_regression_cost
.