Skip to content

Commit

Permalink
Fixed label_smoothing for Detector
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexeyAB committed Mar 2, 2020
1 parent c814d56 commit 81290b0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
16 changes: 14 additions & 2 deletions src/gaussian_yolo_layer.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,13 +371,25 @@ void delta_gaussian_yolo_class(float *output, float *delta, int index, int class
{
int n;
if (delta[index]){
delta[index + stride*class_id] = (1 - label_smooth_eps) - output[index + stride*class_id];
if (label_smooth_eps > 0) {
float out_val = output[index + stride*class_id] * (1 - label_smooth_eps) + 0.5*label_smooth_eps;
delta[index + stride*class_id] = 1 - out_val;
}
else {
delta[index + stride*class_id] = 1 - output[index + stride*class_id];
}
if (classes_multipliers) delta[index + stride*class_id] *= classes_multipliers[class_id];
if(avg_cat) *avg_cat += output[index + stride*class_id];
return;
}
for(n = 0; n < classes; ++n){
delta[index + stride*n] = ((n == class_id) ? (1 - label_smooth_eps) : (0 + label_smooth_eps/classes)) - output[index + stride*n];
if (label_smooth_eps > 0) {
float out_val = output[index + stride*class_id] * (1 - label_smooth_eps) + 0.5*label_smooth_eps;
delta[index + stride*n] = ((n == class_id) ? 1 : 0) - out_val;
}
else {
delta[index + stride*n] = ((n == class_id) ? 1 : 0) - output[index + stride*n];
}
if (classes_multipliers && n == class_id) delta[index + stride*class_id] *= classes_multipliers[class_id];
if(n == class_id && avg_cat) *avg_cat += output[index + stride*n];
}
Expand Down
16 changes: 14 additions & 2 deletions src/yolo_layer.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,13 @@ void delta_yolo_class(float *output, float *delta, int index, int class_id, int
{
int n;
if (delta[index + stride*class_id]){
delta[index + stride*class_id] = (1 - label_smooth_eps) - output[index + stride*class_id];
if (label_smooth_eps > 0) {
float out_val = output[index + stride*class_id] * (1 - label_smooth_eps) + 0.5*label_smooth_eps;
delta[index + stride*class_id] = 1 - out_val;
}
else {
delta[index + stride*class_id] = 1 - output[index + stride*class_id];
}
if (classes_multipliers) delta[index + stride*class_id] *= classes_multipliers[class_id];
if(avg_cat) *avg_cat += output[index + stride*class_id];
return;
Expand Down Expand Up @@ -285,7 +291,13 @@ void delta_yolo_class(float *output, float *delta, int index, int class_id, int
else {
// default
for (n = 0; n < classes; ++n) {
delta[index + stride*n] = ((n == class_id) ? (1 - label_smooth_eps) : (0 + label_smooth_eps/classes)) - output[index + stride*n];
if (label_smooth_eps > 0) {
float out_val = output[index + stride*class_id] * (1 - label_smooth_eps) + 0.5*label_smooth_eps;
delta[index + stride*n] = ((n == class_id) ? 1 : 0) - out_val;
}
else {
delta[index + stride*n] = ((n == class_id) ? 1 : 0) - output[index + stride*n];
}
if (classes_multipliers && n == class_id) delta[index + stride*class_id] *= classes_multipliers[class_id];
if (n == class_id && avg_cat) *avg_cat += output[index + stride*n];
}
Expand Down

0 comments on commit 81290b0

Please sign in to comment.