Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the torch.nn.Conv2d () function in pytorch

2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly shows you "how to use the torch.nn.Conv2d () function in pytorch". The content is simple and clear. I hope it can help you solve your doubts. Let me lead you to study and learn how to use the torch.nn.Conv2d () function in pytorch.

I. introduction of official documents

Official website

Nn.Conv2d: two-dimensional convolution of input signals consisting of multiple input planes

2. Detailed explanation of torch.nn.Conv2d () function

Detailed explanation of parameters

Torch.nn.Conv2d (in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=True)

Parameter type in_channelsintNumber of channelsin the input image input number of image channels kernel_size (int or tuple) Size of the convolving kernel convolution kernel size generated by out_channelsintNumber of channels produced by the convolution convolution can be set to an int number or a (int, int) tuple. For example, (2p3) is a high 2 wide 3 convolution kernel stride (int or tuple, optional) Stride of the convolution. Default: 1 convolution step, default is 1. Can be set to an int number or a tuple of type (int, int). Padding (int or tuple, optional) Zero-padding added to both sides of the input. Default: 0 padding operation, which controls the number of padding_mode. Padding_mode (string, optional) 'zeros',' reflect', 'replicate' or' circular'. Default: 'zeros'padding mode, default is Zero-padding. Dilation (int or tuple, optional) Spacing between kernel elements. Default: 1 expansion operation: controls the spacing of kernel points (convolution kernel points). The default value is 1. Groups (int, optional) Number of blocked connections from input channels to output channels. Default: the function of the 1group parameter is to control packet convolution, which is not grouped by default and is set to group 1. Bias (bool, optional) If True, adds a learnable bias to the output. Default: if True is true, a learnable deviation is added to the output. Default: True. Parametric dilation-- extension convolution (also known as void convolution)

The operation diagram of dilation is shown below:

Dilated Convolution with a 3 x 3 kernel and dilation rate 2

The expansion convolution kernel is 3 × 3, and the expansion rate is 2.

Parameter groups-- grouped convolution

Group Convolution, as its name implies, groups the input feature map and convolution each group separately.

Third, code examples

Import torchx = torch.randn print (x) conv = torch.nn.Conv2d (1meme 4, (2mem3)) res = conv (x) print (res.shape) # torch.Size ([3,4,2])

Input: X [batch_size, channels, height_1, width_1]

Batch_size, the number of samples in a batch

Channels, number of channels, that is, the depth of the current layer 1

Height_1, the height of the picture is 5

Width_1, the width of the picture 4

Convolution operation: Conv2d [channels, output, height_2, width_2]

Channels, number of channels, consistent with the above, that is, the depth of the current layer 1

Output, output depth 4 [requires 4 filter]

Height_2, high 2 of convolution kernel

Width_2, width 3 of convolution kernel

Output: res [batch_size,output, height_3, width_3]

Batch_size, the number of samples in a batch, as above 3

Output, output depth 4

Height_3, height of convolution result 4

Width_3, width of convolution result 2

An example of sample convolution:

These are all the contents of the article "how to use the torch.nn.Conv2d () function in pytorch". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report