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

Function test_visit_functions

dlib/test/dnn.cpp:3247–3322  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3245 using pres = prelu<add_prev1<bn_con<con<8,3,3,1,1,prelu<bn_con<con<8,3,3,1,1,tag1<SUBNET>>>>>>>>;
3246
3247 void test_visit_functions()
3248 {
3249 using net_type2 = loss_multiclass_log<fc<10,
3250 avg_pool_everything<
3251 pres<res<res<res_down< // 2 prelu layers here
3252 tag4<repeat<9,pres, // 9 groups, each containing 2 prelu layers
3253 res_down<
3254 leaky_relu<res<
3255 input<matrix<unsigned char>>
3256 >>>>>>>>>>>>;
3257
3258 net_type2 pnet;
3259 const net_type2& const_pnet = pnet;
3260
3261 DLIB_TEST_MSG(pnet.num_layers == 132, pnet.num_layers);
3262 DLIB_TEST_MSG(pnet.num_computational_layers == 110, pnet.num_computational_layers);
3263
3264 {
3265 std::vector<bool> hit(pnet.num_computational_layers, false);
3266 size_t count = 0;
3267 visit_layer_parameter_gradients(pnet, [&](size_t i, tensor& ){hit[i] = true; ++count; });
3268 for (auto x : hit)
3269 DLIB_TEST(x);
3270 DLIB_TEST(count == pnet.num_computational_layers);
3271 }
3272 {
3273 std::vector<bool> hit(pnet.num_computational_layers, false);
3274 size_t count = 0;
3275 visit_layer_parameter_gradients(const_pnet, [&](size_t i, const tensor& ){hit[i] = true; ++count; });
3276 for (auto x : hit)
3277 DLIB_TEST(x);
3278 DLIB_TEST(count == pnet.num_computational_layers);
3279 }
3280
3281 {
3282 size_t count = 0;
3283 std::vector<bool> hit2(pnet.num_computational_layers, false);
3284 visit_layer_parameters(pnet, [&](size_t i, tensor& ){hit2[i] = true; ++count; });
3285 for (auto x : hit2)
3286 DLIB_TEST(x);
3287 DLIB_TEST(count == pnet.num_computational_layers);
3288 }
3289 {
3290 size_t count = 0;
3291 std::vector<bool> hit2(pnet.num_computational_layers, false);
3292 visit_layer_parameters(const_pnet, [&](size_t i, const tensor& ){hit2[i] = true; ++count; });
3293 for (auto x : hit2)
3294 DLIB_TEST(x);
3295 DLIB_TEST(count == pnet.num_computational_layers);
3296 }
3297
3298 int num_relus = 0;
3299 visit_computational_layers(pnet, [&num_relus](relu_&) { ++num_relus; });
3300 DLIB_TEST(num_relus == 10);
3301 num_relus = 0;
3302 visit_computational_layers(const_pnet, [&num_relus](const relu_&) { ++num_relus; });
3303 DLIB_TEST(num_relus == 10);
3304 num_relus = 0;

Callers 1

run_testsMethod · 0.85

Calls 6

count_parametersFunction · 0.85
visit_layer_parametersFunction · 0.50
leaky_relu_Class · 0.50
get_alphaMethod · 0.45

Tested by

no test coverage detected