Hey in CNN visualisation toolkit : https://github.com/utkuozbulak/pytorch-cnn-visualizations/blob/master/src/cnn_layer_visualization.py 67 I am unable to understand :
def hook_layer(self):
        def hook_function(module, grad_in, grad_out):
            # Gets the conv output of the selected filter (from selected layer)
            self.conv_output = grad_out[0, self.selected_filter]

        # Hook the selected layer
        self.model[self.selected_layer].register_forward_hook(hook_function)

What are the hooks functions and ‘grad_out’ doing? Grad_out has been not defined anywhere yet the code works fine. Also later this is called as :
def visualise_layer_with_hooks(self):
        # Hook the selected layer
        self.hook_layer()

without any arguments passed for grad_in or out. What is this line doing and how?