From 7f53d7feb671d5c2da4a39bba613e14b02fb951d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Arrufat?= <1671644+arrufat@users.noreply.github.com> Date: Tue, 13 Apr 2021 10:49:49 +0900 Subject: [PATCH] Make clipped-relu inplace and fix docs for elu (#2345) --- dlib/dnn/layers.h | 17 ++++++----------- dlib/dnn/layers_abstract.h | 4 ++-- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/dlib/dnn/layers.h b/dlib/dnn/layers.h index 12e0e3afe..06216e7e8 100644 --- a/dlib/dnn/layers.h +++ b/dlib/dnn/layers.h @@ -3479,24 +3479,19 @@ namespace dlib { } - template - void forward( - SUBNET& sub, - resizable_tensor& data_output - ) + void forward_inplace(const tensor& input, tensor& output) { - data_output.copy_size(sub.get_output()); - tt::clipped_relu(data_output, sub.get_output(), ceiling); + tt::clipped_relu(output, input, ceiling); } - template - void backward( + void backward_inplace( + const tensor& computed_output, const tensor& gradient_input, - SUBNET& sub, + tensor& data_grad, tensor& ) { - tt::clipped_relu_gradient(sub.get_gradient_input(), sub.get_output(), gradient_input, ceiling); + tt::clipped_relu_gradient(data_grad, computed_output, gradient_input, ceiling); } inline dpoint map_input_to_output (const dpoint& p) const { return p; } diff --git a/dlib/dnn/layers_abstract.h b/dlib/dnn/layers_abstract.h index 6f0a35caf..a4407b143 100644 --- a/dlib/dnn/layers_abstract.h +++ b/dlib/dnn/layers_abstract.h @@ -2537,8 +2537,8 @@ namespace dlib - returns the alpha parameter of the elu !*/ template void setup (const SUBNET& sub); - void forward_inplace(const tensor& input, tensor& output); - void backward_inplace(const tensor& computed_output, const tensor& gradient_input, tensor& data_grad, tensor& params_grad); + template void forward(const SUBNET& sub, resizable_tensor& data_output); + template void backward(const tensor& gradient_input, SUBNET& sub, tensor&); dpoint map_input_to_output(dpoint p) const; dpoint map_output_to_input(dpoint p) const; const tensor& get_layer_params() const;