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