Use `dont_show` in the obj.data file to disable detection for a specific class

This commit is contained in:
AlexeyAB 2018-12-29 21:52:31 +03:00
parent 08f0f80b66
commit cb94ef9308
2 changed files with 8 additions and 6 deletions

View File

@ -3,7 +3,7 @@
#ifdef YOLODLL_EXPORTS #ifdef YOLODLL_EXPORTS
#if defined(_MSC_VER) #if defined(_MSC_VER)
#define YOLODLL_API __declspec(dllexport) #define YOLODLL_API __declspec(dllexport)
#else #else
#define YOLODLL_API __attribute__((visibility("default"))) #define YOLODLL_API __attribute__((visibility("default")))
#endif #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 // Creates array of detections with prob > thresh and fills best_class for them
// Return number of selected detections in *selected_detections_num // 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 #endif

View File

@ -269,7 +269,7 @@ image **load_alphabet()
// Creates array of detections with prob > thresh and fills best_class for them // 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; int selected_num = 0;
detection_with_class* result_arr = calloc(dets_num, sizeof(detection_with_class)); 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; float best_class_prob = thresh;
int j; int j;
for (j = 0; j < dets[i].classes; ++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 = j;
best_class_prob = dets[i].prob[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) 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; 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 // text output
qsort(selected_detections, selected_detections_num, sizeof(*selected_detections), compare_by_lefts); 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 }; char labelstr[4096] = { 0 };
int class_id = -1; int class_id = -1;
for (j = 0; j < classes; ++j) { 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) { if (class_id < 0) {
strcat(labelstr, names[j]); strcat(labelstr, names[j]);
class_id = j; class_id = j;