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.

The meow() method is totally independent of the Cat class. We do not even

need to create a cat! That’s what I meant by "called on an uninstantiated class

object."

Cat.meow()

Output

Meow

See? The meow() method could well be an independent function because it

works like one. But, in the context of a Cat class, it makes sense to have that

method attached to it since they belong together, conceptually speaking.

Most of the _visualize_tensors() method’s body consists of handling titles,

labels, and axes' ticks before using imshow() to actually plot the image, so it is not

that interesting. Let’s check its arguments:

• axs: an array of subplots, corresponding to one row of subplots as returned by

Matplotlib’s subplot

• x: a Numpy array containing at least as many images / filters as subplots in axs

• y: optional, a Numpy array containing at least as many labels as subplots in axs

• yhat: optional, a Numpy array containing at least as many predicted labels as

subplots in axs

• layer_name: label for the row of subplots

• title: title prefix for each subplot

We’ll call our static method from other (regular) methods to plot the images we’re

interested in. Let’s start with the filters.

Visualizing Filters

We can apply the same principle to the weights of the filter learned by our

convolutional layer. We can access the weights of any given layer using dot

notation:

Visualizing Filters and More! | 391

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

Saved successfully!

Ooh no, something went wrong!