Visualizing outputs from intermediate layers

Visualizing the outputs from intermediate layers will help us understand how the input image is being transformed across different layers. Often, the output from each layer is called an activation. To do this, we should extract the output from intermediate layers, which can be done in different ways. PyTorch provides a method called register_forward_hook, which allows us to pass a function that can extract the outputs of a particular layer.

By default, PyTorch models only store the output of the last layer so that they use memory optimally. So, before we inspect what the activations from the intermediate layers look like, let's learn how to extract outputs from the model. Take a look at the following ...

Get Deep Learning with PyTorch 1.x now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.