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