当前位置:网站首页>[pytorch] 2.4 convolution function nn conv2d
[pytorch] 2.4 convolution function nn conv2d
2022-07-01 09:08:00 【Enzo tried to smash the computer】
Two dimensional convolution should be the most commonly used convolution method , stay Pytorch Of nn Module , Encapsulates the nn.Conv2d() Class as an implementation of two-dimensional convolution . The usage method is the same as that of ordinary classes , Instantiate first and then use . Here is a neural network with only one layer of two-dimensional convolution , As nn.Conv2d() Introduction to the use of the method :
class Net(nn.Module):
def __init__(self):
nn.Module.__init__(self)
self.conv2d = nn.Conv2d(in_channels=3,out_channels=64,kernel_size=4,stride=2,padding=1)
def forward(self, x):
print(x.requires_grad)
x = self.conv2d(x)
return x
print(net.conv2d.weight)
print(net.conv2d.bias)
Its formal parameters are Pytorch The manual can be found , The first three parameters must be provided manually , The following ones have default values . Next, I'll introduce :
- in_channels
It's easy to understand , Is the input four-dimensional tensor [N, C, H, W] Medium C 了 , That is, the input tensor channels Count . This parameter is used to determine the weight and other learnable parameters shape Necessary .
- out_channels
It's easy to understand , Of the desired four-dimensional output tensor channels Count , Don't say more .
- kernel_size
The size of the convolution kernel , We usually use 5x5、3x3 This convolution kernel with the same number on the left and right , So in this case, just write kernel_size = 5 That's all . If the left and right numbers are different , such as 3x5 Convolution kernel , So writing kernel_size = (3, 5), Note that you need to write a tuple, Instead of writing a list (list).
- stride = 1
The interval between each translation of convolution kernel on the image window , The so-called step size . This concept and Tensorflow Other frameworks make no difference , No more words .
- padding = 0
Pytorch And Tensorflow The biggest difference in the implementation of convolution layer is padding On .
Padding The so-called image filling , hinder int The type constant represents how much is filled ( Row number 、 Number of columns ), The default is 0. It should be noted that the filling here includes the top, bottom, left and right of the image , With padding = 1 For example , If the original image size is 32x32, that padding The size of the image becomes 34x34, instead of 33x33.
Pytorch differ Tensorflow The point is ,Tensorflow What is offered is padding The pattern of , such as same、valid, And different modes correspond to different output image size calculation formulas . and Pytorch You need to manually enter padding The number of , Of course ,Pytorch The advantage of this implementation is that the calculation formula of output image size is unique , namely

- dilation = 1
This parameter determines whether to use Cavity convolution , What is void convolution , Put two pictures and you will understand . The default is 1( Do not use ).

- groups = 1
Control the connection between input and output .group=1, The output is the convolution of all the inputs ;group=2, At this time, it is equivalent to having two convolution layers side by side , Each convolution layer computes half of the input channel , And the output is half of the output channel , Then connect the two outputs .
- bias = True
That is, whether to add offset parameters as learnable parameters , The default is True.
- padding_mode = ‘zeros’
namely padding The pattern of , Zero padding is used by default .
边栏推荐
- Redis -- lattice connects to redis cluster
- Phishing identification app
- Shell脚本-字符串
- Performance improvement 2-3 times! The second generation Kunlun core server of Baidu AI Cloud was launched
- Shell脚本-位置参数(命令行参数)
- Imitation of Baidu search results top navigation bar effect
- DataBinding源码分析
- Reproduced Xray - cve-2017-7921 (unauthorized access by Hikvision)
- It is designed with high bandwidth, which is almost processed into an open circuit?
- Dynamic proxy
猜你喜欢

Reproduced Xray - cve-2017-7921 (unauthorized access by Hikvision)

2.3 【kaggle数据集 - dog breed 举例】数据预处理、重写Dataset、DataLoader读取数据

Nacos - gestion de la configuration

如何做好固定资产管理?易点易动提供智能化方案

Simple load balancing with Nacos

Bird recognition app

How to manage fixed assets well? Easy to point and move to provide intelligent solutions

3D printing Arduino four axis aircraft

Daily practice of C language - day 80: currency change

nacos服务配置和持久化配置
随机推荐
[ESP nanny level tutorial] crazy completion chapter - Case: ws2812 light control system based on Alibaba cloud, applet and Arduino
Shell脚本-read命令:读取从键盘输入的数据
Record a redis timeout
Nacos - gestion de la configuration
Dynamic proxy
Understanding and implementation of AVL tree
【检测技术课案】简易数显电子秤的设计与制作
It is designed with high bandwidth, which is almost processed into an open circuit?
固定资产管理系统让企业动态掌握资产情况
Shell script - special variables: shell $, $*, [email protected], $$$
Shell脚本-while循环详解
LogBack
MySQL optimization
如何做好固定资产管理?易点易动提供智能化方案
Software Engineer Interview Question brushing website and experience method
Which method is good for the management of fixed assets of small and medium-sized enterprises?
nacos简易实现负载均衡
VSYNC+三重缓存机制+Choreographer
Shell script -while loop explanation
Mysql8.0 learning record 17 -create table