| 844 | } |
| 845 | |
| 846 | void test_clipped_relu() |
| 847 | { |
| 848 | IF_DLIB_USE_CUDA( |
| 849 | using namespace dlib::tt; |
| 850 | print_spinner(); |
| 851 | const long n = 4; |
| 852 | const long k = 5; |
| 853 | const long nr = 3; |
| 854 | const long nc = 3; |
| 855 | const float ceiling = 6.0f; |
| 856 | resizable_tensor src(n, k, nr, nc); |
| 857 | tt::tensor_rand rnd; |
| 858 | rnd.fill_gaussian(src, 0, 3); |
| 859 | resizable_tensor dest_cuda, dest_cpu; |
| 860 | dest_cuda.copy_size(src); |
| 861 | dest_cpu.copy_size(src); |
| 862 | // initialize to different values in order to make sure the output is actually changed |
| 863 | dest_cuda = 1; |
| 864 | dest_cpu = 2; |
| 865 | cuda::clipped_relu(dest_cuda, src, ceiling); |
| 866 | cpu::clipped_relu(dest_cpu, src, ceiling); |
| 867 | auto error = max(abs(mat(dest_cuda) - mat(dest_cpu))); |
| 868 | DLIB_TEST_MSG(error < 1e-7, "error: " << error); |
| 869 | |
| 870 | // test gradients |
| 871 | resizable_tensor grad_cuda, grad_cpu, grad_input; |
| 872 | grad_cuda.copy_size(src); |
| 873 | grad_cpu.copy_size(src); |
| 874 | grad_input.copy_size(src); |
| 875 | rnd.fill_uniform(grad_input); |
| 876 | grad_cuda = 0; |
| 877 | grad_cpu = 0; |
| 878 | cuda::clipped_relu_gradient(grad_cuda, dest_cuda, grad_input, ceiling); |
| 879 | cpu::clipped_relu_gradient(grad_cpu, dest_cpu, grad_input, ceiling); |
| 880 | error = max(abs(mat(grad_cuda) - mat(grad_cpu))); |
| 881 | DLIB_TEST_MSG(error < 1e-7, "error: " << error); |
| 882 | ) |
| 883 | } |
| 884 | |
| 885 | void test_elu() |
| 886 | { |
no test coverage detected