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


Posted in Python onFebruary 28, 2022

一、官方文档介绍

官网

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_channels int Number of channels in the input image 输入图像通道数
out_channels int Number 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: 1 group参数的作用是控制分组卷积,默认不分组,为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()函数图文详解

总结 

到此这篇关于pytorch中torch.nn.Conv2d()函数的文章就介绍到这了,更多相关pytorch torch.nn.Conv2d()函数内容请搜索三水点靠木以前的文章或继续浏览下面的相关文章希望大家以后多多支持三水点靠木!

Python 相关文章推荐
python time模块用法实例详解
Sep 11 Python
python读取word文档的方法
May 09 Python
Python PyQt5标准对话框用法示例
Aug 23 Python
Python创建二维数组实例(关于list的一个小坑)
Nov 07 Python
浅谈使用Python内置函数getattr实现分发模式
Jan 22 Python
Python使用分布式锁的代码演示示例
Jul 30 Python
python用BeautifulSoup库简单爬虫实例分析
Jul 30 Python
influx+grafana自定义python采集数据和一些坑的总结
Sep 17 Python
Python 分发包中添加额外文件的方法
Aug 16 Python
Python实现括号匹配方法详解
Feb 10 Python
Python列表倒序输出及其效率详解
Mar 04 Python
Pytorch 使用tensor特定条件判断索引
Apr 08 Python
python3中apply函数和lambda函数的使用详解
Feb 28 #Python
你需要掌握的20个Python常用技巧
Feb 28 #Python
python opencv将多个图放在一个窗口的实例详解
pandas中关于apply+lambda的应用
Feb 28 #Python
Python中的datetime包与time包包和模块详情
Feb 28 #Python
Python 数据可视化神器Pyecharts绘制图像练习
Python使用OpenCV实现虚拟缩放效果
You might like
phpMyAdmin2.11.6安装配置方法
2008/08/24 PHP
php使用imagick模块实现图片缩放、裁剪、压缩示例
2014/04/17 PHP
使用配置类定义Codeigniter全局变量
2014/06/12 PHP
PHP代码加密的方法总结
2020/03/13 PHP
JavaScript的面向对象方法以及差别
2008/03/31 Javascript
js修改table中Td的值(定义td的单击事件)
2013/01/10 Javascript
面向对象继承实例(a如何继承b问题)(自写)
2013/07/01 Javascript
js在输入框屏蔽按键,只能键入数字的示例代码
2014/01/03 Javascript
IE6下拉框图层问题探讨及解决
2014/01/03 Javascript
jQuery CSS()方法改变现有的CSS样式
2014/08/20 Javascript
JS模仿手机端九宫格登录功能实现代码
2016/04/28 Javascript
js获取上传文件的绝对路径实现方法
2016/08/02 Javascript
原生js实现网易轮播图效果
2020/04/10 Javascript
js字符串操作总结(必看篇)
2016/11/22 Javascript
jQuery中clone()函数实现表单中增加和减少输入项
2017/05/13 jQuery
import的本质解析
2017/10/30 Python
python 对dataframe下面的值进行大规模赋值方法
2018/06/09 Python
使用Python的Dataframe取两列时间值相差一年的所有行方法
2018/07/10 Python
Django Form设置文本框为readonly操作
2020/07/03 Python
python如何变换环境
2020/07/21 Python
Python如何创建装饰器时保留函数元信息
2020/08/07 Python
一篇文章搞懂python的转义字符及用法
2020/09/03 Python
CSS3系列教程:背景图片(背景大小和多背景图) 应用说明
2012/12/19 HTML / CSS
非凡女性奢华谦虚风格:The Modist
2017/10/28 全球购物
当当网官方旗舰店:中国图书销售夺金品牌
2018/04/02 全球购物
TripAdvisor日本:全球领先的旅游网站
2019/02/14 全球购物
新闻专业大学生找工作的自我评价
2013/10/30 职场文书
高三生物教学反思
2014/01/25 职场文书
求职信怎么写范文
2014/05/26 职场文书
运动会拉拉队口号
2014/06/09 职场文书
2015年复活节活动总结
2015/02/27 职场文书
2015年社区纪检工作总结
2015/04/21 职场文书
2019事业单位个人工作总结范文
2019/08/26 职场文书
在校大学生才艺比赛策划书怎么写?
2019/08/26 职场文书
Python爬虫爬取全球疫情数据并存储到mysql数据库的步骤
2021/03/29 Python
各国货币符号大全
2022/02/17 杂记