automatic commit
[folded-ctf.git] / detector.h
1
2 ///////////////////////////////////////////////////////////////////////////
3 // This program is free software: you can redistribute it and/or modify  //
4 // it under the terms of the version 3 of the GNU General Public License //
5 // as published by the Free Software Foundation.                         //
6 //                                                                       //
7 // This program is distributed in the hope that it will be useful, but   //
8 // WITHOUT ANY WARRANTY; without even the implied warranty of            //
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      //
10 // General Public License for more details.                              //
11 //                                                                       //
12 // You should have received a copy of the GNU General Public License     //
13 // along with this program. If not, see <http://www.gnu.org/licenses/>.  //
14 //                                                                       //
15 // Written by Francois Fleuret                                           //
16 // (C) Idiap Research Institute                                          //
17 //                                                                       //
18 // Contact <francois.fleuret@idiap.ch> for comments & bug reports        //
19 ///////////////////////////////////////////////////////////////////////////
20
21 /*
22
23   This is the main class, a detector as a folded hierarchy of
24   classifiers.
25
26 */
27
28 #ifndef DETECTOR_H
29 #define DETECTOR_H
30
31 #include "storable.h"
32 #include "boosted_classifier.h"
33 #include "labelled_image_pool.h"
34 #include "parsing_pool.h"
35 #include "pose_cell_scored_set.h"
36
37 class Detector : public Storable {
38 public:
39   PoseCellHierarchy *_hierarchy;
40   int _nb_levels, _nb_classifiers_per_level, _nb_classifiers;
41   scalar_t *_thresholds;
42   Classifier **_classifiers;
43   PiFeatureFamily **_pi_feature_families;
44
45   void free();
46
47   virtual void train_classifier(int level,
48                                 LossMachine *loss_machine,
49                                 ParsingPool *parsing,
50                                 PiFeatureFamily *pi_feature_family,
51                                 Classifier *classifier);
52
53   virtual void parse_rec(RichImage *image, int level,
54                          PoseCell *cell, scalar_t response,
55                          PoseCellScoredSet *result);
56
57 public:
58
59   Detector();
60   virtual ~Detector();
61
62   inline int nb_levels() { return _nb_levels; }
63
64   // The validation set is only used to save ROCs curves during
65   // training for monitoring the learning
66
67   virtual void train(LabelledImagePool *train_pool,
68                      LabelledImagePool *validation_pool,
69                      LabelledImagePool *hierarchy_pool);
70
71   // Compute the thresholds at the various levels to reach the desired
72   // overall true positive rate
73
74   virtual void compute_thresholds(LabelledImagePool *validation_pool, scalar_t wanted_tp);
75
76   virtual void parse(RichImage *image, PoseCellScoredSet *result_cell_set);
77
78   virtual void read(istream *is);
79   virtual void write(ostream *os);
80 };
81
82 #endif