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

Function test_clipped_relu

dlib/test/dnn.cpp:846–883  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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 {

Callers 1

run_testsMethod · 0.85

Calls 7

print_spinnerFunction · 0.85
absFunction · 0.85
copy_sizeMethod · 0.80
clipped_reluFunction · 0.50
maxFunction · 0.50
matFunction · 0.50
clipped_relu_gradientFunction · 0.50

Tested by

no test coverage detected