automatic commit
[folded-ctf.git] / global.cc
diff --git a/global.cc b/global.cc
new file mode 100644 (file)
index 0000000..253733c
--- /dev/null
+++ b/global.cc
@@ -0,0 +1,172 @@
+
+///////////////////////////////////////////////////////////////////////////
+// This program is free software: you can redistribute it and/or modify  //
+// it under the terms of the version 3 of the GNU General Public License //
+// as published by the Free Software Foundation.                         //
+//                                                                       //
+// This program is distributed in the hope that it will be useful, but   //
+// WITHOUT ANY WARRANTY; without even the implied warranty of            //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      //
+// General Public License for more details.                              //
+//                                                                       //
+// You should have received a copy of the GNU General Public License     //
+// along with this program. If not, see <http://www.gnu.org/licenses/>.  //
+//                                                                       //
+// Written by Francois Fleuret, (C) IDIAP                                //
+// Contact <francois.fleuret@idiap.ch> for comments & bug reports        //
+///////////////////////////////////////////////////////////////////////////
+
+#include <string.h>
+
+#include "global.h"
+
+Global global;
+
+Global::Global() {
+  log_stream = 0;
+}
+
+Global::~Global() {
+  delete log_stream;
+}
+
+void Global::init_parser(ParamParser *parser) {
+  // The nice level of the process
+  parser->add_association("niceness", "5", false);
+
+  // Seed to initialize the random generator
+  parser->add_association("random-seed", "0", false);
+
+  // Should the pictures be b&w
+  parser->add_association("pictures-for-article", "no", false);
+
+  // The name of the image pool to use
+  parser->add_association("pool-name", "", false);
+  // The name of the test image pool to use
+  parser->add_association("test-pool-name", "", false);
+  // From where to load or where to save the detector
+  parser->add_association("detector-name", "default.det", false);
+  // Where to put the generated files
+  parser->add_association("result-path", "/tmp/", false);
+
+  // What kind of loss for the boosting
+  parser->add_association("loss-type", "exponential", false);
+
+  // How many images to produce/process
+  parser->add_association("nb-images", "-1", false);
+
+  // What is the maximum tree depth
+  parser->add_association("tree-depth-max", "1", false);
+  // What is the proportion of negative cells we actually use during training
+  parser->add_association("proportion-negative-cells-for-training", "0.025", false);
+  // How many negative samples to sub-sample for boosting every classifier
+  parser->add_association("nb-negative-samples-per-positive", "10", false);
+  // How many features we will look at for boosting optimization
+  parser->add_association("nb-features-for-boosting-optimization", "10000", false);
+  // Do we allow head-belly registration
+  parser->add_association("force-head-belly-independence", "no", false);
+  // How many weak-learners in every classifier
+  parser->add_association("nb-weak-learners-per-classifier", "10", false);
+  // How many classifiers per level
+  parser->add_association("nb-classifiers-per-level", "25", false);
+  // How many levels
+  parser->add_association("nb-levels", "1", false);
+
+  // Proportion of images from the pool to use for training
+  parser->add_association("proportion-for-train", "0.5", false);
+  // Proportion of images from the pool to use for validation
+  parser->add_association("proportion-for-validation", "0.25", false);
+  // Proportion of images from the pool to use for test (negative
+  // means everything else)
+  parser->add_association("proportion-for-test", "0.25", false);
+  // During training, should we write the ROC curve estimated on the
+  // validation set (which cost a bit of computation)
+  parser->add_association("write-validation-rocs", "no", false);
+
+  // Should we write down the PNGs for the results of the parsing
+  parser->add_association("write-parse-images", "no", false);
+
+  // Should we write down the PNGs for the tags
+  parser->add_association("write-tag-images", "no", false);
+
+  // What is the wanted true overall positive rate
+  parser->add_association("wanted-true-positive-rate", "0.5", false);
+  // How many rates to try for the sequence of tests
+  parser->add_association("nb-wanted-true-positive-rates", "10", false);
+
+  // What is the minimum radius of the heads to detect. This is used
+  // as the reference size.
+  parser->add_association("min-head-radius", "25", false);
+  // What is the maximum size of the heads to detect.
+  parser->add_association("max-head-radius", "200", false);
+  // How many translation cell for one scale when generating the "top
+  // level" cells for an image.
+  parser->add_association("root-cell-nb-xy-per-scale", "5", false);
+
+  // What is the minimum size of the windows
+  parser->add_association("pi-feature-window-min-size", "0.1", false);
+
+  // How many scales between two powers of two for the multi-scale
+  // images
+  parser->add_association("nb-scales-per-power-of-two", "5", false);
+
+  // Should we display a progress bar for lengthy operations
+  parser->add_association("progress-bar", "yes", false);
+}
+
+void Global::read_parser(ParamParser *parser) {
+  niceness = parser->get_association_int("niceness");
+  random_seed = parser->get_association_int("random-seed");
+  pictures_for_article = parser->get_association_bool("pictures-for-article");
+
+  strncpy(pool_name, parser->get_association("pool-name"), buffer_size);
+  strncpy(test_pool_name, parser->get_association("test-pool-name"), buffer_size);
+  strncpy(detector_name, parser->get_association("detector-name"), buffer_size);
+  strncpy(result_path, parser->get_association("result-path"), buffer_size);
+
+  char buffer[buffer_size];
+  sprintf(buffer, "%s/log", result_path);
+  log_stream = new ofstream(buffer);
+
+  char *l = parser->get_association("loss-type");
+  if(strcmp(l, "exponential") == 0)
+    loss_type = LOSS_EXPONENTIAL;
+  else if(strcmp(l, "ev-regularized") == 0)
+    loss_type = LOSS_EV_REGULARIZED;
+  else if(strcmp(l, "hinge") == 0)
+    loss_type = LOSS_HINGE;
+  else if(strcmp(l, "logistic") == 0)
+    loss_type = LOSS_LOGISTIC;
+  else {
+    cerr << "Unknown loss type." << endl;
+    exit(1);
+  }
+
+  nb_images = parser->get_association_int("nb-images");
+  tree_depth_max = parser->get_association_int("tree-depth-max");
+  nb_weak_learners_per_classifier = parser->get_association_int("nb-weak-learners-per-classifier");
+  nb_classifiers_per_level = parser->get_association_int("nb-classifiers-per-level");
+  nb_levels = parser->get_association_int("nb-levels");
+  proportion_negative_cells_for_training = parser->get_association_scalar("proportion-negative-cells-for-training");
+  nb_negative_samples_per_positive = parser->get_association_int("nb-negative-samples-per-positive");
+  nb_features_for_boosting_optimization = parser->get_association_int("nb-features-for-boosting-optimization");
+  force_head_belly_independence = parser->get_association_bool("force-head-belly-independence");
+  proportion_for_train = parser->get_association_scalar("proportion-for-train");
+  proportion_for_validation = parser->get_association_scalar("proportion-for-validation");
+  proportion_for_test = parser->get_association_scalar("proportion-for-test");
+  write_validation_rocs = parser->get_association_bool("write-validation-rocs");
+  write_parse_images = parser->get_association_bool("write-parse-images");
+  write_tag_images = parser->get_association_bool("write-tag-images");
+  wanted_true_positive_rate = parser->get_association_scalar("wanted-true-positive-rate");
+  nb_wanted_true_positive_rates = parser->get_association_int("nb-wanted-true-positive-rates");
+
+  min_head_radius = parser->get_association_scalar("min-head-radius");
+  max_head_radius = parser->get_association_scalar("max-head-radius");
+  root_cell_nb_xy_per_scale = parser->get_association_int("root-cell-nb-xy-per-scale");
+
+  pi_feature_window_min_size = parser->get_association_scalar("pi-feature-window-min-size");
+
+  nb_scales_per_power_of_two = parser->get_association_int("nb-scales-per-power-of-two");
+
+  bar.set_visible(parser->get_association_bool("progress-bar"));
+}