22.02.2024 Views

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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Output

[('', Sequential(

(conv1): Conv2d(1, 1, kernel_size=(3, 3), stride=(1, 1))

(relu1): ReLU()

(maxp1): MaxPool2d(kernel_size=2, stride=2, padding=0,

dilation=1, ceil_mode=False)

(flatten): Flatten()

(fc1): Linear(in_features=16, out_features=10, bias=True)

(relu2): ReLU()

(fc2): Linear(in_features=10, out_features=3, bias=True)

)),

('conv1', Conv2d(1, 1, kernel_size=(3, 3), stride=(1, 1))),

('relu1', ReLU()),

('maxp1',

MaxPool2d(kernel_size=2, stride=2, padding=0, dilation=1,

ceil_mode=False)),

('flatten', Flatten()),

('fc1', Linear(in_features=16, out_features=10, bias=True)),

('relu2', ReLU()),

('fc2', Linear(in_features=10, out_features=3, bias=True))]

The first, unnamed, module is the whole model itself. The other, named, modules

are its layers. Any of those layers may be one of the inputs of the hook function. So,

we need to be able to look up the layer name, given the corresponding layer

instance—if only there was something we could use to easily look up values, right?

layer_names = {layer: name for name, layer in modules[1:]}

layer_names

398 | Chapter 5: Convolutions

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

Saved successfully!

Ooh no, something went wrong!