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

tensor([[53, 53],

[75, 75]])

Once again, the model’s accuracy is perfect. Maybe you’ve noticed it was much

faster to train too. How come this simple model performed so well? Let’s try to

figure out what it did under the hood…

Visualizing the Model

The key component of our model is the nn.Conv1d layer, so let’s take a look at its

state_dict():

model.conv1d.state_dict()

Output

OrderedDict([('weight', tensor([[[-0.2186, 2.3289],

[-2.3765, -0.1814]]], device='cuda:0')),

('bias', tensor([-0.5457], device='cuda:0'))])

Then, let’s see what this filter is doing by feeding it a "perfect" square starting at

corner A and going counterclockwise (sequence ADCB):

Figure 8.34 - Applying filter over the "perfect" square

The figure above shows us the element-wise multiplication and result for the first

region, corresponding to the AD edge of our square (without including the bias

value from the convolutional layer). The outputs on the right are the "edge features."

678 | Chapter 8: Sequences

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

Saved successfully!

Ooh no, something went wrong!