pytorch中的torch.nn.Conv2d()函数图文详解

作者:夏普通 时间:2021-02-01 17:32:13 

一、官方文档介绍

官网

pytorch中的torch.nn.Conv2d()函数图文详解

nn.Conv2d:对由多个输入平面组成的输入信号进行二维卷积

pytorch中的torch.nn.Conv2d()函数图文详解

pytorch中的torch.nn.Conv2d()函数图文详解

二、torch.nn.Conv2d()函数详解

参数详解

torch.nn.Conv2d(in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=True)

参数参数类型  
in_channelsintNumber of channels in the input image输入图像通道数
out_channelsintNumber of channels produced by the convolution卷积产生的通道数
kernel_size(int or tuple)Size of the convolving kernel卷积核尺寸,可以设为1个int型数或者一个(int, int)型的元组。例如(2,3)是高2宽3卷积核
stride(int or tuple, optional)Stride of the convolution. Default: 1卷积步长,默认为1。可以设为1个int型数或者一个(int, int)型的元组。
padding(int or tuple, optional)Zero-padding added to both sides of the input. Default: 0填充操作,控制padding_mode的数目。
padding_mode(string, optional)‘zeros’, ‘reflect’, ‘replicate’ or ‘circular’. Default: ‘zeros’padding模式,默认为Zero-padding 。
dilation(int or tuple, optional)Spacing between kernel elements. Default: 1扩张操作:控制kernel点(卷积核点)的间距,默认值:1。
groups(int, optional)Number of blocked connections from input channels to output channels. Default: 1group参数的作用是控制分组卷积,默认不分组,为1组。
bias(bool, optional)If True, adds a learnable bias to the output. Default: True为真,则在输出中添加一个可学习的偏差。默认:True。

参数dilation——扩张卷积(也叫空洞卷积)

dilation操作动图演示如下:

Dilated Convolution with a 3 x 3 kernel and dilation rate 2

扩张卷积核为3×3,扩张率为2

pytorch中的torch.nn.Conv2d()函数图文详解

参数groups——分组卷积

Group Convolution顾名思义,则是对输入feature map进行分组,然后每组分别卷积。

pytorch中的torch.nn.Conv2d()函数图文详解

pytorch中的torch.nn.Conv2d()函数图文详解

三、代码实例

import torch

x = torch.randn(3,1,5,4)
print(x)

conv = torch.nn.Conv2d(1,4,(2,3))
res = conv(x)

print(res.shape)    # torch.Size([3, 4, 4, 2])

输入:x[ batch_size, channels, height_1, width_1 ]

  • batch_size,一个batch中样本的个数 3

  • channels,通道数,也就是当前层的深度 1

  • height_1, 图片的高 5

  • width_1, 图片的宽 4

卷积操作:Conv2d[ channels, output, height_2, width_2 ]

  • channels,通道数,和上面保持一致,也就是当前层的深度 1

  • output ,输出的深度 4【需要4个filter】

  • height_2,卷积核的高 2

  • width_2,卷积核的宽 3

输出:res[ batch_size,output, height_3, width_3 ]

  • batch_size,,一个batch中样例的个数,同上 3

  • output, 输出的深度 4

  • height_3, 卷积结果的高度 4

  • width_3,卷积结果的宽度 2

一个样本卷积示例:

pytorch中的torch.nn.Conv2d()函数图文详解

pytorch中的torch.nn.Conv2d()函数图文详解

总结 

来源:https://blog.csdn.net/qq_34243930/article/details/107231539

标签:pytorch,torch.nn.conv2d(),函数
0
投稿

猜你喜欢

  • 五分钟学会Python 模块和包、文件

    2023-06-01 20:05:38
  • Pycharm激活码激活两种快速方式(附最新激活码和插件)

    2023-05-17 12:07:07
  • Oracle批量查询、删除、更新使用BULK COLLECT提高效率

    2023-07-14 03:15:52
  • NumPy迭代数组的实现

    2022-01-03 14:07:37
  • MySQL数据库中使用GRANT语句增添新用户

    2008-12-17 14:45:00
  • JavaScript实现点击按钮复制指定区域文本(推荐)

    2023-08-22 17:36:30
  • 基于Python3编写一个GUI翻译器

    2022-07-07 07:57:54
  • Python中Django发送带图片和附件的邮件

    2023-11-09 16:59:03
  • 浅谈Python中列表生成式和生成器的区别

    2023-03-21 11:50:39
  • 详解基于python的全局与局部序列比对的实现(DNA)

    2021-03-29 13:23:31
  • Python多叉树的构造及取出节点数据(treelib)的方法

    2021-11-07 05:00:16
  • asp(JavaScript)自动判断网页编码并转换的代码

    2011-03-03 11:19:00
  • Python计算标准差之numpy.std和torch.std的区别

    2022-08-17 11:38:14
  • 关于 MediaPlayer 播放器参数详解

    2008-08-10 18:33:00
  • OpenCV-Python实现图像平滑处理操作

    2021-06-19 10:28:21
  • 详解python中的生成器、迭代器、闭包、装饰器

    2023-06-25 19:39:57
  • python+excel接口自动化获取token并作为请求参数进行传参操作

    2022-05-19 04:10:18
  • python使用itchat实现手机控制电脑

    2023-08-30 20:20:14
  • python移位运算的实现

    2021-07-16 10:23:38
  • 细化解析:转换 SQL数据库时的疑难问题

    2009-02-05 15:38:00
  • asp之家 网络编程 m.aspxhome.com