From 5c2e84b056d04cf1815a67b760f4015adfec43fc Mon Sep 17 00:00:00 2001 From: K Pranit Abhinav Date: Mon, 31 Oct 2022 15:46:16 +0530 Subject: [PATCH] callback functions added --- ravdl/v2/NeuralNetwork.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/ravdl/v2/NeuralNetwork.py b/ravdl/v2/NeuralNetwork.py index 4148cd0..c909b17 100644 --- a/ravdl/v2/NeuralNetwork.py +++ b/ravdl/v2/NeuralNetwork.py @@ -112,17 +112,30 @@ def fit(self, X, y, n_epochs, batch_size, save_model = False): if save_model: self.save_model() - def _forward_pass(self, X, training=True): + def _forward_pass(self, X, training=True,return_all_layer_output=False): """ Calculate the output of the NN """ layer_output = X + all_layer_out={} for layer in self.layers: if layer == self.layers[0]: layer_output = layer._forward_pass(layer_output, input_layer="True", training = training) + if isinstance(layer_output, dict): + layer_output = layer_output['output'] + all_layer_out[layer.layer_name]=layer_output else: layer_output = layer._forward_pass(layer_output, training = training) + if isinstance(layer_output, dict): + layer_output = layer_output['output'] + all_layer_out[layer.layer_name]=layer_output + + if return_all_layer_output is True: + return all_layer_out return layer_output + + + def _backward_pass(self, loss_grad): """ Propagate the gradient 'backwards' and update the weights in each layer """ reversed_layers = list(reversed(self.layers))