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 folded hierarchy of classifiers.
24
25 */
26
27 #ifndef DETECTOR_H
28 #define DETECTOR_H
29
30 #include "storable.h"
31 #include "boosted_classifier.h"
32 #include "labelled_image_pool.h"
33 #include "parsing_pool.h"
34 #include "pose_cell_scored_set.h"
35
36 class Detector : public Storable {
37 public:
38   PoseCellHierarchy *_hierarchy;
39   int _nb_levels, _nb_classifiers_per_level, _nb_classifiers;
40   scalar_t *_thresholds;
41   Classifier **_classifiers;
42   PiFeatureFamily **_pi_feature_families;
43
44   void free();
45
46   virtual void train_classifier(int level,
47                                 LossMachine *loss_machine,
48                                 ParsingPool *parsing,
49                                 PiFeatureFamily *pi_feature_family,
50                                 Classifier *classifier);
51
52   virtual void parse_rec(RichImage *image, int level,
53                          PoseCell *cell, scalar_t response,
54                          PoseCellScoredSet *result);
55
56 public:
57
58   Detector();
59   virtual ~Detector();
60
61   inline int nb_levels() { return _nb_levels; }
62
63   // The validation set is only used to save ROCs curves during
64   // training for monitoring the learning
65
66   virtual void train(LabelledImagePool *train_pool,
67                      LabelledImagePool *validation_pool,
68                      LabelledImagePool *hierarchy_pool);
69
70   virtual void compute_thresholds(LabelledImagePool *validation_pool, scalar_t wanted_tp);
71
72   virtual void parse(RichImage *image, PoseCellScoredSet *result_cell_set);
73
74   virtual void read(istream *is);
75   virtual void write(ostream *os);
76 };
77
78 #endif