[activation] Derivative for activation
authorParichay Kapoor <pk.kapoor@samsung.com>
Wed, 24 Jun 2020 05:56:59 +0000 (14:56 +0900)
committerJijoong Moon <jijoong.moon@samsung.com>
Wed, 24 Jun 2020 10:51:21 +0000 (19:51 +0900)
The derivative of softmax has been hand crafted to be different from others
Refer to https://github.com/nnstreamer/nntrainer/blob/2a650512813db6ce3bba828b5790066fbc655f14/nntrainer/src/fc_layer.cpp#L265 for original implementation
Softmax requires softmax(x) as input for derivative while other activations require x as input for derivative_

Signed-off-by: Parichay Kapoor <pk.kapoor@samsung.com>
nntrainer/src/activation_layer.cpp

index e8fa9ef..8f460d5 100644 (file)
@@ -58,7 +58,10 @@ Tensor ActivationLayer::forwarding(Tensor in, int &status) {
 }
 
 Tensor ActivationLayer::backwarding(Tensor derivative, int iteration) {
-  return derivative.multiply(_act_prime_fn(hidden));
+  if (activation_type == ActiType::ACT_SOFTMAX)
+    return derivative.multiply(_act_prime_fn(hidden));
+  else
+    return derivative.multiply(_act_prime_fn(input));
 }
 
 /**