pull/1466/head
AlexeyAB 7 years ago
parent c2a8cc2ad3
commit 552207d6f0
  1. 17
      src/data.c
  2. 12
      src/region_layer.c
  3. 12
      src/yolo_layer.c

@ -320,6 +320,7 @@ void fill_truth_detection(char *path, int num_boxes, float *truth, int classes,
if (count > num_boxes) count = num_boxes; if (count > num_boxes) count = num_boxes;
float x, y, w, h; float x, y, w, h;
int id; int id;
int sub = 0;
for (i = 0; i < count; ++i) { for (i = 0; i < count; ++i) {
x = boxes[i].x; x = boxes[i].x;
@ -337,23 +338,27 @@ void fill_truth_detection(char *path, int num_boxes, float *truth, int classes,
sprintf(buff, "echo %s \"Wrong annotation: class_id = %d. But class_id should be [from 0 to %d]\" >> bad_label.list", labelpath, id, classes); sprintf(buff, "echo %s \"Wrong annotation: class_id = %d. But class_id should be [from 0 to %d]\" >> bad_label.list", labelpath, id, classes);
system(buff); system(buff);
getchar(); getchar();
++sub;
continue; continue;
} }
if ((w < lowest_w || h < lowest_h)) { if ((w < lowest_w || h < lowest_h)) {
//sprintf(buff, "echo %s \"Very small object: w < lowest_w OR h < lowest_h\" >> bad_label.list", labelpath); //sprintf(buff, "echo %s \"Very small object: w < lowest_w OR h < lowest_h\" >> bad_label.list", labelpath);
//system(buff); //system(buff);
++sub;
continue; continue;
} }
if (x == 999999 || y == 999999) { if (x == 999999 || y == 999999) {
printf("\n Wrong annotation: x = 0, y = 0 \n"); printf("\n Wrong annotation: x = 0, y = 0 \n");
sprintf(buff, "echo %s \"Wrong annotation: x = 0 or y = 0\" >> bad_label.list", labelpath); sprintf(buff, "echo %s \"Wrong annotation: x = 0 or y = 0\" >> bad_label.list", labelpath);
system(buff); system(buff);
++sub;
continue; continue;
} }
if (x <= 0 || x > 1 || y <= 0 || y > 1) { if (x <= 0 || x > 1 || y <= 0 || y > 1) {
printf("\n Wrong annotation: x = %f, y = %f \n", x, y); printf("\n Wrong annotation: x = %f, y = %f \n", x, y);
sprintf(buff, "echo %s \"Wrong annotation: x = %f, y = %f\" >> bad_label.list", labelpath, x, y); sprintf(buff, "echo %s \"Wrong annotation: x = %f, y = %f\" >> bad_label.list", labelpath, x, y);
system(buff); system(buff);
++sub;
continue; continue;
} }
if (w > 1) { if (w > 1) {
@ -371,11 +376,11 @@ void fill_truth_detection(char *path, int num_boxes, float *truth, int classes,
if (x == 0) x += lowest_w; if (x == 0) x += lowest_w;
if (y == 0) y += lowest_h; if (y == 0) y += lowest_h;
truth[i*5+0] = x; truth[(i-sub)*5+0] = x;
truth[i*5+1] = y; truth[(i-sub)*5+1] = y;
truth[i*5+2] = w; truth[(i-sub)*5+2] = w;
truth[i*5+3] = h; truth[(i-sub)*5+3] = h;
truth[i*5+4] = id; truth[(i-sub)*5+4] = id;
} }
free(boxes); free(boxes);
} }
@ -784,7 +789,7 @@ data load_data_detection(int n, char **paths, int m, int w, int h, int c, int bo
image ai = image_data_augmentation(src, w, h, pleft, ptop, swidth, sheight, flip, jitter, dhue, dsat, dexp); image ai = image_data_augmentation(src, w, h, pleft, ptop, swidth, sheight, flip, jitter, dhue, dsat, dexp);
d.X.vals[i] = ai.data; d.X.vals[i] = ai.data;
//show_image(ai, "aug"); //show_image(ai, "aug");
//cvWaitKey(0); //cvWaitKey(0);

@ -127,17 +127,17 @@ void delta_region_class(float *output, float *delta, int index, int class_id, in
class_id = hier->parent[class_id]; class_id = hier->parent[class_id];
} }
*avg_cat += pred; *avg_cat += pred;
} else { } else {
// Focal loss // Focal loss
if (focal_loss) { if (focal_loss) {
// Focal Loss // Focal Loss
float alpha = 0.5; // 0.25 or 0.5 float alpha = 0.5; // 0.25 or 0.5
//float gamma = 2; // hardcoded in many places of the grad-formula //float gamma = 2; // hardcoded in many places of the grad-formula
int ti = index + class_id; int ti = index + class_id;
float pt = output[ti] + 0.000000000000001F; float pt = output[ti] + 0.000000000000001F;
// http://fooplot.com/#W3sidHlwZSI6MCwiZXEiOiItKDEteCkqKDIqeCpsb2coeCkreC0xKSIsImNvbG9yIjoiIzAwMDAwMCJ9LHsidHlwZSI6MTAwMH1d // http://fooplot.com/#W3sidHlwZSI6MCwiZXEiOiItKDEteCkqKDIqeCpsb2coeCkreC0xKSIsImNvbG9yIjoiIzAwMDAwMCJ9LHsidHlwZSI6MTAwMH1d
float grad = -(1 - pt) * (2 * pt*logf(pt) + pt - 1); // http://blog.csdn.net/linmingan/article/details/77885832 float grad = -(1 - pt) * (2 * pt*logf(pt) + pt - 1); // http://blog.csdn.net/linmingan/article/details/77885832
//float grad = (1 - pt) * (2 * pt*logf(pt) + pt - 1); // https://github.com/unsky/focal-loss //float grad = (1 - pt) * (2 * pt*logf(pt) + pt - 1); // https://github.com/unsky/focal-loss
for (n = 0; n < classes; ++n) { for (n = 0; n < classes; ++n) {
@ -224,7 +224,7 @@ void forward_region_layer(const region_layer l, network_state state)
int onlyclass_id = 0; int onlyclass_id = 0;
for(t = 0; t < l.max_boxes; ++t){ for(t = 0; t < l.max_boxes; ++t){
box truth = float_to_box(state.truth + t*5 + b*l.truths); box truth = float_to_box(state.truth + t*5 + b*l.truths);
if(!truth.x) break; if(!truth.x) break; // continue;
int class_id = state.truth[t*5 + b*l.truths + 4]; int class_id = state.truth[t*5 + b*l.truths + 4];
float maxp = 0; float maxp = 0;
int maxi = 0; int maxi = 0;
@ -258,7 +258,7 @@ void forward_region_layer(const region_layer l, network_state state)
box truth = float_to_box(state.truth + t*5 + b*l.truths); box truth = float_to_box(state.truth + t*5 + b*l.truths);
int class_id = state.truth[t * 5 + b*l.truths + 4]; int class_id = state.truth[t * 5 + b*l.truths + 4];
if (class_id >= l.classes) continue; // if label contains class_id more than number of classes in the cfg-file if (class_id >= l.classes) continue; // if label contains class_id more than number of classes in the cfg-file
if(!truth.x) break; if(!truth.x) break; // continue;
float iou = box_iou(pred, truth); float iou = box_iou(pred, truth);
if (iou > best_iou) { if (iou > best_iou) {
best_class_id = state.truth[t*5 + b*l.truths + 4]; best_class_id = state.truth[t*5 + b*l.truths + 4];
@ -302,7 +302,7 @@ void forward_region_layer(const region_layer l, network_state state)
continue; // if label contains class_id more than number of classes in the cfg-file continue; // if label contains class_id more than number of classes in the cfg-file
} }
if(!truth.x) break; if(!truth.x) break; // continue;
float best_iou = 0; float best_iou = 0;
int best_index = 0; int best_index = 0;
int best_n = 0; int best_n = 0;

@ -121,12 +121,12 @@ void delta_yolo_class(float *output, float *delta, int index, int class_id, int
if (focal_loss) { if (focal_loss) {
// Focal Loss // Focal Loss
float alpha = 0.5; // 0.25 or 0.5 float alpha = 0.5; // 0.25 or 0.5
//float gamma = 2; // hardcoded in many places of the grad-formula //float gamma = 2; // hardcoded in many places of the grad-formula
int ti = index + stride*class_id; int ti = index + stride*class_id;
float pt = output[ti] + 0.000000000000001F; float pt = output[ti] + 0.000000000000001F;
// http://fooplot.com/#W3sidHlwZSI6MCwiZXEiOiItKDEteCkqKDIqeCpsb2coeCkreC0xKSIsImNvbG9yIjoiIzAwMDAwMCJ9LHsidHlwZSI6MTAwMH1d // http://fooplot.com/#W3sidHlwZSI6MCwiZXEiOiItKDEteCkqKDIqeCpsb2coeCkreC0xKSIsImNvbG9yIjoiIzAwMDAwMCJ9LHsidHlwZSI6MTAwMH1d
float grad = -(1 - pt) * (2 * pt*logf(pt) + pt - 1); // http://blog.csdn.net/linmingan/article/details/77885832 float grad = -(1 - pt) * (2 * pt*logf(pt) + pt - 1); // http://blog.csdn.net/linmingan/article/details/77885832
//float grad = (1 - pt) * (2 * pt*logf(pt) + pt - 1); // https://github.com/unsky/focal-loss //float grad = (1 - pt) * (2 * pt*logf(pt) + pt - 1); // https://github.com/unsky/focal-loss
for (n = 0; n < classes; ++n) { for (n = 0; n < classes; ++n) {
@ -206,7 +206,7 @@ void forward_yolo_layer(const layer l, network_state state)
getchar(); getchar();
continue; // if label contains class_id more than number of classes in the cfg-file continue; // if label contains class_id more than number of classes in the cfg-file
} }
if(!truth.x) break; if(!truth.x) break; // continue;
float iou = box_iou(pred, truth); float iou = box_iou(pred, truth);
if (iou > best_iou) { if (iou > best_iou) {
best_iou = iou; best_iou = iou;
@ -237,7 +237,7 @@ void forward_yolo_layer(const layer l, network_state state)
int class_id = state.truth[t*(4 + 1) + b*l.truths + 4]; int class_id = state.truth[t*(4 + 1) + b*l.truths + 4];
if (class_id >= l.classes) continue; // if label contains class_id more than number of classes in the cfg-file if (class_id >= l.classes) continue; // if label contains class_id more than number of classes in the cfg-file
if(!truth.x) break; if(!truth.x) break; // continue;
float best_iou = 0; float best_iou = 0;
int best_n = 0; int best_n = 0;
i = (truth.x * l.w); i = (truth.x * l.w);
@ -307,8 +307,8 @@ void correct_yolo_boxes(detection *dets, int n, int w, int h, int netw, int neth
} }
for (i = 0; i < n; ++i){ for (i = 0; i < n; ++i){
box b = dets[i].bbox; box b = dets[i].bbox;
b.x = (b.x - (netw - new_w)/2./netw) / ((float)new_w/netw); b.x = (b.x - (netw - new_w)/2./netw) / ((float)new_w/netw);
b.y = (b.y - (neth - new_h)/2./neth) / ((float)new_h/neth); b.y = (b.y - (neth - new_h)/2./neth) / ((float)new_h/neth);
b.w *= (float)netw/new_w; b.w *= (float)netw/new_w;
b.h *= (float)neth/new_h; b.h *= (float)neth/new_h;
if(!relative){ if(!relative){

Loading…
Cancel
Save