Fix focal loss

The loss value should reflect the impact of the gamma parameter, as well.
This commit is contained in:
Adrià Arrufat 2022-03-31 07:55:27 +09:00 committed by Davis E. King
parent 5cb036564c
commit 9bb1b6f712
1 changed files with 2 additions and 2 deletions

View File

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