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

Function prelu_gradient

dlib/cuda/cpu_dlib.cpp:1963–1990  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1961 }
1962
1963 void prelu_gradient (
1964 tensor& grad,
1965 const tensor& src,
1966 const tensor& gradient_input,
1967 const tensor& param,
1968 tensor& params_grad
1969 )
1970 {
1971 DLIB_CASSERT(is_same_object(grad, gradient_input) == false);
1972 const float p = param.host()[0];
1973 const float* gi = gradient_input.host();
1974 const float* s = src.host();
1975 float* out = grad.host();
1976 float pgrad = 0;
1977 for (size_t i = 0; i < src.size(); ++i)
1978 {
1979 if (s[i] > 0)
1980 {
1981 out[i] += gi[i];
1982 }
1983 else
1984 {
1985 out[i] += p*gi[i];
1986 pgrad += gi[i]*s[i];
1987 }
1988 }
1989 params_grad.host()[0] = pgrad;
1990 }
1991
1992 // ------------------------------------------------------------------------------------
1993

Callers 1

backwardMethod · 0.50

Calls 3

is_same_objectFunction · 0.50
hostMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected