diounms_sort() fixed

pull/4364/head
AlexeyAB 6 years ago
parent 14212154d9
commit 8cb3ee4e79
  1. 5
      include/darknet.h
  2. 32
      src/box.c
  3. 3
      src/gaussian_yolo_layer.c
  4. 1
      src/parser.c

@ -112,12 +112,12 @@ typedef enum {
// parser.h
typedef enum {
DEFAULT_NMS, GREEDY_NMS, DIOU_NMS
DEFAULT_NMS, GREEDY_NMS, DIOU_NMS, CORNERS_NMS
} NMS_KIND;
// parser.h
typedef enum {
YOLO_CENTER, YOLO_LEFT_TOP, YOLO_RIGHT_BOTTOM
YOLO_CENTER = 1 << 0, YOLO_LEFT_TOP = 1 << 1, YOLO_RIGHT_BOTTOM = 1 << 2
} YOLO_POINT;
@ -748,6 +748,7 @@ typedef struct detection{
float objectness;
int sort_class;
float *uc; // Gaussian_YOLOv3 - tx,ty,tw,th uncertainty
int points; // bit-0 - center, bit-1 - top-left-corner, bit-2 - bottom-right-corner
} detection;
// matrix.h

@ -871,13 +871,36 @@ void diounms_sort(detection *dets, int total, int classes, float thresh, NMS_KIN
for (i = 0; i < total; ++i) {
dets[i].sort_class = k;
}
qsort(dets, total, sizeof(detection), nms_comparator);
for (i = 0; i < total; ++i) {
qsort(dets, total, sizeof(detection), nms_comparator_v3);
for (i = 0; i < total; ++i)
{
if (dets[i].prob[k] == 0) continue;
box a = dets[i].bbox;
for (j = i + 1; j < total; ++j) {
box b = dets[j].bbox;
if (box_iou(a, b) > thresh && nms_kind == GREEDY_NMS) {
if (box_iou(a, b) > thresh && nms_kind == CORNERS_NMS)
{
float sum_prob = pow(dets[i].prob[k], 2) + pow(dets[j].prob[k], 2);
float alpha_prob = pow(dets[i].prob[k], 2) / sum_prob;
float beta_prob = pow(dets[j].prob[k], 2) / sum_prob;
//dets[i].bbox.x = (dets[i].bbox.x*alpha_prob + dets[j].bbox.x*beta_prob);
//dets[i].bbox.y = (dets[i].bbox.y*alpha_prob + dets[j].bbox.y*beta_prob);
//dets[i].bbox.w = (dets[i].bbox.w*alpha_prob + dets[j].bbox.w*beta_prob);
//dets[i].bbox.h = (dets[i].bbox.h*alpha_prob + dets[j].bbox.h*beta_prob);
/*
if (dets[j].points == YOLO_CENTER && (dets[i].points & dets[j].points) == 0) {
dets[i].bbox.x = (dets[i].bbox.x*alpha_prob + dets[j].bbox.x*beta_prob);
dets[i].bbox.y = (dets[i].bbox.y*alpha_prob + dets[j].bbox.y*beta_prob);
}
else if ((dets[i].points & dets[j].points) == 0) {
dets[i].bbox.w = (dets[i].bbox.w*alpha_prob + dets[j].bbox.w*beta_prob);
dets[i].bbox.h = (dets[i].bbox.h*alpha_prob + dets[j].bbox.h*beta_prob);
}
dets[i].points |= dets[j].points;
*/
dets[j].prob[k] = 0;
}
else if (box_iou(a, b) > thresh && nms_kind == GREEDY_NMS) {
dets[j].prob[k] = 0;
}
else {
@ -886,6 +909,9 @@ void diounms_sort(detection *dets, int total, int classes, float thresh, NMS_KIN
}
}
}
//if ((nms_kind == CORNERS_NMS) && (dets[i].points != (YOLO_CENTER | YOLO_LEFT_TOP | YOLO_RIGHT_BOTTOM)))
// dets[i].prob[k] = 0;
}
}
}

@ -742,6 +742,9 @@ int get_gaussian_yolo_detections(layer l, int w, int h, int netw, int neth, floa
dets[count].uc[2] = predictions[entry_gaussian_index(l, 0, n*l.w*l.h + i, 5)]; // tw uncertainty
dets[count].uc[3] = predictions[entry_gaussian_index(l, 0, n*l.w*l.h + i, 7)]; // th uncertainty
dets[count].points = l.yolo_point;
//if (l.yolo_point != YOLO_CENTER) dets[count].objectness = objectness = 0;
for (j = 0; j < l.classes; ++j) {
int class_index = entry_gaussian_index(l, 0, n*l.w*l.h + i, 9 + j);
float uc_aver = (dets[count].uc[0] + dets[count].uc[1] + dets[count].uc[2] + dets[count].uc[3]) / 4.0;

@ -474,6 +474,7 @@ layer parse_gaussian_yolo(list *options, size_params params) // Gaussian_YOLOv3
else {
if (strcmp(nms_kind, "greedynms") == 0) l.nms_kind = GREEDY_NMS;
else if (strcmp(nms_kind, "diounms") == 0) l.nms_kind = DIOU_NMS;
else if (strcmp(nms_kind, "cornersnms") == 0) l.nms_kind = CORNERS_NMS;
else l.nms_kind = DEFAULT_NMS;
printf("nms_kind: %s (%d), beta = %f \n", nms_kind, l.nms_kind, l.beta_nms);
}

Loading…
Cancel
Save