automatic commit
[folded-ctf.git] / global.cc
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 #include <string.h>
20
21 #include "global.h"
22
23 Global global;
24
25 Global::Global() {
26   log_stream = 0;
27 }
28
29 Global::~Global() {
30   delete log_stream;
31 }
32
33 void Global::init_parser(ParamParser *parser) {
34   // The nice level of the process
35   parser->add_association("niceness", "5", false);
36
37   // Seed to initialize the random generator
38   parser->add_association("random-seed", "0", false);
39
40   // Should the pictures be b&w
41   parser->add_association("pictures-for-article", "no", false);
42
43   // The name of the image pool to use
44   parser->add_association("pool-name", "", false);
45   // The name of the test image pool to use
46   parser->add_association("test-pool-name", "", false);
47   // From where to load or where to save the detector
48   parser->add_association("detector-name", "default.det", false);
49   // Where to put the generated files
50   parser->add_association("result-path", "/tmp/", false);
51
52   // What kind of loss for the boosting
53   parser->add_association("loss-type", "exponential", false);
54
55   // How many images to produce/process
56   parser->add_association("nb-images", "-1", false);
57
58   // What is the maximum tree depth
59   parser->add_association("tree-depth-max", "1", false);
60   // What is the proportion of negative cells we actually use during training
61   parser->add_association("proportion-negative-cells-for-training", "0.025", false);
62   // How many negative samples to sub-sample for boosting every classifier
63   parser->add_association("nb-negative-samples-per-positive", "10", false);
64   // How many features we will look at for boosting optimization
65   parser->add_association("nb-features-for-boosting-optimization", "10000", false);
66   // Do we allow head-belly registration
67   parser->add_association("force-head-belly-independence", "no", false);
68   // How many weak-learners in every classifier
69   parser->add_association("nb-weak-learners-per-classifier", "10", false);
70   // How many classifiers per level
71   parser->add_association("nb-classifiers-per-level", "25", false);
72   // How many levels
73   parser->add_association("nb-levels", "1", false);
74
75   // Proportion of images from the pool to use for training
76   parser->add_association("proportion-for-train", "0.5", false);
77   // Proportion of images from the pool to use for validation
78   parser->add_association("proportion-for-validation", "0.25", false);
79   // Proportion of images from the pool to use for test (negative
80   // means everything else)
81   parser->add_association("proportion-for-test", "0.25", false);
82   // During training, should we write the ROC curve estimated on the
83   // validation set (which cost a bit of computation)
84   parser->add_association("write-validation-rocs", "no", false);
85
86   // Should we write down the PNGs for the results of the parsing
87   parser->add_association("write-parse-images", "no", false);
88
89   // Should we write down the PNGs for the tags
90   parser->add_association("write-tag-images", "no", false);
91
92   // What is the wanted true overall positive rate
93   parser->add_association("wanted-true-positive-rate", "0.5", false);
94   // How many rates to try for the sequence of tests
95   parser->add_association("nb-wanted-true-positive-rates", "10", false);
96
97   // What is the minimum radius of the heads to detect. This is used
98   // as the reference size.
99   parser->add_association("min-head-radius", "25", false);
100   // What is the maximum size of the heads to detect.
101   parser->add_association("max-head-radius", "200", false);
102   // How many translation cell for one scale when generating the "top
103   // level" cells for an image.
104   parser->add_association("root-cell-nb-xy-per-radius", "5", false);
105
106   // What is the minimum size of the windows
107   parser->add_association("pi-feature-window-min-size", "0.1", false);
108
109   // How many scales between two powers of two for the multi-scale
110   // images
111   parser->add_association("nb-scales-per-power-of-two", "5", false);
112
113   // Should we display a progress bar for lengthy operations
114   parser->add_association("progress-bar", "yes", false);
115 }
116
117 void Global::read_parser(ParamParser *parser) {
118   niceness = parser->get_association_int("niceness");
119   random_seed = parser->get_association_int("random-seed");
120   pictures_for_article = parser->get_association_bool("pictures-for-article");
121
122   strncpy(pool_name, parser->get_association("pool-name"), buffer_size);
123   strncpy(test_pool_name, parser->get_association("test-pool-name"), buffer_size);
124   strncpy(detector_name, parser->get_association("detector-name"), buffer_size);
125   strncpy(result_path, parser->get_association("result-path"), buffer_size);
126
127   char buffer[buffer_size];
128   sprintf(buffer, "%s/log", result_path);
129   log_stream = new ofstream(buffer);
130
131   char *l = parser->get_association("loss-type");
132   if(strcmp(l, "exponential") == 0)
133     loss_type = LOSS_EXPONENTIAL;
134   else if(strcmp(l, "ev-regularized") == 0)
135     loss_type = LOSS_EV_REGULARIZED;
136   else if(strcmp(l, "hinge") == 0)
137     loss_type = LOSS_HINGE;
138   else if(strcmp(l, "logistic") == 0)
139     loss_type = LOSS_LOGISTIC;
140   else {
141     cerr << "Unknown loss type." << endl;
142     exit(1);
143   }
144
145   nb_images = parser->get_association_int("nb-images");
146   tree_depth_max = parser->get_association_int("tree-depth-max");
147   nb_weak_learners_per_classifier = parser->get_association_int("nb-weak-learners-per-classifier");
148   nb_classifiers_per_level = parser->get_association_int("nb-classifiers-per-level");
149   nb_levels = parser->get_association_int("nb-levels");
150   proportion_negative_cells_for_training = parser->get_association_scalar("proportion-negative-cells-for-training");
151   nb_negative_samples_per_positive = parser->get_association_int("nb-negative-samples-per-positive");
152   nb_features_for_boosting_optimization = parser->get_association_int("nb-features-for-boosting-optimization");
153   force_head_belly_independence = parser->get_association_bool("force-head-belly-independence");
154   proportion_for_train = parser->get_association_scalar("proportion-for-train");
155   proportion_for_validation = parser->get_association_scalar("proportion-for-validation");
156   proportion_for_test = parser->get_association_scalar("proportion-for-test");
157   write_validation_rocs = parser->get_association_bool("write-validation-rocs");
158   write_parse_images = parser->get_association_bool("write-parse-images");
159   write_tag_images = parser->get_association_bool("write-tag-images");
160   wanted_true_positive_rate = parser->get_association_scalar("wanted-true-positive-rate");
161   nb_wanted_true_positive_rates = parser->get_association_int("nb-wanted-true-positive-rates");
162
163   min_head_radius = parser->get_association_scalar("min-head-radius");
164   max_head_radius = parser->get_association_scalar("max-head-radius");
165   root_cell_nb_xy_per_radius = parser->get_association_int("root-cell-nb-xy-per-radius");
166
167   pi_feature_window_min_size = parser->get_association_scalar("pi-feature-window-min-size");
168
169   nb_scales_per_power_of_two = parser->get_association_int("nb-scales-per-power-of-two");
170
171   bar.set_visible(parser->get_association_bool("progress-bar"));
172 }