https://pytorch.org/docs/stable/nn.html#conv2d
torch.nn.Conv2d(
in_channels, out_channels, kernel_size,
stride=1, padding=0, dilation=1, groups=1,
bias=True, padding_mode='zeros'
)
import torch
import torch.nn as nn
def print_result(input, output, filter):
print('------------------------------------------------------')
print(input.size())
print(filter)
print(output.size())
print('------------------------------------------------------')
# (batches, channels, H, W)
print('(batches, channels, H, W)')
input = torch.randn(1, 3, 128, 128)
print('base:')
m = nn.Conv2d(3, 6, 3)
output = m(input)
print_result(input, output, m)
print('padding:')
m = nn.Conv2d(6, 6, 3, padding=1)
input = output
output = m(input)
print_result(input, output, m)
print('stride:')
m = nn.Conv2d(6, 6, 3, stride=2)
input = output
output = m(input)
print_result(input, output, m)
print('dilation:')
m = nn.Conv2d(6, 6, 3, dilation=2)
input = output
output = m(input)
print_result(input, output, m)
(batches, channels, H, W)
base:
------------------------------------------------------
torch.Size([1, 3, 128, 128])
Conv2d(3, 6, kernel_size=(3, 3), stride=(1, 1))
torch.Size([1, 6, 126, 126])
------------------------------------------------------
padding:
------------------------------------------------------
torch.Size([1, 6, 126, 126])
Conv2d(6, 6, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
torch.Size([1, 6, 126, 126])
------------------------------------------------------
stride:
------------------------------------------------------
torch.Size([1, 6, 126, 126])
Conv2d(6, 6, kernel_size=(3, 3), stride=(2, 2))
torch.Size([1, 6, 62, 62])
------------------------------------------------------
dilation:
------------------------------------------------------
torch.Size([1, 6, 62, 62])
Conv2d(6, 6, kernel_size=(3, 3), stride=(1, 1), dilation=(2, 2))
torch.Size([1, 6, 58, 58])
------------------------------------------------------
https://pytorch.org/docs/stable/nn.html?highlight=batchnorm2d#torch.nn.BatchNorm2d
torch.nn.BatchNorm1d(
num_features, eps=1e-05, momentum=0.1, affine=True,
track_running_stats=True
)
https://pytorch.org/docs/stable/nn.html?highlight=maxpool2d#torch.nn.MaxPool2d
torch.nn.MaxPool2d(
kernel_size, stride=None, padding=0, dilation=1,
return_indices=False, ceil_mode=False
)