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

peiying410632
from peiying410632 More from this publisher
22.02.2024 Views

Figure 5.4 - Striding the image, one step at a timeThe size of the movement, in pixels, is called a stride. In ourexample, the stride is one.In code, it means we’re changing the slice of the input image:new_region = single[:, :, 0:3, (0+1):(3+1)]But the operation remains the same: First, an element-wise multiplication, andthen adding up the elements of the resulting matrix.Figure 5.5 - Element-wise multiplicationnew_filtered_region = new_region * identitynew_total = new_filtered_region.sum()new_totalConvolutions | 349

Output5Great! We have a second pixel value to add to our resulting image.Figure 5.6 - Taking one step to the rightWe can keep moving the gray region to the right until we can’t move it anymore.Figure 5.7 - An invalid step!The fourth step to the right will actually place the region partially outside theinput image. That’s a big no-no!last_horizontal_region = single[:, :, 0:3, (0+4):(3+4)]The selected region does not match the shape of the filter anymore. So, if we try toperform the element-wise multiplication, it fails:last_horizontal_region * identity350 | Chapter 5: Convolutions

Output

5

Great! We have a second pixel value to add to our resulting image.

Figure 5.6 - Taking one step to the right

We can keep moving the gray region to the right until we can’t move it anymore.

Figure 5.7 - An invalid step!

The fourth step to the right will actually place the region partially outside the

input image. That’s a big no-no!

last_horizontal_region = single[:, :, 0:3, (0+4):(3+4)]

The selected region does not match the shape of the filter anymore. So, if we try to

perform the element-wise multiplication, it fails:

last_horizontal_region * identity

350 | Chapter 5: Convolutions

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

Saved successfully!

Ooh no, something went wrong!