| 5722 | } |
| 5723 | |
| 5724 | void test_input_tensor() |
| 5725 | { |
| 5726 | using namespace dlib::tt; |
| 5727 | print_spinner(); |
| 5728 | tt::tensor_rand rnd; |
| 5729 | std::vector<resizable_tensor> tensors(3); |
| 5730 | |
| 5731 | for (auto& t : tensors) { |
| 5732 | t.set_size(1, 3, 224, 224); |
| 5733 | rnd.fill_gaussian(t); |
| 5734 | } |
| 5735 | |
| 5736 | resizable_tensor out; |
| 5737 | input_tensor input_layer; |
| 5738 | |
| 5739 | input_layer.to_tensor(tensors.begin(), tensors.end(), out); |
| 5740 | |
| 5741 | DLIB_TEST(out.num_samples() == 3); |
| 5742 | DLIB_TEST(out.k() == 3); |
| 5743 | DLIB_TEST(out.nr() == 224); |
| 5744 | DLIB_TEST(out.nc() == 224); |
| 5745 | size_t stride = out.k() * out.nr() * out.nc(); |
| 5746 | size_t offset = 0; |
| 5747 | int error = 0; |
| 5748 | |
| 5749 | for (auto& t : tensors) { |
| 5750 | error = memcmp(out.host() + offset, t.host(), sizeof(float) * t.size()); |
| 5751 | DLIB_TEST(error == 0); |
| 5752 | offset += stride; |
| 5753 | } |
| 5754 | } |
| 5755 | |
| 5756 | // ---------------------------------------------------------------------------------------- |
| 5757 | |