From 806c6372591fddc6604c2291bcee82f62bdfa01f Mon Sep 17 00:00:00 2001 From: Davis King Date: Mon, 26 Dec 2011 00:11:17 -0500 Subject: [PATCH] Made this trainer automatically determine decent parameters for the test_box_overlap object when it is used and the user hasn't specifically assigned an overlap tester. --- .../svm/structural_object_detection_trainer.h | 45 ++++++++++++++++++- ...ctural_object_detection_trainer_abstract.h | 21 +++++++++ 2 files changed, 64 insertions(+), 2 deletions(-) diff --git a/dlib/svm/structural_object_detection_trainer.h b/dlib/svm/structural_object_detection_trainer.h index ada4b2613..580e05bea 100644 --- a/dlib/svm/structural_object_detection_trainer.h +++ b/dlib/svm/structural_object_detection_trainer.h @@ -50,6 +50,14 @@ namespace dlib loss_per_false_alarm = 1; scanner.copy_configuration(scanner_); + + auto_overlap_tester = is_same_type::value; + } + + bool auto_set_overlap_tester ( + ) const + { + return auto_overlap_tester; } void set_overlap_tester ( @@ -57,11 +65,19 @@ namespace dlib ) { overlap_tester = tester; + auto_overlap_tester = false; } overlap_tester_type get_overlap_tester ( ) const { + // make sure requires clause is not broken + DLIB_ASSERT(auto_set_overlap_tester() == false, + "\t overlap_tester_type structural_object_detection_trainer::get_overlap_tester()" + << "\n\t You can't call this function if the overlap tester is generated dynamically." + << "\n\t this: " << this + ); + return overlap_tester; } @@ -235,8 +251,32 @@ namespace dlib << "\n\t is_learning_problem(images,truth_rects): " << is_learning_problem(images,truth_rects) ); + overlap_tester_type local_overlap_tester; + + if (auto_overlap_tester) + { + image_scanner_type local_scanner; + local_scanner.copy_configuration(scanner); + std::vector > mapped_rects(truth_rects.size()); + for (unsigned long i = 0; i < truth_rects.size(); ++i) + { + local_scanner.load(images[i]); + mapped_rects[i].resize(truth_rects[i].size()); + for (unsigned long j = 0; j < truth_rects[i].size(); ++j) + { + mapped_rects[i][j] = local_scanner.get_best_matching_rect(truth_rects[i][j]); + } + } + + local_overlap_tester = find_tight_overlap_tester(mapped_rects); + } + else + { + local_overlap_tester = overlap_tester; + } + structural_svm_object_detection_problem - svm_prob(scanner, overlap_tester, images, truth_rects, num_threads); + svm_prob(scanner, local_overlap_tester, images, truth_rects, num_threads); if (verbose) svm_prob.be_verbose(); @@ -253,7 +293,7 @@ namespace dlib solver(svm_prob,w); // report the results of the training. - return object_detector(scanner, overlap_tester, w); + return object_detector(scanner, local_overlap_tester, w); } @@ -271,6 +311,7 @@ namespace dlib unsigned long max_cache_size; double loss_per_missed_target; double loss_per_false_alarm; + bool auto_overlap_tester; }; diff --git a/dlib/svm/structural_object_detection_trainer_abstract.h b/dlib/svm/structural_object_detection_trainer_abstract.h index f9253d5d7..47969c39f 100644 --- a/dlib/svm/structural_object_detection_trainer_abstract.h +++ b/dlib/svm/structural_object_detection_trainer_abstract.h @@ -60,6 +60,24 @@ namespace dlib - #get_loss_per_false_alarm() == 1 - This object will attempt to learn a model for the given scanner object when train() is called. + - if (overlap_tester_type == test_box_overlap) then + - #auto_set_overlap_tester() == true + - else + - #auto_set_overlap_tester() == false + !*/ + + bool auto_set_overlap_tester ( + ) const; + /*! + ensures + - if (this object will automatically determine an appropriate + state for the overlap tester used for non-max suppression.) then + - returns true + - In this case, it is determined using the find_tight_overlap_tester() + routine based on the truth_rects given to the + structural_object_detection_trainer::train() method. + - else + - returns false !*/ void set_overlap_tester ( @@ -68,11 +86,14 @@ namespace dlib /*! ensures - #get_overlap_tester() == tester + - #auto_set_overlap_tester() == false !*/ overlap_tester_type get_overlap_tester ( ) const; /*! + requires + - auto_set_overlap_tester() == false ensures - returns the overlap tester object which will be used to perform non-max suppression. In particular, this function returns the overlap tester which will populate the