当前位置:网站首页>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.
边栏推荐
- 有了MVC,为什么还要DDD?
- C语言教程(三)-if和循环
- matlab simulink欠驱动水面船舶航迹自抗扰控制研究
- MySQL-如何分库分表?一看就懂
- STM32 - DMA
- tf.keras.utils.get_file()
- The interviewer asked me TCP three handshake and four wave, I really
- 剑指offer专项突击版 ---- 第 6 天
- C语言实验一 熟悉C程序的环境
- About the problems encountered by Xiaobai installing nodejs (npm WARN config global `--global`, `--local` are deprecated. Use `--location=glob)
猜你喜欢

第7章 网络层第3次练习题答案(第三版)

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

剑指offer专项突击版 --- 第 3 天

关于小白安装nodejs遇到的问题(npm WARN config global `--global`, `--local` are deprecated. Use `--location=glob)

快速掌握并发编程 --- 基础篇

Centos7 install mysql5.7

MySQL-Explain详解

基于flask的三方登陆的流程

Redis Advanced - Cache Issues: Consistency, Penetration, Penetration, Avalanche, Pollution, etc.
![[mysql improves query efficiency] Mysql database query is slow to solve the problem](/img/fa/502a2efdd37508f15541558851a254.png)
[mysql improves query efficiency] Mysql database query is slow to solve the problem
随机推荐
MYSQL一站式学习,看完即学完
Refinement of the four major collection frameworks: Summary of List core knowledge
Anaconda配置环境指令
数据库上机实验7 数据库设计
MySQL_关于JSON数据的查询
<urlopen error [Errno 11001] getaddrinfo failed>的解决、isinstance()函数初略介绍
pytorch中的一维、二维、三维卷积操作
【一起学Rust】Rust的Hello Rust详细解析
面试Redis 高可靠性|主从模式、哨兵模式、Cluster集群模式
工作流编排引擎-Temporal
ABC D - Distinct Trio (Number of k-tuples
数据库上机实验3 连接查询和分组查询
太厉害了,终于有人能把文件上传漏洞讲的明明白白了
Simple read operation of EasyExcel
tf.keras.utils.get_file()
精解四大集合框架:List 核心知识总结
实验8 DNS解析
【一起学Rust】Rust学习前准备——注释和格式化输出
MySQL-Explain详解
剑指offer专项突击版 ---- 第2天