|
|
|
@ -575,9 +575,9 @@ void MultiBinaryLabelCrossEntropy::backwardImp(Matrix& output,
|
|
|
|
|
//
|
|
|
|
|
// Huber loss for robust 2-classes classification
|
|
|
|
|
//
|
|
|
|
|
REGISTER_LAYER(huber, HuberTwoClass);
|
|
|
|
|
REGISTER_LAYER(huber, HuberTwoClassification);
|
|
|
|
|
|
|
|
|
|
bool HuberTwoClass::init(const LayerMap& layerMap,
|
|
|
|
|
bool HuberTwoClassification::init(const LayerMap& layerMap,
|
|
|
|
|
const ParameterMap& parameterMap) {
|
|
|
|
|
CostLayer::init(layerMap, parameterMap);
|
|
|
|
|
if (useGpu_) {
|
|
|
|
@ -589,7 +589,9 @@ bool HuberTwoClass::init(const LayerMap& layerMap,
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HuberTwoClass::forwardImp(Matrix& output, Argument& label, Matrix& cost) {
|
|
|
|
|
void HuberTwoClassification::forwardImp(Matrix& output,
|
|
|
|
|
Argument& label,
|
|
|
|
|
Matrix& cost) {
|
|
|
|
|
if (useGpu_) {
|
|
|
|
|
for (size_t i = 0; i < inputLayers_.size(); i++) {
|
|
|
|
|
tmpCpuInput_[i].resizeAndCopyFrom(
|
|
|
|
@ -600,10 +602,11 @@ void HuberTwoClass::forwardImp(Matrix& output, Argument& label, Matrix& cost) {
|
|
|
|
|
forwardImpIn(output, label, cost);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HuberTwoClass::forwardImpIn(Matrix& output,
|
|
|
|
|
void HuberTwoClassification::forwardImpIn(Matrix& output,
|
|
|
|
|
Argument& label,
|
|
|
|
|
Matrix& target) {
|
|
|
|
|
size_t numSamples = target.getHeight();
|
|
|
|
|
CHECK(label.ids);
|
|
|
|
|
CHECK_EQ((*label.ids).getSize(), numSamples);
|
|
|
|
|
CHECK_EQ(output.getHeight(), numSamples);
|
|
|
|
|
CHECK_EQ(output.getWidth(), (size_t)1);
|
|
|
|
@ -624,7 +627,7 @@ void HuberTwoClass::forwardImpIn(Matrix& output,
|
|
|
|
|
target.copyFrom(cost.data(), numSamples);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HuberTwoClass::backwardImp(Matrix& outputValue,
|
|
|
|
|
void HuberTwoClassification::backwardImp(Matrix& outputValue,
|
|
|
|
|
Argument& label,
|
|
|
|
|
Matrix& outputGrad) {
|
|
|
|
|
if (useGpu_) {
|
|
|
|
@ -636,7 +639,7 @@ void HuberTwoClass::backwardImp(Matrix& outputValue,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HuberTwoClass::backwardImpIn(Matrix& output,
|
|
|
|
|
void HuberTwoClassification::backwardImpIn(Matrix& output,
|
|
|
|
|
Argument& label,
|
|
|
|
|
Matrix& outputG) {
|
|
|
|
|
size_t numSamples = output.getHeight();
|
|
|
|
|