当前位置:网站首页>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.
边栏推荐
- 面试Redis 高可靠性|主从模式、哨兵模式、Cluster集群模式
- pycharm专业版使用
- 如何将项目部署到服务器上(全套教程)
- 关于superset集成到自己的项目中
- 账号或密码多次输入错误,进行账号封禁
- Quickly master concurrent programming --- the basics
- [Introduction to MySQL 8 to Mastery] Basics - silent installation of MySQL on Linux system, cross-version upgrade
- ABC D - Distinct Trio (Number of k-tuples
- CentOS7 - yum install mysql
- 剑指offer专项突击版 --- 第 4 天
猜你喜欢

Goodbye to the cumbersome Excel, mastering data analysis and processing technology depends on it

Sword Point Offer Special Assault Edition ---- Day 2

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

基于web3.0使用钱包Metamask的三方登陆

Sword Point Offer Special Assault Edition ---- Day 1

Quickly master concurrent programming --- the basics

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

Swordsman Offer Special Assault Edition ---- Day 6

面试官问我TCP三次握手和四次挥手,我真的是

MySQL-Explain详解
随机推荐
Mysql——字符串函数
Flink sink redis 写入Redis
太厉害了,终于有人能把文件上传漏洞讲的明明白白了
Linux的mysql报ERROR 1045 (28000) Access denied for user ‘root‘@‘localhost‘ (using password NOYSE)
【JS面试题】面试官:“[1,2,3].map(parseInt)“ 输出结果是什么?答上来就算你通过面试
a different object with the same identifier value was already associated with the session
剑指offer基础版 --- 第21天
数据库上机实验3 连接查询和分组查询
mysql5.7.35安装配置教程【超级详细安装教程】
Pytorch教程Introduction中的神经网络实现示例
Flink sink ES 写入 ES(带密码)
Apache DButils使用注意事项--with modifiers “public“
详解扫雷游戏(C语言)
Interviewer: If the order is not paid within 30 minutes, it will be automatically canceled. How to do this?
剑指offer基础版 --- 第24天
Swordsman Offer Special Assault Edition ---- Day 6
Information System Project Manager Core Test Site (55) Configuration Manager (CMO) Work
Refinement of the four major collection frameworks: Summary of List core knowledge
Quickly master concurrent programming --- the basics
【mysql 提高查询效率】Mysql 数据库查询好慢问题解决