From 5f5c46f49e8544ccd64f571b945e43af3951b7a6 Mon Sep 17 00:00:00 2001 From: Davis King Date: Sat, 21 Nov 2015 10:42:39 -0500 Subject: [PATCH] Made loss layers output the gradients by assigning them to the output rather than adding them. This way, the gradient buffer can be used as scratch space during the loss computation. --- dlib/dnn/loss.h | 2 +- dlib/dnn/loss_abstract.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dlib/dnn/loss.h b/dlib/dnn/loss.h index 41a57ca08..dfac4371c 100644 --- a/dlib/dnn/loss.h +++ b/dlib/dnn/loss.h @@ -77,7 +77,7 @@ namespace dlib if (temp > 0) { loss += scale*temp; - g[i] += -scale*y; + g[i] = -scale*y; } } return loss; diff --git a/dlib/dnn/loss_abstract.h b/dlib/dnn/loss_abstract.h index 5ca90d627..e950efec3 100644 --- a/dlib/dnn/loss_abstract.h +++ b/dlib/dnn/loss_abstract.h @@ -110,9 +110,9 @@ namespace dlib of sub matches the expected labels given by truth. Let's write the loss function as L(input_tensor, truth, sub). - Then compute_loss() computes the gradient of L() with respect to the - outputs in sub. Specifically, compute_loss() adds the gradients into sub - by performing the following tensor additions, for all valid i: - - layer(sub).get_gradient_input() += the gradient of + outputs in sub. Specifically, compute_loss() assigns the gradients into + sub by performing the following tensor assignments, for all valid i: + - layer(sub).get_gradient_input() = the gradient of L(input_tensor,truth,sub) with respect to layer(sub).get_output(). - returns L(input_tensor,truth,sub) !*/