当前位置:网站首页>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。
边栏推荐
- MySQL transaction isolation level, rounding
- Temporal客户端模型
- 面试官:生成订单30分钟未支付,则自动取消,该怎么实现?
- SQL语句中对时间字段进行区间查询
- 矩池云快速安装torch-sparse、torch-geometric等包
- Paginate the list collection and display the data on the page
- 【MySQL8入门到精通】基础篇- Linux系统静默安装MySQL,跨版本升级
- Unity mobile game performance optimization series: performance tuning for the CPU side
- Interviewer: If the order is not paid within 30 minutes, it will be automatically canceled. How to do this?
- MySQL忘记密码怎么办
猜你喜欢
Distributed Transactions - Introduction to Distributed Transactions, Distributed Transaction Framework Seata (AT Mode, Tcc Mode, Tcc Vs AT), Distributed Transactions - MQ
Sun Wenlong, Secretary General of the Open Atom Open Source Foundation |
太厉害了,终于有人能把文件上传漏洞讲的明明白白了
ES 源码 API调用链路源码分析
Temporal客户端模型
MySQL database installation (detailed)
CentOS7 - yum install mysql
Mysql——字符串函数
面试官:生成订单30分钟未支付,则自动取消,该怎么实现?
1. 获取数据-requests.get()
随机推荐
Redis进阶 - 缓存问题:一致性、穿击、穿透、雪崩、污染等.
MySQL事务(transaction) (有这篇就足够了..)
mysql uses on duplicate key update to update data in batches
Unity Tutorial: URP Rendering Pipeline Practical Tutorial Series [1]
PWN ROP
Tapdata 与 Apache Doris 完成兼容性互认证,共建新一代数据架构
MySQL forgot password
面试官竟然问我怎么分库分表?幸亏我总结了一套八股文
Error EPERM operation not permitted, mkdir 'Dsoftwarenodejsnode_cache_cacach Two solutions
Go language study notes - dealing with timeout problems - Context usage | Go language from scratch
Mysql应用安装后找不到my.ini文件
Unity mobile game performance optimization series: performance tuning for the CPU side
Typec手机有线网卡网线转网口转接口快充方案
MYSQL一站式学习,看完即学完
With MVC, why DDD?
centos7安装mysql5.7步骤(图解版)
快速掌握并发编程 --- 基础篇
DVWA installation tutorial (understand what you don't understand · in detail)
Input length must be multiple of 8 when decrypting with padded cipher
matlab simulink欠驱动水面船舶航迹自抗扰控制研究