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.

three_channel_filter = np.array([[[[0, 3, 0],

[1, 0, 1],

[2, 1, 0]],

[[2, 1, 0],

[0, 3, 1],

[1, -1, 0]],

[[0, 1, 3],

[-1, -2, 0],

[2, 0, 1]]]])

three_channel_filter.shape

Output

(1, 3, 3, 3)

result = F.conv2d(torch.as_tensor(regions),

torch.as_tensor(three_channel_filter))

result, result.shape

Output

(tensor([[[[39]]]]), torch.Size([1, 1, 1, 1]))

"What if I have two filters?"

Glad you asked! The figure below illustrates the fact that every filter has as many

channels as the image being convolved.

Three-Channel Convolutions | 427

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

Saved successfully!

Ooh no, something went wrong!