This test really just checks if the mmod loss goes negative when a whole lot of overlapping truth rectangles are given.
| 5592 | // This test really just checks if the mmod loss goes negative when a whole lot of overlapping |
| 5593 | // truth rectangles are given. |
| 5594 | void test_loss_mmod() |
| 5595 | { |
| 5596 | print_spinner(); |
| 5597 | |
| 5598 | // Define input image size. |
| 5599 | constexpr int nc = 20; |
| 5600 | constexpr int nr = 20; |
| 5601 | |
| 5602 | constexpr int margin = 3; |
| 5603 | |
| 5604 | // Create a checkerboard pattern. |
| 5605 | std::deque<point> labeled_points; |
| 5606 | for (int y = margin; y < nr - margin; ++y) |
| 5607 | for (int x = margin + 1 - y % 2; x < nc - margin; x += 2) |
| 5608 | labeled_points.emplace_back(x, y); |
| 5609 | |
| 5610 | // Create training data that follows the generated pattern. |
| 5611 | typedef matrix<float> input_image_type; |
| 5612 | |
| 5613 | const auto generate_input_image = [&labeled_points, nr, nc]() |
| 5614 | { |
| 5615 | input_image_type sample(nr, nc); |
| 5616 | sample = -1.0; |
| 5617 | |
| 5618 | for (const auto& point : labeled_points) |
| 5619 | sample(point.y(), point.x()) = 1.0; |
| 5620 | |
| 5621 | return sample; |
| 5622 | }; |
| 5623 | |
| 5624 | const auto generate_labels = [&labeled_points]() |
| 5625 | { |
| 5626 | const auto point_to_rect = [](const point& point) { |
| 5627 | constexpr int rect_size = 5; |
| 5628 | return centered_rect( |
| 5629 | point.x(), point.y(), |
| 5630 | rect_size, rect_size |
| 5631 | ); |
| 5632 | }; |
| 5633 | |
| 5634 | std::vector<mmod_rect> labels; |
| 5635 | |
| 5636 | std::transform( |
| 5637 | labeled_points.begin(), |
| 5638 | labeled_points.end(), |
| 5639 | std::back_inserter(labels), |
| 5640 | point_to_rect |
| 5641 | ); |
| 5642 | |
| 5643 | return labels; |
| 5644 | }; |
| 5645 | |
| 5646 | const input_image_type input_image = generate_input_image(); |
| 5647 | const std::vector<mmod_rect> labels = generate_labels(); |
| 5648 | |
| 5649 | mmod_options options(use_image_pyramid::no, { labels }); |
| 5650 | options.be_quiet = true; |
| 5651 |
no test coverage detected