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.

Padding in Computer Vision

Padding an image simply means adding zeros around it. An image is worth a

thousand words in this case.

By adding columns and rows of zeros around it, we expand the input image

such that the gray region starts centered in the actual top-left corner of the

input image. This simple trick can be used to preserve the original size of the

image.

Padding

Now, we’ll stuff sequences with zeros so they all have matching sizes. Simple

enough, right?

"OK, it is simple, but why are we doing it?"

We need to pad the sequences because we cannot create a tensor out of a list of

elements with different sizes:

all_seqs = [s0, s1, s2]

torch.as_tensor(all_seqs)

654 | Chapter 8: Sequences

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

Saved successfully!

Ooh no, something went wrong!