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

Function test_multm_prev

dlib/test/dnn.cpp:4009–4052  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4007// ----------------------------------------------------------------------------------------
4008
4009void test_multm_prev()
4010{
4011 print_spinner();
4012 using net_type = tag1<multm_prev6<skip5<tag6<transpose<tag5<input<matrix<float>>>>>>>>;
4013 net_type net;
4014
4015 dlib::rand rnd;
4016 const int nr = 3, nc = 4;
4017 const int n_samples = 3, k = 1;
4018 std::vector<matrix<float>> x(n_samples);
4019 matrix<float> xtmp(nr, nc);
4020 for (int ii = 0; ii < n_samples; ++ii) {
4021 for (int jj = 0; jj < nr; ++jj)
4022 for (int kk = 0; kk < nc; ++kk)
4023 xtmp(jj, kk) = rnd.get_random_gaussian();
4024 x[ii] = xtmp;
4025 }
4026
4027 resizable_tensor input_tensor;
4028 net.to_tensor(&x[0], &x[0] + n_samples, input_tensor);
4029 net.forward(input_tensor);
4030
4031 resizable_tensor expected_output(n_samples, k, nr, nr);
4032 matrix<float> input_mat(nr, nc);
4033 matrix<float> output_mat(nr, nr);
4034
4035 for (long s = 0; s < n_samples; ++s) {
4036 for (long r = 0; r < nr; ++r) {
4037 for (long c = 0; c < nc; ++c) {
4038 input_mat(r, c) = input_tensor.host()[tensor_index(input_tensor, s, 0, r, c)];
4039 }
4040 }
4041 output_mat = input_mat * trans(input_mat);
4042
4043 for (long r = 0; r < nr; ++r) {
4044 for (long c = 0; c < nr; ++c) {
4045 expected_output.host()[tensor_index(expected_output, s, 0, r, c)] = output_mat(r, c);
4046 }
4047 }
4048 }
4049
4050 auto& net_output = layer<tag1>(net).get_output();
4051 DLIB_TEST(max(abs(mat(net_output) - mat(expected_output))) < 1e-5);
4052}
4053
4054// ----------------------------------------------------------------------------------------
4055

Callers 1

run_testsMethod · 0.85

Calls 10

print_spinnerFunction · 0.85
tensor_indexFunction · 0.85
absFunction · 0.85
get_random_gaussianMethod · 0.80
transFunction · 0.50
maxFunction · 0.50
matFunction · 0.50
to_tensorMethod · 0.45
forwardMethod · 0.45
hostMethod · 0.45

Tested by

no test coverage detected