22.02.2024 Views

Daniel Voigt Godoy - Deep Learning with PyTorch Step-by-Step A Beginner’s Guide-leanpub

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Weights as Pixels

During data preparation, we flattened the inputs from five-by-five images to 25-

element-long tensors. Here is a crazy idea: What if we take some other tensor with

25 elements in it and try to visualize it as an image?

We have some perfect candidates for this: The weights used by each unit in

Hidden Layer #0. Each unit uses 25 weights since each unit receives values from 25

features. We even have these weights in a variable already:

w_nn_hidden0.shape

Output

torch.Size([5, 25])

Five units, 25 weights each. Perfect! We only need to use view() to reshape the 25-

element-long tensors representing the weights into two-dimensional tensors

(5x5), and visualize them as if they were images:

Figure 4.10 - Weights as pixels

"What’s the point of doing that?"

Visualizing weights as images is commonplace when using convolutional neural

networks (CNNs). These images will be called filters, and trained models will likely

exhibit more recognizable characteristics in their filters. Since our model was

poorly trained, it’s no wonder the images above are not very informative.

Moreover, in our case, these are not quite "filters," since they have the same size as

the input image. In CNN-based models, real filters cover only part of the image.

We’ll get back to it in the next chapter.

Deep-ish Model | 311

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!