python进阶教程:pytorch中的卷积和池化计算方式详解

本文详细介绍了PyTorch中卷积和池化的计算方式,包括TensorFlow与PyTorch中padding的区别,PyTorch的卷积与池化操作的输出尺寸计算,以及AvgPool2d函数和F.avg_pool1d()的应用实例。通过对比和实例,阐述了PyTorch中卷积神经网络的特性和计算逻辑。
摘要由CSDN通过智能技术生成

@本文来源于公众号:csdn2299,喜欢可以关注公众号 程序员学府
TensorFlow里面的padding只有两个选项也就是valid和same

pytorch里面的padding么有这两个选项,它是数字0,1,2,3等等,默认是0

所以输出的h和w的计算方式也是稍微有一点点不同的:tf中的输出大小是和原来的大小成倍数关系,不能任意的输出大小;而nn输出大小可以通过padding进行改变

nn里面的卷积操作或者是池化操作的H和W部分都是一样的计算公式:H和W的计算
在这里插入图片描述

class torch.nn.MaxPool2d(kernel_size, stride=None, padding=0, dilation=1, return_indices=False, ceil_mode=False):
"""
Parameters: 
  kernel_size – the size of the window to take a max over
  stride – the stride of the window. 默认值是kernel_size
  padding – implicit zero padding to be added on both side,默认值是0
  dilation – a parameter that controls the stride of elements in the window,默认值是1
  return_indices – if True, will return the max indices along with the outputs. Useful when Unpooling later
  ceil_mode – when True, will use ceil instead of floor to compute the output shape,向上取整和向下取整,默认是向下取整
"""

不一样的地方在于:第一点,步长stride默认值,上面默认和设定的kernel_size一样,下面默认是1;第二点,输出通道的不一样,上面的输出通道和输入通道是一样的也就是没有改变特征图的数目,下面改变特征图的数目为out_channels

class tor
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值