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

Function test_fuse_layers

dlib/test/dnn.cpp:5676–5702  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5674// ----------------------------------------------------------------------------------------
5675
5676 void test_fuse_layers()
5677 {
5678 print_spinner();
5679 using net_type = fc<10, avg_pool_everything<relu<bn_con<con<16, 3, 3, 1, 1, input_rgb_image>>>>>;
5680 using net_type_fused = fc<10, avg_pool_everything<relu<affine<con<16, 3, 3, 1, 1, input_rgb_image>>>>>;
5681 net_type net_bias, net_nobias;
5682 disable_duplicative_biases(net_nobias);
5683 resizable_tensor x;
5684 matrix<rgb_pixel> image(8, 8);
5685 net_bias.to_tensor(&image, &image+1, x);
5686 net_nobias.to_tensor(&image, &image+1, x);
5687 net_bias.forward(x);
5688 net_nobias.forward(x);
5689 net_type_fused net_fused_bias(net_bias);
5690 net_type_fused net_fused_nobias(net_nobias);
5691 const resizable_tensor out_bias = net_bias.get_output();
5692 const resizable_tensor out_nobias = net_nobias.get_output();
5693 fuse_layers(net_fused_bias);
5694 fuse_layers(net_fused_nobias);
5695 net_fused_bias.forward(x);
5696 net_fused_nobias.forward(x);
5697 const resizable_tensor out_bias_fused = net_fused_bias.get_output();
5698 const resizable_tensor out_nobias_fused = net_fused_nobias.get_output();
5699
5700 DLIB_TEST(max(squared(mat(out_bias) - mat(out_bias_fused))) < 1e-10);
5701 DLIB_TEST(max(squared(mat(out_nobias) - mat(out_nobias_fused))) < 1e-10);
5702 }
5703
5704// ----------------------------------------------------------------------------------------
5705

Callers 1

run_testsMethod · 0.85

Calls 8

print_spinnerFunction · 0.85
fuse_layersFunction · 0.85
squaredFunction · 0.85
maxFunction · 0.50
matFunction · 0.50
to_tensorMethod · 0.45
forwardMethod · 0.45

Tested by

no test coverage detected