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([[[ 0.6241, -0.0274, -0.6412]]], grad_fn=<SqueezeBackward1>)

The resulting shape is given by the formula below, where l is the length of the

sequence, f is the filter size, p is the padding, and s is the stride:

Equation 8.15 - Resulting shape

If any of the resulting dimensions are not an integer, they must be rounded down.

Dilation

There is yet another operation that can be used with convolutions in any number of

dimensions, but that we haven’t discussed yet: dilation. The general idea is quite

simple: Instead of a contiguous kernel, it uses a dilated kernel. A dilation of size

two, for instance, means that the kernel uses every other element (be it a pixel or a

feature value in a sequence).

"Why would I want to do that?"

In a nutshell, the idea is to capture long-term properties of a sequence (like

seasonality in a time series, for example) or to integrate information from different

scales in an image (local and global context). We’re not delving deeper than

explaining the mechanism itself, though.

In our example, a kernel of size two (so it goes over two values in the sequence)

with a dilation of two (so it skips every other value in the sequence) works like

this:

674 | Chapter 8: Sequences

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

Saved successfully!

Ooh no, something went wrong!