当前位置:网站首页>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。
边栏推荐
- [Detailed explanation of ORACLE Explain]
- ERROR 1819 (HY000) Your password does not satisfy the current policy requirements
- DVWA之SQL注入
- [Cloud Native] DevOps (5): Integrating Harbor
- Multiple table query of sql statement
- MySQL optimization: from ten seconds to three hundred milliseconds
- Interviewer: If the order is not paid within 30 minutes, it will be automatically canceled. How to do this?
- Error EPERM operation not permitted, mkdir 'Dsoftwarenodejsnode_cache_cacach Two solutions
- Shell重油常压塔模拟仿真与控制
- MySQL-如何分库分表?一看就懂
猜你喜欢

matlab abel变换图片处理

工作流编排引擎-Temporal

sql statement - how to query data in another table based on the data in one table

About the problems encountered by Xiaobai installing nodejs (npm WARN config global `--global`, `--local` are deprecated. Use `--location=glob)

MySQL(更新中)

DVWA之SQL注入

PWN ROP

MySQL (updating)

mysql使用on duplicate key update批量更新数据

为什么要用Flink,怎么入门使用Flink?
随机推荐
Unity Tutorial: URP Rendering Pipeline Practical Tutorial Series [1]
CentOS7 安装MySQL 图文详细教程
精解四大集合框架:List 核心知识总结
【一起学Rust】Rust学习前准备——注释和格式化输出
MySQL8.0.26安装配置教程(windows 64位)
【mysql 提高查询效率】Mysql 数据库查询好慢问题解决
【一起学Rust】Rust的Hello Rust详细解析
EasyExcel的简单读取操作
Interview | Cheng Li, CTO of Alibaba: Cloud + open source together form a credible foundation for the digital world
sql语句之多表查询
<urlopen error [Errno 11001] getaddrinfo failed>的解决、isinstance()函数初略介绍
MySQL8--Windows下使用压缩包安装的方法
Centos7 install mysql5.7 steps (graphical version)
On-line monitoring system for urban waterlogging and water accumulation in bridges and tunnels
ABC D - Distinct Trio(k元组的个数
MySQL_关于JSON数据的查询
MYSQL下载及安装完整教程
质量小议12 -- 以测代评
Goodbye to the cumbersome Excel, mastering data analysis and processing technology depends on it
Blockbuster | foundation for platinum, gold, silver gave nameboards donors