| 2688 | // ---------------------------------------------------------------------------------------- |
| 2689 | |
| 2690 | void test_max_pool( |
| 2691 | const int window_height, |
| 2692 | const int window_width, |
| 2693 | const int stride_y, |
| 2694 | const int stride_x, |
| 2695 | const int padding_y, |
| 2696 | const int padding_x |
| 2697 | ) |
| 2698 | { |
| 2699 | print_spinner(); |
| 2700 | resizable_tensor A, B, gradient_input; |
| 2701 | A.set_size(4,5,16,7); |
| 2702 | B.copy_size(A); |
| 2703 | gradient_input.copy_size(A); |
| 2704 | |
| 2705 | tt::tensor_rand rnd; |
| 2706 | rnd.fill_gaussian(A,0,1); |
| 2707 | rnd.fill_gaussian(B,0,1); |
| 2708 | rnd.fill_gaussian(gradient_input,0,1); |
| 2709 | |
| 2710 | |
| 2711 | tt::pooling mp; |
| 2712 | |
| 2713 | mp.setup_max_pooling(window_height,window_width,stride_y,stride_x,padding_y,padding_x); |
| 2714 | mp(A, B); |
| 2715 | |
| 2716 | // make sure max pooling does what it's spec says it should. |
| 2717 | DLIB_TEST( A.num_samples() == B.num_samples()); |
| 2718 | DLIB_TEST( A.k() == B.k()); |
| 2719 | |
| 2720 | DLIB_TEST( A.nr() == 1+(B.nr()+2*padding_y-window_height)/stride_y); |
| 2721 | DLIB_TEST( A.nc() == 1+(B.nc()+2*padding_x-window_width)/stride_x); |
| 2722 | |
| 2723 | const long x_offset = window_width/2 - padding_x; |
| 2724 | const long y_offset = window_height/2 - padding_y; |
| 2725 | for (long s = 0; s < A.num_samples(); ++s) |
| 2726 | { |
| 2727 | for (long k = 0; k < A.k(); ++k) |
| 2728 | { |
| 2729 | for (long r = 0; r < A.nr(); ++r) |
| 2730 | { |
| 2731 | for (long c = 0; c < A.nc(); ++c) |
| 2732 | { |
| 2733 | DLIB_TEST_MSG(image_plane(A,s,k)(r,c) == max(subm_clipped(image_plane(B,s,k), |
| 2734 | centered_rect(c*stride_x+x_offset, |
| 2735 | r*stride_y+y_offset, |
| 2736 | window_width, |
| 2737 | window_height))), |
| 2738 | "padding: "<< padding_x << " " << padding_y |
| 2739 | << " window size: " << window_width << " " << window_height |
| 2740 | << " stride: " << stride_x << " " << stride_y |
| 2741 | ); |
| 2742 | } |
| 2743 | } |
| 2744 | } |
| 2745 | } |
| 2746 | } |
| 2747 |
no test coverage detected