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

Function test_concat

dlib/test/dnn.cpp:3242–3297  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3240 template <typename SUBNET> using concat_incept = inception3<concat_block1,concat_block2,concat_block3,SUBNET>;
3241
3242 void test_concat()
3243 {
3244 using namespace dlib::tt;
3245 print_spinner();
3246
3247 using net_type = concat_incept<input<matrix<float>>>;
3248
3249 resizable_tensor data(10, 1, 111, 222);
3250 tt::tensor_rand rnd;
3251 rnd.fill_gaussian(data);
3252
3253 net_type net;
3254
3255
3256 auto& out = net.forward(data);
3257
3258 auto& b1o = layer<itag1>(net).get_output();
3259 auto& b2o = layer<itag2>(net).get_output();
3260 auto& b3o = layer<itag3>(net).get_output();
3261
3262 resizable_tensor dest(10, 14, 111, 222);
3263 copy_tensor(false, dest, 0, b1o, 0, b1o.k());
3264 copy_tensor(false, dest, b1o.k(), b2o, 0, b2o.k());
3265 copy_tensor(false, dest, b1o.k() + b2o.k(), b3o, 0, b3o.k());
3266
3267 DLIB_TEST(dest.size() == out.size());
3268 int error = memcmp(dest.host(), out.host(), dest.size());
3269 DLIB_TEST(error == 0);
3270
3271 resizable_tensor gr(10, 14, 111, 222);
3272 rnd.fill_gaussian(gr);
3273
3274 resizable_tensor params;
3275 net.layer_details().backward(gr, net, params);
3276
3277 auto& b1g = layer<itag1>(net).subnet().get_gradient_input();
3278 auto& b2g = layer<itag2>(net).subnet().get_gradient_input();
3279 auto& b3g = layer<itag3>(net).subnet().get_gradient_input();
3280
3281 resizable_tensor g1(10, 5, 111, 222);
3282 resizable_tensor g2(10, 8, 111, 222);
3283 resizable_tensor g3(10, 1, 111, 222);
3284
3285 copy_tensor(false, g1, 0, gr, 0, g1.k());
3286 copy_tensor(false, g2, 0, gr, g1.k(), g2.k());
3287 copy_tensor(false, g3, 0, gr, g1.k() + g2.k(), g3.k());
3288 DLIB_TEST(g1.size() == b1g.size());
3289 error = memcmp(g1.host(), b1g.host(), b1g.size());
3290 DLIB_TEST(error == 0);
3291 DLIB_TEST(g2.size() == b2g.size());
3292 error = memcmp(g2.host(), b2g.host(), b2g.size());
3293 DLIB_TEST(error == 0);
3294 DLIB_TEST(g3.size() == b3g.size());
3295 error = memcmp(g3.host(), b3g.host(), b3g.size());
3296 DLIB_TEST(error == 0);
3297 }
3298
3299// ----------------------------------------------------------------------------------------

Callers 1

run_testsMethod · 0.85

Calls 7

print_spinnerFunction · 0.85
copy_tensorFunction · 0.50
forwardMethod · 0.45
kMethod · 0.45
sizeMethod · 0.45
hostMethod · 0.45
backwardMethod · 0.45

Tested by

no test coverage detected