当前位置:网站首页>pytorch中的一维、二维、三维卷积操作
pytorch中的一维、二维、三维卷积操作
2022-07-31 05:09:00 【Cheng-O】
卷积操作就是就是利用滑动窗口机制对数据进行互相关运算来提取特征。
一维卷积
一维卷积用于处理序列数据,输入之前一般会对每个序列元素进行编码,这样得到的输入序列的格式应该是[batch_size, seq_len, embedding_size],这里的embedding_size相当于通道数一样的概念。所以在处理之前一般会进行permute(0,2,1)将输入的格式转换为[batch_size, embedding_size, seq_len]将embedding_size作为中间层来作为通道数来作为一维卷积的输入。
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')二维卷积
二维卷积是最早提出的卷积操作,用于对高维数据的处理,二维卷积的输入为[batch_size, channel_num, H, W]。
PS:在python中通常使用cv2函数来读取图片,读取的格式为[H,W,C],使用torchvision.transforms. ToTensor()可以将cv2读取的图片转换为pytorch中使用的格式[C,H,W]。
self.conv2 = nn.Conv2d(planes, planes, kernel_size=3, stride=stride, padding=2,
bias=False, dilation=1) # 前两个参数为通道数PS: 空洞卷积
卷积操作参数中有一项为dilation,设置为1则为正常的卷积操作,设置为大于1,则为空洞卷积,空洞卷积操作可以通过较小的卷积核来获得较大的感受野,以卷积核为3*3,dilation=2为例,原本的卷积操作会在特征图上取一个3*3大小的子区域和卷积核进行互相关运算,而使用空洞卷积之后,3*3的卷积核会被填充成5*5,即在原本的卷积核里用0填充,这样在进行互相关运算时同样会对一个5*5的区域进行运算,dilation为2的含义就为,卷积核中每个元素之间的距离经过填充之后的距离为2。
三维卷积
三维卷积用于提取视频数据特征,输入数据格式为[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)总结:相比于低维,高维卷积要多一个维度输入,同时数据的输入中前两个维度都是,batch_size和channel_num。
边栏推荐
- Go language study notes - dealing with timeout problems - Context usage | Go language from scratch
- Centos7 install mysql5.7
- MySQL optimization: from ten seconds to three hundred milliseconds
- [mysql improves query efficiency] Mysql database query is slow to solve the problem
- PCL calculates the point cloud coordinate maximum and its index
- [Introduction to MySQL 8 to Mastery] Basics - silent installation of MySQL on Linux system, cross-version upgrade
- Typec手机有线网卡网线转网口转接口快充方案
- 【一起学Rust】Rust的Hello Rust详细解析
- Mysql——字符串函数
- 如何将项目部署到服务器上(全套教程)
猜你喜欢

再见了繁琐的Excel,掌握数据分析处理技术就靠它了

CentOS7 —— yum安装mysql

A complete introduction to JSqlParse of Sql parsing and conversion

ERROR 1064 (42000) You have an error in your SQL syntax; check the manual that corresponds to your
![Unity Tutorial: URP Rendering Pipeline Practical Tutorial Series [1]](/img/7c/c9ab32bbf43b933e5f84f0d142f7bd.jpg)
Unity Tutorial: URP Rendering Pipeline Practical Tutorial Series [1]

Interview Redis High Reliability | Master-Slave Mode, Sentinel Mode, Cluster Cluster Mode

MySQL (updating)
![[R language] [3] apply, tapply, lapply, sapply, mapply and par function related parameters](/img/98/282d8d192f701ad33de48aeeb038b4.png)
[R language] [3] apply, tapply, lapply, sapply, mapply and par function related parameters

Temporal介绍

MySQL8--Windows下使用压缩包安装的方法
随机推荐
Distributed Transactions - Introduction to Distributed Transactions, Distributed Transaction Framework Seata (AT Mode, Tcc Mode, Tcc Vs AT), Distributed Transactions - MQ
110 MySQL interview questions and answers (continuously updated)
DVWA shooting range environment construction
ERROR 1819 (HY000) Your password does not satisfy the current policy requirements
MySQL database addition, deletion, modification and query (detailed explanation of basic operation commands)
Simple read operation of EasyExcel
MySQL-如何分库分表?一看就懂
Go中间件
MySQL(更新中)
The MySQL database installed configuration nanny level tutorial for 8.0.29 (for example) have hands
Goodbye to the cumbersome Excel, mastering data analysis and processing technology depends on it
【MQ我可以讲一个小时】
Error EPERM operation not permitted, mkdir 'Dsoftwarenodejsnode_cache_cacach Two solutions
【mysql 提高查询效率】Mysql 数据库查询好慢问题解决
Unity resources management series: Unity framework how to resource management
分布式事务处理方案大 PK!
MYSQL一站式学习,看完即学完
.NET-6.WinForm2.NanUI learning and summary
分布式事务——分布式事务简介、分布式事务框架 Seata(AT模式、Tcc模式、Tcc Vs AT)、分布式事务—MQ
The monitoring of Doris study notes