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