当前位置:网站首页>1D, 2D, 3D convolution operations in pytorch
1D, 2D, 3D convolution operations in pytorch
2022-07-31 05:33:00 【Cheng-O】
The convolution operation is to use the sliding window mechanism to perform cross-correlation operations on the data to extract features.
One-dimensional convolution
One-dimensional convolution is used to process sequence data. Each sequence element is usually encoded before input. The format of the input sequence obtained in this way should be [batch_size, seq_len, embedding_size], hereThe embedding_size is equivalent to the same concept as the number of channels.Therefore, before processing, permute(0,2,1) is generally performed to convert the input format to [batch_size, embedding_size, seq_len] embedding_size is used as the intermediate layer as the number of channels as the one-dimensional convolutioninput of.
eg:
self.conv1 = nn.Conv1d(in_channels=n_feature, out_channels=n_feature, kernel_size=1,stride=1,padding=0, dilation=1, groups=1,bias=True, padding_mode='zeros')2D Convolution
Two-dimensional convolution is the earliest proposed convolution operation for processing high-dimensional data. The input of two-dimensional convolution is [batch_size, channel_num, H, W].
PS: In python, the cv2 function is usually used to read the image. The read format is [H,W,C]. Use torchvision.transforms.ToTensor() to read cv2The image is converted to the format [C,H,W] used in pytorch.
self.conv2 = nn.Conv2d(planes, planes, kernel_size=3, stride=stride, padding=2,bias=False, dilation=1) # The first two parameters are the number of channelsPS: Atrous convolution
One of the convolution operation parameters is dilation. If it is set to 1, it is a normal convolution operation. If it is set to be greater than 1, it is a hole convolution. The hole convolution operation can be obtained by a smaller convolution kernel.For a large receptive field, taking the convolution kernel as 3*3 and dilation=2 as an example, the original convolution operation will take a 3*3 size sub-region and the convolution kernel on the feature map for cross-correlation operation, and useAfter the hole convolution, the 3*3 convolution kernel will be padded to 5*5, that is, the original convolution kernel will be filled with 0, so that a 5*5 area will also be operated when the cross-correlation operation is performed., the meaning of a dilation of 2 is that the distance between each element in the convolution kernel is filled with a distance of 2.
3D Convolution
3D convolution is used to extract video data features, and the input data format is [batch_size, channel_num, t_len, H, W].
self.conv3d = nn.Conv3d(in_channels=in_channels, out_channels=output_channels,kernel_size=kernel_shape, stride=stride,padding=0, bias=self._use_bias)Summary: Compared with low-dimensional, high-dimensional convolution requires one more dimension input, and the first two dimensions of the data input are both batch_size and channel_num.
边栏推荐
猜你喜欢

Simple read operation of EasyExcel

With MVC, why DDD?

工作流编排引擎-Temporal

Swordsman Offer Special Assault Edition --- Day 3

C语言实验五 循环结构程序设计(二)

面试Redis 高可靠性|主从模式、哨兵模式、Cluster集群模式

Apache DButils使用注意事项--with modifiers “public“

剑指offer基础版 ----- 第25天

Swordsman Offer Special Assault Edition ---- Day 6

Information System Project Manager Core Test Site (55) Configuration Manager (CMO) Work
随机推荐
MySQL (updating)
Sword Point Offer Special Assault Edition ---- Day 2
torch.normal function usage
可点击也可直接复制指定内容js
剑指offer基础版 --- 第24天
Unity resources management series: Unity framework how to resource management
Centos7 install mysql5.7
剑指offer专项突击版 --- 第 3 天
踏上编程之路,你必须要干的几件事
Refinement of the four major collection frameworks: Summary of List core knowledge
pycharm专业版使用
【JS面试题】面试官:“[1,2,3].map(parseInt)“ 输出结果是什么?答上来就算你通过面试
Workflow番外篇
The monitoring of Doris study notes
第7章 网络层第2次练习题答案(第三版)
剑指offer基础版 ----- 第25天
数据库上机实验4 数据更新和视图
数据库上机实验6 数据库完整性
Kubernetes 证书可用年限修改
Unity Framework Design Series: How Unity Designs Network Frameworks