当前位置:网站首页>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。
边栏推荐
- Goodbye to the cumbersome Excel, mastering data analysis and processing technology depends on it
- 矩池云快速安装torch-sparse、torch-geometric等包
- mysql uses on duplicate key update to update data in batches
- DVWA安装教程(懂你的不懂·详细)
- MYSQL下载及安装完整教程
- datagrip带参sql查询
- ERROR 1064 (42000) You have an error in your SQL syntax; check the manual that corresponds to your
- sql statement - how to query data in another table based on the data in one table
- The Vue project connects to the MySQL database through node and implements addition, deletion, modification and query operations
- 【MQ我可以讲一个小时】
猜你喜欢

MySQL transaction (transaction) (this is enough..)

MySQL优化:从十几秒优化到三百毫秒

CentOS7 安装MySQL 图文详细教程

MySQL forgot password

太厉害了,终于有人能把文件上传漏洞讲的明明白白了
![2022-07-30:以下go语言代码输出什么?A:[]byte{} []byte;B:[]byte{} []uint8;C:[]uint8{} []byte;D:[]uin8{} []uint8。](/img/7f/130a9b733855a2bab07d26ffda2c49.png)
2022-07-30:以下go语言代码输出什么?A:[]byte{} []byte;B:[]byte{} []uint8;C:[]uint8{} []byte;D:[]uin8{} []uint8。

Three oj questions on leetcode

mysql uses on duplicate key update to update data in batches
【一起学Rust】Rust的Hello Rust详细解析

sql语句-如何以一个表中的数据为条件据查询另一个表中的数据
随机推荐
Shell重油常压塔模拟仿真与控制
Redis Advanced - Cache Issues: Consistency, Penetration, Penetration, Avalanche, Pollution, etc.
MySQL database backup
Summary of MySQL common interview questions (recommended collection!!!)
【MySQL8入门到精通】基础篇- Linux系统静默安装MySQL,跨版本升级
【一起学Rust】Rust学习前准备——注释和格式化输出
mysql5.7.35安装配置教程【超级详细安装教程】
MYSQL一站式学习,看完即学完
CentOS7 —— yum安装mysql
Go language study notes - dealing with timeout problems - Context usage | Go language from scratch
DVWA安装教程(懂你的不懂·详细)
CentOS7 安装MySQL 图文详细教程
A complete introduction to JSqlParse of Sql parsing and conversion
datagrip带参sql查询
STM32——DMA
限流的原理
pycharm专业版使用
Error EPERM operation not permitted, mkdir 'Dsoftwarenodejsnode_cache_cacach Two solutions
mysql存储过程
如何将项目部署到服务器上(全套教程)