| 3813 | template <typename SUBNET> using concat_incept = inception3<concat_block1,concat_block2,concat_block3,SUBNET>; |
| 3814 | |
| 3815 | void test_concat() |
| 3816 | { |
| 3817 | using namespace dlib::tt; |
| 3818 | print_spinner(); |
| 3819 | |
| 3820 | using net_type = concat_incept<input<matrix<float>>>; |
| 3821 | |
| 3822 | resizable_tensor data(10, 1, 111, 222); |
| 3823 | tt::tensor_rand rnd; |
| 3824 | rnd.fill_gaussian(data); |
| 3825 | |
| 3826 | net_type net; |
| 3827 | |
| 3828 | |
| 3829 | auto& out = net.forward(data); |
| 3830 | |
| 3831 | auto& b1o = layer<itag1>(net).get_output(); |
| 3832 | auto& b2o = layer<itag2>(net).get_output(); |
| 3833 | auto& b3o = layer<itag3>(net).get_output(); |
| 3834 | |
| 3835 | resizable_tensor dest(10, 14, 111, 222); |
| 3836 | copy_tensor(false, dest, 0, b1o, 0, b1o.k()); |
| 3837 | copy_tensor(false, dest, b1o.k(), b2o, 0, b2o.k()); |
| 3838 | copy_tensor(false, dest, b1o.k() + b2o.k(), b3o, 0, b3o.k()); |
| 3839 | |
| 3840 | DLIB_TEST(dest.size() == out.size()); |
| 3841 | int error = memcmp(dest.host(), out.host(), dest.size()); |
| 3842 | DLIB_TEST(error == 0); |
| 3843 | |
| 3844 | resizable_tensor gr(10, 14, 111, 222); |
| 3845 | rnd.fill_gaussian(gr); |
| 3846 | |
| 3847 | resizable_tensor params; |
| 3848 | net.layer_details().backward(gr, net, params); |
| 3849 | |
| 3850 | auto& b1g = layer<itag1>(net).subnet().get_gradient_input(); |
| 3851 | auto& b2g = layer<itag2>(net).subnet().get_gradient_input(); |
| 3852 | auto& b3g = layer<itag3>(net).subnet().get_gradient_input(); |
| 3853 | |
| 3854 | resizable_tensor g1(10, 5, 111, 222); |
| 3855 | resizable_tensor g2(10, 8, 111, 222); |
| 3856 | resizable_tensor g3(10, 1, 111, 222); |
| 3857 | |
| 3858 | copy_tensor(false, g1, 0, gr, 0, g1.k()); |
| 3859 | copy_tensor(false, g2, 0, gr, g1.k(), g2.k()); |
| 3860 | copy_tensor(false, g3, 0, gr, g1.k() + g2.k(), g3.k()); |
| 3861 | DLIB_TEST(g1.size() == b1g.size()); |
| 3862 | error = memcmp(g1.host(), b1g.host(), b1g.size()); |
| 3863 | DLIB_TEST(error == 0); |
| 3864 | DLIB_TEST(g2.size() == b2g.size()); |
| 3865 | error = memcmp(g2.host(), b2g.host(), b2g.size()); |
| 3866 | DLIB_TEST(error == 0); |
| 3867 | DLIB_TEST(g3.size() == b3g.size()); |
| 3868 | error = memcmp(g3.host(), b3g.host(), b3g.size()); |
| 3869 | DLIB_TEST(error == 0); |
| 3870 | } |
| 3871 | |
| 3872 | // ---------------------------------------------------------------------------------------- |
no test coverage detected