当前位置:网站首页>PyTorch中 nn.Conv2d与nn.ConvTranspose2d函数的用法
PyTorch中 nn.Conv2d与nn.ConvTranspose2d函数的用法
2022-07-26 14:31:00 【代码的路】
1. 通道数问题
描述一个像素点,如果是灰度,那么只需要一个数值来描述它,就是单通道。如果有RGB三种颜色来描述它,就是三通道。最初输入的图片样本的 channels,取决于图片类型;卷积操作完成后输出的 out_channels,取决于卷积核的数量。此时的out_channels也会作为下一次卷积时的卷积核的in_channels;卷积核中的 in_channels,上面已经说了,就是上一次卷积的out_channels,如果是第一次做卷积,就是样本图片的channels。
举个例子,假设现有一个为 6×6×3的图片样本,使用 3×3×3 的卷积核(filter)进行卷积操作。此时输入图片的 channels 为 3,而卷积核中的 in_channels 与需要进行卷积操作的数据的 channels 一致(就是图片样本,为3)。接下来进行卷积操作,卷积核中的27个数字与分别与样本对应相乘后,再进行求和,得到第一个结果。依次进行,最终得到 4×4的结果。由于只有一个卷积核,所以最终得到的结果为 4×4×1,out_channels 为 1。如下图所示:

在实际应用中,都会使用多个卷积核。这里如果再加一个卷积核,就会得到 4×4×2的结果。如下图所示:

2. nn.Conv2d
class torch.nn.Conv2d(in_channels, out_channels, kernel_size, stride=1, padding=0, output_padding=0, groups=1, bias=True)
nn.Conv2d的功能是:对由多个输入平面组成的输入信号进行二维卷积。输入信号的形式为:
(1)参数说明
N:表示batch size(批处理参数)
**C_{in}**:表示channel个数
H,W:分别表示特征图的高和宽。
stride(步长):步长,默认为1,可以设为1个int型数或者一个(int, int)型的tuple。
kernel_size:卷积核的宽度和长度,单个整数或由两个整数构成的list/tuple。如为单个整数,则表示在各个空间维度的相同长度。
padding(补0):控制zero-padding的数目,padding是在卷积之前补0。
dilation(扩张):控制kernel点(卷积核点)的间距; 可以在此github地址查看:Dilated convolution animations
groups(卷积核个数):通常来说,卷积个数唯一,但是对某些情况,可以设置范围在1 —— in_channels中数目的卷积核:
(2)图像尺寸
经过一次卷积之后,生成的图的大小:
(original_size - (kernal_size - 1)) / stride
3. nn.ConvTranspose2d
nn.ConvTranspose2d的功能是进行反卷积操作
(1)输入格式
nn.ConvTranspose2d(in_channels, out_channels, kernel_size, stride=1, padding=0, output_padding=0, groups=1, bias=True, dilation=1)
(2)参数的含义
in_channels(int) – 输入信号的通道数 out_channels(int) – 卷积产生的通道数 kerner_size(int or tuple) - 卷积核的大小 stride(int or tuple,optional) - 卷积步长,即要将输入扩大的倍数。 padding(int or tuple, optional) - 输入的每一条边补充0的层数,高宽都增加2*padding output_padding(int or tuple, optional) - 输出边补充0的层数,高宽都增加padding groups(int, optional) – 从输入通道到输出通道的阻塞连接数 bias(bool, optional) - 如果bias=True,添加偏置 dilation(int or tuple, optional) – 卷积核元素之间的间距
学习更多编程知识,请关注我的公众号:

边栏推荐
- Install dexdump on win10 and remove the shell
- Jzoffer (array; string; linked list)
- 图神经网络Core数据集介绍
- uni-app从创建到运行到微信开发者工具
- SiamRPN++:深层网络连体视觉跟踪的演变
- Tips for unity transparent channel
- 【常微分方程求解及绘图之求解小船行走轨迹】
- Fill in the questionnaire and receive the prize | we sincerely invite you to fill in the Google play academy activity survey questionnaire
- The development of smart home industry pays close attention to edge computing and applet container technology
- 中值滤波器
猜你喜欢

What is the problem of the time series database that has been developed for 5 years?

~6. CCF 2021-09-1 array derivation
![[ostep] 04 virtualized CPU - process scheduling strategy](/img/42/7ffb9745ef21a8db35861119dd70bf.png)
[ostep] 04 virtualized CPU - process scheduling strategy

win10安装Dexdump并脱壳

【1.2.投资的收益和风险】

Lingo软件的使用

Unity learning notes – infinite map

Pdf translation, which translation company in Beijing is good

Tips for unity transparent channel

Fill in the questionnaire and receive the prize | we sincerely invite you to fill in the Google play academy activity survey questionnaire
随机推荐
Win11运行虚拟机死机了?Win11运行VMware虚拟机崩溃的解决方法
UDP多线程在线聊天
中值滤波器
初识Opencv4.X----图像透视变换
网络图片转本地导致内核退出
maya将模型导入到unity
UE4 smart pointer and weak pointer
【方差分析】之matlab求解
Matlab solution of [analysis of variance]
低功耗多通道WFAS1431无线数据采集采发仪使用流程说明
Sqldeveloper tools quick start
如何评价测试质量?
目标跟踪相关知识总结
Pdf translation, which translation company in Beijing is good
Network pictures are transferred locally, causing the kernel to exit
Seata的部署与微服务集成
win10安装Dexdump并脱壳
Prediction and value evaluation of technology fusion relationship based on multiple features
在检测分割中一些轻量级网络模型(自己学习的笔记分享)
Redis data operation