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.

In PyTorch’s documentation there is a note warning about

possible reproducibility issues while using padding:

"When using the CUDA backend, this operation may induce

nondeterministic behaviour in its backward pass that is not easily

switched off. Please see the notes on reproducibility for background."

It strikes me as a bit odd that such a straightforward operation, of

all things, would jeopardize reproducibility. Go figure!

"What are the other available modes?"

There are three other modes: replicate, reflect, and circular. Let’s take a look at

them, starting with the visualization.

Figure 5.12 - Paddings modes

In replication padding, the padded pixels have the same value as the closest real

pixel. The padded corners have the same value as the real corners. The other

columns (left and right) and rows (top and bottom) replicate the corresponding

values of the original image. The values used in the replication are in a darker shade

of orange.

In PyTorch, one can use the functional form F.pad() with mode="replicate", or use

the module version nn.ReplicationPad2d:

replication_padder = nn.ReplicationPad2d(padding=1)

replication_padder(image)

360 | Chapter 5: Convolutions

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

Saved successfully!

Ooh no, something went wrong!