| 312 | } |
| 313 | |
| 314 | inline const simple_test_results test_simple_object_detector ( |
| 315 | const std::string& dataset_filename, |
| 316 | const std::string& detector_filename, |
| 317 | const int upsample_amount |
| 318 | ) |
| 319 | { |
| 320 | |
| 321 | // Load all the testing images |
| 322 | dlib::array<array2d<rgb_pixel> > images; |
| 323 | std::vector<std::vector<rectangle> > boxes, ignore; |
| 324 | ignore = load_image_dataset(images, boxes, dataset_filename); |
| 325 | |
| 326 | // Load the detector off disk (We have to use the explicit serialization here |
| 327 | // so that we have an open file stream) |
| 328 | simple_object_detector detector; |
| 329 | std::ifstream fin(detector_filename.c_str(), std::ios::binary); |
| 330 | if (!fin) |
| 331 | throw error("Unable to open file " + detector_filename); |
| 332 | deserialize(detector, fin); |
| 333 | |
| 334 | |
| 335 | /* Here we need a little hack to deal with whether we are going to be loading a |
| 336 | * simple_object_detector (possibly trained outside of Python) or a |
| 337 | * simple_object_detector_py (definitely trained from Python). In order to do this |
| 338 | * we peek into the filestream to see if there is more data after the object |
| 339 | * detector. If there is, it will be the version and upsampling amount. Therefore, |
| 340 | * by default we set the upsampling amount to -1 so that we can catch when no |
| 341 | * upsampling amount has been passed (numbers less than 0). If -1 is passed, we |
| 342 | * assume no upsampling and use 0. If a number > 0 is passed, we use that, else we |
| 343 | * use the upsampling amount saved in the detector file (if it exists). |
| 344 | */ |
| 345 | unsigned int final_upsampling_amount = 0; |
| 346 | if (fin.peek() != EOF) |
| 347 | { |
| 348 | int version = 0; |
| 349 | deserialize(version, fin); |
| 350 | if (version != 1) |
| 351 | throw error("Unknown simple_object_detector format."); |
| 352 | deserialize(final_upsampling_amount, fin); |
| 353 | } |
| 354 | if (upsample_amount >= 0) |
| 355 | final_upsampling_amount = upsample_amount; |
| 356 | |
| 357 | return test_simple_object_detector_with_images(images, final_upsampling_amount, boxes, ignore, detector); |
| 358 | } |
| 359 | |
| 360 | // ---------------------------------------------------------------------------------------- |
| 361 |
nothing calls this directly
no test coverage detected