MCPcopy Create free account
hub / github.com/davisking/dlib / main

Function main

examples/train_object_detector.cpp:171–419  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

169// ----------------------------------------------------------------------------------------
170
171int main(int argc, char** argv)
172{
173 try
174 {
175 command_line_parser parser;
176 parser.add_option("h","Display this help message.");
177 parser.add_option("t","Train an object detector and save the detector to disk.");
178 parser.add_option("cross-validate",
179 "Perform cross-validation on an image dataset and print the results.");
180 parser.add_option("test", "Test a trained detector on an image dataset and print the results.");
181 parser.add_option("u", "Upsample each input image <arg> times. Each upsampling quadruples the number of pixels in the image (default: 0).", 1);
182
183 parser.set_group_name("training/cross-validation sub-options");
184 parser.add_option("v","Be verbose.");
185 parser.add_option("folds","When doing cross-validation, do <arg> folds (default: 3).",1);
186 parser.add_option("c","Set the SVM C parameter to <arg> (default: 1.0).",1);
187 parser.add_option("threads", "Use <arg> threads for training (default: 4).",1);
188 parser.add_option("eps", "Set training epsilon to <arg> (default: 0.01).", 1);
189 parser.add_option("target-size", "Set size of the sliding window to about <arg> pixels in area (default: 80*80).", 1);
190 parser.add_option("flip", "Add left/right flipped copies of the images into the training dataset. Useful when the objects "
191 "you want to detect are left/right symmetric.");
192
193
194 parser.parse(argc, argv);
195
196 // Now we do a little command line validation. Each of the following functions
197 // checks something and throws an exception if the test fails.
198 const char* one_time_opts[] = {"h", "v", "t", "cross-validate", "c", "threads", "target-size",
199 "folds", "test", "eps", "u", "flip"};
200 parser.check_one_time_options(one_time_opts); // Can't give an option more than once
201 // Make sure the arguments to these options are within valid ranges if they are supplied by the user.
202 parser.check_option_arg_range("c", 1e-12, 1e12);
203 parser.check_option_arg_range("eps", 1e-5, 1e4);
204 parser.check_option_arg_range("threads", 1, 1000);
205 parser.check_option_arg_range("folds", 2, 100);
206 parser.check_option_arg_range("u", 0, 8);
207 parser.check_option_arg_range("target-size", 4*4, 10000*10000);
208 const char* incompatible[] = {"t", "cross-validate", "test"};
209 parser.check_incompatible_options(incompatible);
210 // You are only allowed to give these training_sub_ops if you also give either -t or --cross-validate.
211 const char* training_ops[] = {"t", "cross-validate"};
212 const char* training_sub_ops[] = {"v", "c", "threads", "target-size", "eps", "flip"};
213 parser.check_sub_options(training_ops, training_sub_ops);
214 parser.check_sub_option("cross-validate", "folds");
215
216
217 if (parser.option("h"))
218 {
219 cout << "Usage: train_object_detector [options] <image dataset file|image file>\n";
220 parser.print_options();
221
222 return EXIT_SUCCESS;
223 }
224
225
226 typedef scan_fhog_pyramid<pyramid_down<6> > image_scanner_type;
227 // Get the upsample option from the user but use 0 if it wasn't given.
228 const unsigned long upsample_amount = get_option(parser, "u", 0);

Callers

nothing calls this directly

Calls 15

get_optionFunction · 0.85
load_image_datasetFunction · 0.85
randomize_samplesFunction · 0.85
tolowerFunction · 0.85
right_substrFunction · 0.85
pyramid_upFunction · 0.85
rgb_pixelClass · 0.85
parseMethod · 0.80
print_optionsMethod · 0.80

Tested by

no test coverage detected