| 152 | |
| 153 | template <typename image_array> |
| 154 | inline shape_predictor train_shape_predictor_on_images ( |
| 155 | image_array& images, |
| 156 | std::vector<std::vector<full_object_detection> >& detections, |
| 157 | const shape_predictor_training_options& options |
| 158 | ) |
| 159 | { |
| 160 | if (options.lambda_param <= 0) |
| 161 | throw error("Invalid lambda_param value given to train_shape_predictor(), lambda_param must be > 0."); |
| 162 | if (!(0 < options.nu && options.nu <= 1)) |
| 163 | throw error("Invalid nu value given to train_shape_predictor(). It is required that 0 < nu <= 1."); |
| 164 | if (options.feature_pool_region_padding <= -0.5) |
| 165 | throw error("Invalid feature_pool_region_padding value given to train_shape_predictor(), feature_pool_region_padding must be > -0.5."); |
| 166 | |
| 167 | if (images.size() != detections.size()) |
| 168 | throw error("The list of images must have the same length as the list of detections."); |
| 169 | |
| 170 | if (!impl::contains_any_detections(detections)) |
| 171 | throw error("Error, the training dataset does not have any labeled object detections in it."); |
| 172 | |
| 173 | shape_predictor_trainer trainer; |
| 174 | |
| 175 | trainer.set_cascade_depth(options.cascade_depth); |
| 176 | trainer.set_tree_depth(options.tree_depth); |
| 177 | trainer.set_num_trees_per_cascade_level(options.num_trees_per_cascade_level); |
| 178 | trainer.set_nu(options.nu); |
| 179 | trainer.set_random_seed(options.random_seed); |
| 180 | trainer.set_oversampling_amount(options.oversampling_amount); |
| 181 | trainer.set_oversampling_translation_jitter(options.oversampling_translation_jitter); |
| 182 | trainer.set_feature_pool_size(options.feature_pool_size); |
| 183 | trainer.set_feature_pool_region_padding(options.feature_pool_region_padding); |
| 184 | trainer.set_lambda(options.lambda_param); |
| 185 | trainer.set_num_test_splits(options.num_test_splits); |
| 186 | trainer.set_num_threads(options.num_threads); |
| 187 | if (options.landmark_relative_padding_mode) |
| 188 | trainer.set_padding_mode(shape_predictor_trainer::landmark_relative); |
| 189 | else |
| 190 | trainer.set_padding_mode(shape_predictor_trainer::bounding_box_relative); |
| 191 | |
| 192 | if (options.be_verbose) |
| 193 | { |
| 194 | std::cout << "Training with cascade depth: " << options.cascade_depth << std::endl; |
| 195 | std::cout << "Training with tree depth: " << options.tree_depth << std::endl; |
| 196 | std::cout << "Training with " << options.num_trees_per_cascade_level << " trees per cascade level."<< std::endl; |
| 197 | std::cout << "Training with nu: " << options.nu << std::endl; |
| 198 | std::cout << "Training with random seed: " << options.random_seed << std::endl; |
| 199 | std::cout << "Training with oversampling amount: " << options.oversampling_amount << std::endl; |
| 200 | std::cout << "Training with oversampling translation jitter: " << options.oversampling_translation_jitter << std::endl; |
| 201 | std::cout << "Training with landmark_relative_padding_mode: " << options.landmark_relative_padding_mode << std::endl; |
| 202 | std::cout << "Training with feature pool size: " << options.feature_pool_size << std::endl; |
| 203 | std::cout << "Training with feature pool region padding: " << options.feature_pool_region_padding << std::endl; |
| 204 | std::cout << "Training with " << options.num_threads << " threads." << std::endl; |
| 205 | std::cout << "Training with lambda_param: " << options.lambda_param << std::endl; |
| 206 | std::cout << "Training with " << options.num_test_splits << " split tests."<< std::endl; |
| 207 | trainer.be_verbose(); |
| 208 | } |
| 209 | |
| 210 | shape_predictor predictor = trainer.train(images, detections); |
| 211 |
no test coverage detected