当前位置:网站首页>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。
边栏推荐
- STM32——DMA
- Unity Tutorial: URP Rendering Pipeline Practical Tutorial Series [1]
- 面试官:生成订单30分钟未支付,则自动取消,该怎么实现?
- wx.miniProgram.navigateTo在web-view中跳回小程序并传参
- MySQL transaction (transaction) (this is enough..)
- [mysql improves query efficiency] Mysql database query is slow to solve the problem
- Puzzle Game Level Design: Reverse Method--Explaining Puzzle Game Level Design
- PCL calculates the point cloud coordinate maximum and its index
- MySQL优化之慢日志查询
- Three oj questions on leetcode
猜你喜欢

TOGAF之架构标准规范(一)

MySQL优化之慢日志查询

Error EPERM operation not permitted, mkdir 'Dsoftwarenodejsnode_cache_cacach Two solutions

ERROR 2003 (HY000) Can't connect to MySQL server on 'localhost3306' (10061)

With MVC, why DDD?

MySQL (updating)

为什么要用Flink,怎么入门使用Flink?
【一起学Rust】Rust的Hello Rust详细解析

Summary of MySQL common interview questions (recommended collection!!!)

mysql使用on duplicate key update批量更新数据
随机推荐
MySQL优化之慢日志查询
【ORACLE Explain 详解】
On-line monitoring system for urban waterlogging and water accumulation in bridges and tunnels
.NET-6.WinForm2.NanUI learning and summary
[Detailed explanation of ORACLE Explain]
Mysql应用安装后找不到my.ini文件
Why use Flink and how to get started with Flink?
MySQL(更新中)
SQL行列转换
TOGAF之架构标准规范(一)
With MVC, why DDD?
Create componentized development based on ILRuntime hot update
分布式事务——分布式事务简介、分布式事务框架 Seata(AT模式、Tcc模式、Tcc Vs AT)、分布式事务—MQ
MySQL window function
【MQ我可以讲一个小时】
Temporal对比Cadence
[R language] [3] apply, tapply, lapply, sapply, mapply and par function related parameters
MySQL (updating)
【mysql 提高查询效率】Mysql 数据库查询好慢问题解决
Temporal介绍