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