From cb94ef9308995276f3e2de45d6c1b98e55c8bb06 Mon Sep 17 00:00:00 2001 From: AlexeyAB Date: Sat, 29 Dec 2018 21:52:31 +0300 Subject: [PATCH] Use `dont_show` in the obj.data file to disable detection for a specific class --- src/box.h | 4 ++-- src/image.c | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/box.h b/src/box.h index 6063a480..6f5e7383 100644 --- a/src/box.h +++ b/src/box.h @@ -3,7 +3,7 @@ #ifdef YOLODLL_EXPORTS #if defined(_MSC_VER) -#define YOLODLL_API __declspec(dllexport) +#define YOLODLL_API __declspec(dllexport) #else #define YOLODLL_API __attribute__((visibility("default"))) #endif @@ -52,6 +52,6 @@ box encode_box(box b, box anchor); // Creates array of detections with prob > thresh and fills best_class for them // Return number of selected detections in *selected_detections_num -detection_with_class* get_actual_detections(detection *dets, int dets_num, float thresh, int* selected_detections_num); +detection_with_class* get_actual_detections(detection *dets, int dets_num, float thresh, int* selected_detections_num, char **names); #endif diff --git a/src/image.c b/src/image.c index 6212406a..cb96ef37 100644 --- a/src/image.c +++ b/src/image.c @@ -269,7 +269,7 @@ image **load_alphabet() // Creates array of detections with prob > thresh and fills best_class for them -detection_with_class* get_actual_detections(detection *dets, int dets_num, float thresh, int* selected_detections_num) +detection_with_class* get_actual_detections(detection *dets, int dets_num, float thresh, int* selected_detections_num, char **names) { int selected_num = 0; detection_with_class* result_arr = calloc(dets_num, sizeof(detection_with_class)); @@ -279,7 +279,8 @@ detection_with_class* get_actual_detections(detection *dets, int dets_num, float float best_class_prob = thresh; int j; for (j = 0; j < dets[i].classes; ++j) { - if (dets[i].prob[j] > best_class_prob ) { + int show = strncmp(names[j], "dont_show", 9); + if (dets[i].prob[j] > best_class_prob && show) { best_class = j; best_class_prob = dets[i].prob[j]; } @@ -314,7 +315,7 @@ int compare_by_probs(const void *a_ptr, const void *b_ptr) { void draw_detections_v3(image im, detection *dets, int num, float thresh, char **names, image **alphabet, int classes, int ext_output) { int selected_detections_num; - detection_with_class* selected_detections = get_actual_detections(dets, num, thresh, &selected_detections_num); + detection_with_class* selected_detections = get_actual_detections(dets, num, thresh, &selected_detections_num, names); // text output qsort(selected_detections, selected_detections_num, sizeof(*selected_detections), compare_by_lefts); @@ -489,7 +490,8 @@ void draw_detections_cv_v3(IplImage* show_img, detection *dets, int num, float t char labelstr[4096] = { 0 }; int class_id = -1; for (j = 0; j < classes; ++j) { - if (dets[i].prob[j] > thresh) { + int show = strncmp(names[j], "dont_show", 9); + if (dets[i].prob[j] > thresh && show) { if (class_id < 0) { strcat(labelstr, names[j]); class_id = j;