Removed the definition of basename, which confuses an existing system one.
[folded-ctf.git] / detector.cc
index 358c66b..0bd651f 100644 (file)
@@ -1,20 +1,26 @@
-
-///////////////////////////////////////////////////////////////////////////
-// This program is free software: you can redistribute it and/or modify  //
-// it under the terms of the version 3 of the GNU General Public License //
-// as published by the Free Software Foundation.                         //
-//                                                                       //
-// This program is distributed in the hope that it will be useful, but   //
-// WITHOUT ANY WARRANTY; without even the implied warranty of            //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      //
-// General Public License for more details.                              //
-//                                                                       //
-// You should have received a copy of the GNU General Public License     //
-// along with this program. If not, see <http://www.gnu.org/licenses/>.  //
-//                                                                       //
-// Written by Francois Fleuret, (C) IDIAP                                //
-// Contact <francois.fleuret@idiap.ch> for comments & bug reports        //
-///////////////////////////////////////////////////////////////////////////
+/*
+ *  folded-ctf is an implementation of the folded hierarchy of
+ *  classifiers for object detection, developed by Francois Fleuret
+ *  and Donald Geman.
+ *
+ *  Copyright (c) 2008 Idiap Research Institute, http://www.idiap.ch/
+ *  Written by Francois Fleuret <francois.fleuret@idiap.ch>
+ *
+ *  This file is part of folded-ctf.
+ *
+ *  folded-ctf is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 3 as
+ *  published by the Free Software Foundation.
+ *
+ *  folded-ctf is distributed in the hope that it will be useful, but
+ *  WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with folded-ctf.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
 
 #include "tools.h"
 #include "detector.h"
@@ -72,15 +78,11 @@ void Detector::train_classifier(int level,
 
   scalar_t *responses = new scalar_t[nb_positives + nb_negatives_to_sample];
 
-  (*global.log_stream) << "Collecting the sampled training set." << endl;
-
   parsing_pool->weighted_sampling(loss_machine,
                                   &full_pi_feature_family,
                                   sample_set,
                                   responses);
 
-  (*global.log_stream) << "Training the classifier." << endl;
-
   (*global.log_stream) << "Initial train_loss "
                        << loss_machine->loss(sample_set, responses)
                        << endl;
@@ -167,8 +169,6 @@ void Detector::train(LabelledImagePool *train_pool,
     for(int c = 0; c < _nb_classifiers_per_level; c++) {
       int q = l * _nb_classifiers_per_level + c;
 
-      (*global.log_stream) << "Building classifier " << q << " (level " << l << ")" << endl;
-
       // Train the classifier
 
       train_classifier(l,
@@ -178,8 +178,6 @@ void Detector::train(LabelledImagePool *train_pool,
 
       // Update the cell responses on the training set
 
-      (*global.log_stream) << "Updating training cell responses." << endl;
-
       train_parsing->update_cell_responses(_pi_feature_families[q],
                                            _classifiers[q]);
 
@@ -197,8 +195,6 @@ void Detector::train(LabelledImagePool *train_pool,
 
         // Update the cell responses on the validation set
 
-        (*global.log_stream) << "Updating validation cell responses." << endl;
-
         validation_parsing->update_cell_responses(_pi_feature_families[q],
                                                   _classifiers[q]);
 
@@ -316,11 +312,6 @@ void Detector::compute_thresholds(LabelledImagePool *validation_pool, scalar_t w
     int wanted_nb_fn_at_this_classifier
       = int(nb_targets_total * (1 - wanted_tp_at_this_classifier));
 
-    (*global.log_stream) << "q = " << q
-                         << " wanted_tp_at_this_classifier = " << wanted_tp_at_this_classifier
-                         << " wanted_nb_fn_at_this_classifier = " << wanted_nb_fn_at_this_classifier
-                         << endl;
-
     indexed_fusion_sort(nb_targets_total, indexes, sorted_indexes,
                         responses + q * nb_targets_total);
 
@@ -338,35 +329,6 @@ void Detector::compute_thresholds(LabelledImagePool *validation_pool, scalar_t w
   delete[] still_detected;
   delete[] indexes;
   delete[] sorted_indexes;
-
-  { ////////////////////////////////////////////////////////////////////
-    // Sanity check
-
-    int nb_positives = 0;
-
-    for(int t = 0; t < nb_targets_total; t++) {
-      int positive = 1;
-      for(int q = 0; q < _nb_classifiers; q++) {
-        if(responses[t + nb_targets_total * q] < _thresholds[q]) positive = 0;
-      }
-      if(positive) nb_positives++;
-    }
-
-    scalar_t actual_tp = scalar_t(nb_positives) / scalar_t(nb_targets_total);
-
-    (*global.log_stream) << "Overall detection rate " << nb_positives << "/" << nb_targets_total
-                         << " "
-                         << "actual_tp = " << actual_tp
-                         << " "
-                         << "wanted_tp = " << wanted_tp
-                         << endl;
-
-    if(actual_tp < wanted_tp) {
-      cerr << "INCONSISTENCY" << endl;
-      abort();
-    }
-  } ////////////////////////////////////////////////////////////////////
-
   delete[] responses;
 }
 
@@ -453,10 +415,6 @@ void Detector::read(istream *is) {
   }
 
   _hierarchy = read_hierarchy(is);
-
-  (*global.log_stream) << "Read Detector" << endl
-                       << "  _nb_levels " << _nb_levels << endl
-                       << "  _nb_classifiers_per_level " << _nb_classifiers_per_level << endl;
 }
 
 void Detector::write(ostream *os) {