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

Function test_max_pool

dlib/test/dnn.cpp:2117–2173  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2115// ----------------------------------------------------------------------------------------
2116
2117 void test_max_pool(
2118 const int window_height,
2119 const int window_width,
2120 const int stride_y,
2121 const int stride_x,
2122 const int padding_y,
2123 const int padding_x
2124 )
2125 {
2126 print_spinner();
2127 resizable_tensor A, B, gradient_input;
2128 A.set_size(4,5,16,7);
2129 B.copy_size(A);
2130 gradient_input.copy_size(A);
2131
2132 tt::tensor_rand rnd;
2133 rnd.fill_gaussian(A,0,1);
2134 rnd.fill_gaussian(B,0,1);
2135 rnd.fill_gaussian(gradient_input,0,1);
2136
2137
2138 tt::pooling mp;
2139
2140 mp.setup_max_pooling(window_height,window_width,stride_y,stride_x,padding_y,padding_x);
2141 mp(A, B);
2142
2143 // make sure max pooling does what it's spec says it should.
2144 DLIB_TEST( A.num_samples() == B.num_samples());
2145 DLIB_TEST( A.k() == B.k());
2146
2147 DLIB_TEST( A.nr() == 1+(B.nr()+2*padding_y-window_height)/stride_y);
2148 DLIB_TEST( A.nc() == 1+(B.nc()+2*padding_x-window_width)/stride_x);
2149
2150 const long x_offset = window_width/2 - padding_x;
2151 const long y_offset = window_height/2 - padding_y;
2152 for (long s = 0; s < A.num_samples(); ++s)
2153 {
2154 for (long k = 0; k < A.k(); ++k)
2155 {
2156 for (long r = 0; r < A.nr(); ++r)
2157 {
2158 for (long c = 0; c < A.nc(); ++c)
2159 {
2160 DLIB_TEST_MSG(image_plane(A,s,k)(r,c) == max(subm_clipped(image_plane(B,s,k),
2161 centered_rect(c*stride_x+x_offset,
2162 r*stride_y+y_offset,
2163 window_width,
2164 window_height))),
2165 "padding: "<< padding_x << " " << padding_y
2166 << " window size: " << window_width << " " << window_height
2167 << " stride: " << stride_x << " " << stride_y
2168 );
2169 }
2170 }
2171 }
2172 }
2173 }
2174

Callers 1

run_testsMethod · 0.85

Calls 13

print_spinnerFunction · 0.85
mpFunction · 0.85
image_planeFunction · 0.85
subm_clippedFunction · 0.85
centered_rectFunction · 0.85
copy_sizeMethod · 0.80
setup_max_poolingMethod · 0.80
maxFunction · 0.50
set_sizeMethod · 0.45
num_samplesMethod · 0.45
kMethod · 0.45
nrMethod · 0.45

Tested by

no test coverage detected