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

Function clipped_relu_gradient

dlib/cuda/cpu_dlib.cpp:2088–2116  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2086 }
2087
2088 void clipped_relu_gradient (
2089 tensor& grad,
2090 const tensor& dest,
2091 const tensor& gradient_input,
2092 const float ceiling
2093 )
2094 {
2095 const auto out = grad.host();
2096 const auto in = dest.host();
2097 const auto gi = gradient_input.host();
2098 if (is_same_object(grad, gradient_input))
2099 {
2100 for (size_t i = 0; i < dest.size(); ++i)
2101 {
2102 if (in[i] > 0 && in[i] < ceiling)
2103 out[i] = gi[i];
2104 else
2105 out[i] = 0;
2106 }
2107 }
2108 else
2109 {
2110 for (size_t i = 0; i < dest.size(); ++i)
2111 {
2112 if (in[i] > 0 && in[i] < ceiling)
2113 out[i] += gi[i];
2114 }
2115 }
2116 }
2117
2118 // ----------------------------------------------------------------------------------------
2119

Callers 2

test_clipped_reluFunction · 0.50
backward_inplaceMethod · 0.50

Calls 3

is_same_objectFunction · 0.50
hostMethod · 0.45
sizeMethod · 0.45

Tested by 1

test_clipped_reluFunction · 0.40