Fix focal loss

The loss value should reflect the impact of the gamma parameter, as well.
pull/2554/head
Adrià Arrufat 3 years ago committed by Davis E. King
parent 5cb036564c
commit 9bb1b6f712

@ -850,14 +850,14 @@ namespace dlib
{
const float temp = log1pexp(-out_data[idx]);
const float focus = std::pow(1 - g[idx], gamma);
loss += y * scale * temp;
loss += y * scale * temp * focus;
g[idx] = y * scale * focus * (g[idx] * (gamma * temp + 1) - 1);
}
else
{
const float temp = -(-out_data[idx] - log1pexp(-out_data[idx]));
const float focus = std::pow(g[idx], gamma);
loss += -y * scale * temp;
loss += -y * scale * temp * focus;
g[idx] = -y * scale * focus * g[idx] * (gamma * temp + 1);
}
}

Loading…
Cancel
Save