Pytorch learning (2) Conv2d convolution

The function is to apply a 2D convolution on an input signal consisting of multiple input planes.
https://pytorch.org/docs/stable/generated/torch.nn.Conv2d.html#torch.nn.Conv2d

function prototype

torch.nn.Conv2d(in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=True, padding_mode='zeros', device=None, dtype=None)

Parameter Description

in_channels: int type, the number of input image channels
out_channels: int type, the number of channels generated by convolution
kernel_size: int or tuple type, the size of the convolution kernel, which can be set to an int type number or an (int, int) type element Group. For example (2,3) is the height, 2, width and 3 convolution kernel
stride: int or tuple type, convolution stride, the default is 1. Can be set to an int or a tuple of (int, int).
padding: int or tuple type, padding operation, controls the number of padding_mode.
padding_mode : string, type 'zeros', 'reflect', 'replicate' or 'circular'. Default: 'zeros' padding mode, the default is Zero-padding.
dilation: int or tuple type, expansion operation: control the spacing of kernel points (convolution kernel points), default value: 1.
groups, int type, the function of the group parameter is to control the grouped convolution, the default is not grouped, it is 1 group.
bias : bool: True to add a learnable bias to the output. Default: True.

code test

import torch

x = torch.randn(2, 1, 5, 5)
print(x)

conv = torch.nn.Conv2d(1,3,(2,2))
res = conv(x)

print(res.shape)
print(res)

Input: x[ batch_size, channels, height_1, width_1 ]
batch_size, the number of samples in a batch 2
channels, the number of channels, that is, the depth of the current layer is 1
height_1, the height of the image is 5
width_1, the width of the image is 5

Convolution operation: Conv2d[ channels, output, height_2, width_2 ]
channels, the number of channels, consistent with the above, that is, the depth of the current layer is 1
output, the depth of the output is 3 [requires 3 filters]
height_2, the height of the convolution kernel 2
width_2, the width of the convolution kernel is 2

Output: res[ batch_size, output, height_3, width_3 ]
batch_size,, the number of samples in a batch, same as above 2
output, output depth 3
height_3, convolution result height 4
width_3, convolution result width 4

printout:
insert image description here

insert image description here

insert image description hereinsert image description here

Guess you like

Origin blog.csdn.net/weixin_44901043/article/details/123744373