| 281 | |
| 282 | template <typename fe_type, typename F> |
| 283 | void test1(F make_data, bool force_assignment) |
| 284 | { |
| 285 | print_spinner(); |
| 286 | |
| 287 | std::vector<sample_type> samples; |
| 288 | std::vector<label_type> labels; |
| 289 | |
| 290 | make_data(samples, labels); |
| 291 | make_data(samples, labels); |
| 292 | make_data(samples, labels); |
| 293 | |
| 294 | randomize_samples(samples, labels); |
| 295 | |
| 296 | structural_assignment_trainer<fe_type> trainer; |
| 297 | |
| 298 | DLIB_TEST(trainer.forces_assignment() == false); |
| 299 | DLIB_TEST(trainer.get_c() == 100); |
| 300 | DLIB_TEST(trainer.get_num_threads() == 2); |
| 301 | DLIB_TEST(trainer.get_max_cache_size() == 5); |
| 302 | |
| 303 | |
| 304 | trainer.set_forces_assignment(force_assignment); |
| 305 | trainer.set_num_threads(3); |
| 306 | trainer.set_c(50); |
| 307 | |
| 308 | DLIB_TEST(trainer.get_c() == 50); |
| 309 | DLIB_TEST(trainer.get_num_threads() == 3); |
| 310 | DLIB_TEST(trainer.forces_assignment() == force_assignment); |
| 311 | |
| 312 | assignment_function<fe_type> ass = trainer.train(samples, labels); |
| 313 | |
| 314 | for (unsigned long i = 0; i < samples.size(); ++i) |
| 315 | { |
| 316 | std::vector<long> out = ass(samples[i]); |
| 317 | dlog << LINFO << "true labels: " << trans(mat(labels[i])); |
| 318 | dlog << LINFO << "pred labels: " << trans(mat(out)); |
| 319 | DLIB_TEST(trans(mat(labels[i])) == trans(mat(out))); |
| 320 | } |
| 321 | |
| 322 | double accuracy; |
| 323 | |
| 324 | dlog << LINFO << "samples.size(): "<< samples.size(); |
| 325 | accuracy = test_assignment_function(ass, samples, labels); |
| 326 | dlog << LINFO << "accuracy: "<< accuracy; |
| 327 | DLIB_TEST(accuracy == 1); |
| 328 | |
| 329 | accuracy = cross_validate_assignment_trainer(trainer, samples, labels, 3); |
| 330 | dlog << LINFO << "cv accuracy: "<< accuracy; |
| 331 | DLIB_TEST(accuracy == 1); |
| 332 | |
| 333 | ostringstream sout; |
| 334 | serialize(ass, sout); |
| 335 | istringstream sin(sout.str()); |
| 336 | assignment_function<fe_type> ass2; |
| 337 | deserialize(ass2, sin); |
| 338 | |
| 339 | DLIB_TEST(ass2.forces_assignment() == ass.forces_assignment()); |
| 340 | DLIB_TEST(length(ass2.get_weights() - ass.get_weights()) < 1e-10); |
nothing calls this directly
no test coverage detected