pytorch中的上采样以及各种反操作,求逆操作详解


Posted in Python onJanuary 03, 2020

import torch.nn.functional as F

import torch.nn as nn

F.upsample(input, size=None, scale_factor=None,mode='nearest', align_corners=None)

r"""Upsamples the input to either the given :attr:`size` or the given
  :attr:`scale_factor`
  The algorithm used for upsampling is determined by :attr:`mode`.
  Currently temporal, spatial and volumetric upsampling are supported, i.e.
  expected inputs are 3-D, 4-D or 5-D in shape.
  The input dimensions are interpreted in the form:
  `mini-batch x channels x [optional depth] x [optional height] x width`.
  The modes available for upsampling are: `nearest`, `linear` (3D-only),
  `bilinear` (4D-only), `trilinear` (5D-only)
  Args:
    input (Tensor): the input tensor
    size (int or Tuple[int] or Tuple[int, int] or Tuple[int, int, int]):
      output spatial size.
    scale_factor (int): multiplier for spatial size. Has to be an integer.
    mode (string): algorithm used for upsampling:
      'nearest' | 'linear' | 'bilinear' | 'trilinear'. Default: 'nearest'
    align_corners (bool, optional): if True, the corner pixels of the input
      and output tensors are aligned, and thus preserving the values at
      those pixels. This only has effect when :attr:`mode` is `linear`,
      `bilinear`, or `trilinear`. Default: False
  .. warning::
    With ``align_corners = True``, the linearly interpolating modes
    (`linear`, `bilinear`, and `trilinear`) don't proportionally align the
    output and input pixels, and thus the output values can depend on the
    input size. This was the default behavior for these modes up to version
    0.3.1. Since then, the default behavior is ``align_corners = False``.
    See :class:`~torch.nn.Upsample` for concrete examples on how this
    affects the outputs.
  """

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

"""
Parameters: 
  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
  stride (int or tuple, optional) ? Stride of the convolution. Default: 1
  padding (int or tuple, optional) ? kernel_size - 1 - padding zero-padding will be added to both sides of each dimension in the input. Default: 0
  output_padding (int or tuple, optional) ? Additional size added to one side of each dimension in the output shape. Default: 0
  groups (int, optional) ? Number of blocked connections from input channels to output channels. Default: 1
  bias (bool, optional) ? If True, adds a learnable bias to the output. Default: True
  dilation (int or tuple, optional) ? Spacing between kernel elements. Default: 1
"""

计算方式:

pytorch中的上采样以及各种反操作,求逆操作详解

定义:nn.MaxUnpool2d(kernel_size, stride=None, padding=0)

调用:

def forward(self, input, indices, output_size=None):
  return F.max_unpool2d(input, indices, self.kernel_size, self.stride,
             self.padding, output_size)
r"""Computes a partial inverse of :class:`MaxPool2d`.
  :class:`MaxPool2d` is not fully invertible, since the non-maximal values are lost.
  :class:`MaxUnpool2d` takes in as input the output of :class:`MaxPool2d`
  including the indices of the maximal values and computes a partial inverse
  in which all non-maximal values are set to zero.
  .. note:: `MaxPool2d` can map several input sizes to the same output sizes.
       Hence, the inversion process can get ambiguous.
       To accommodate this, you can provide the needed output size
       as an additional argument `output_size` in the forward call.
       See the Inputs and Example below.
  Args:
    kernel_size (int or tuple): Size of the max pooling window.
    stride (int or tuple): Stride of the max pooling window.
      It is set to ``kernel_size`` by default.
    padding (int or tuple): Padding that was added to the input
  Inputs:
    - `input`: the input Tensor to invert
    - `indices`: the indices given out by `MaxPool2d`
    - `output_size` (optional) : a `torch.Size` that specifies the targeted output size
  Shape:
    - Input: :math:`(N, C, H_{in}, W_{in})`
    - Output: :math:`(N, C, H_{out}, W_{out})` where
  计算公式:见下面
  Example: 见下面
  """

pytorch中的上采样以及各种反操作,求逆操作详解

F. max_unpool2d(input, indices, kernel_size, stride=None, padding=0, output_size=None)

见上面的用法一致!

def max_unpool2d(input, indices, kernel_size, stride=None, padding=0,
         output_size=None):
  r"""Computes a partial inverse of :class:`MaxPool2d`.
  See :class:`~torch.nn.MaxUnpool2d` for details.
  """
  pass

以上这篇pytorch中的上采样以及各种反操作,求逆操作详解就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持三水点靠木。

Python 相关文章推荐
使用python绘制常用的图表
Aug 27 Python
Django 实现下载文件功能的示例
Mar 06 Python
Python实现的计算器功能示例
Apr 26 Python
python使用循环打印所有三位数水仙花数的实例
Nov 13 Python
Python简易版停车管理系统
Aug 12 Python
python中数据库like模糊查询方式
Mar 02 Python
Django数据库操作之save与update的使用
Apr 01 Python
Pytorch转tflite方式
May 25 Python
python3.8动态人脸识别的实现示例
Sep 21 Python
python使用pygame创建精灵Sprite
Apr 06 Python
浅谈pytorch中stack和cat的及to_tensor的坑
May 20 Python
Python+Selenium实现读取网易邮箱验证码
Mar 13 Python
pytorch 获取tensor维度信息示例
Jan 03 #Python
pytorch中torch.max和Tensor.view函数用法详解
Jan 03 #Python
pytorch逐元素比较tensor大小实例
Jan 03 #Python
pytorch 改变tensor尺寸的实现
Jan 03 #Python
Pytorch Tensor 输出为txt和mat格式方式
Jan 03 #Python
CentOS7下安装python3.6.8的教程详解
Jan 03 #Python
Python实现大数据收集至excel的思路详解
Jan 03 #Python
You might like
PHP扩展编写点滴 技巧收集
2010/03/09 PHP
PHP简单获取网站百度搜索和搜狗搜索收录量的方法
2016/08/23 PHP
PHP  实现等比压缩图片尺寸和大小实例代码
2016/10/08 PHP
php安装扩展mysqli的实现步骤及报错解决办法
2017/09/23 PHP
Firefox getBoxObjectFor getBoundingClientRect联系
2008/10/26 Javascript
JQuery扩展插件Validate 3通过参数设置错误信息
2011/09/05 Javascript
javascript检测对象中是否存在某个属性判断方法小结
2013/05/19 Javascript
javascript删除数组重复元素的方法汇总
2015/06/24 Javascript
Node.js开发第三方微信公众平台
2017/06/05 Javascript
jQuery实现html table行Tr的复制、删除、计算功能
2017/07/10 jQuery
vue中七牛插件使用的实例代码
2017/07/28 Javascript
vue-router2.0 组件之间传参及获取动态参数的方法
2017/11/10 Javascript
js实现把时间戳转换为yyyy-MM-dd hh:mm 格式(es6语法)
2017/12/28 Javascript
jQuery获取所有父级元素及同级元素及子元素的方法(推荐)
2018/01/21 jQuery
vue+element实现批量删除功能的示例
2018/02/28 Javascript
vue中使用cropperjs的方法
2018/03/01 Javascript
vue.js使用3DES加密的方法示例
2018/05/18 Javascript
vue主动刷新页面及列表数据删除后的刷新实例
2018/09/16 Javascript
vue.js 打包时出现空白页和路径错误问题及解决方法
2019/06/26 Javascript
Webpack中loader打包各种文件的方法实例
2019/09/03 Javascript
Python判断值是否在list或set中的性能对比分析
2016/04/16 Python
tensorflow更改变量的值实例
2018/07/30 Python
Python 生成 -1~1 之间的随机数矩阵方法
2018/08/04 Python
对python中UDP,socket的使用详解
2019/08/22 Python
Python3 Tkinkter + SQLite实现登录和注册界面
2019/11/19 Python
python标准库OS模块函数列表与实例全解
2020/03/10 Python
Python Opencv轮廓常用操作代码实例解析
2020/09/01 Python
python日志通过不同的等级打印不同的颜色(示例代码)
2021/01/13 Python
可持续木材、生态和铝制太阳镜:Proof Eyewear
2019/07/24 全球购物
夏威夷咖啡公司:Hawaii Coffee Company
2019/09/19 全球购物
校园元旦活动总结
2014/07/09 职场文书
护士工作失误检讨书
2014/09/14 职场文书
2015年教师自我评价范文
2015/03/04 职场文书
2016年校园植树节广播稿
2015/12/17 职场文书
springboot应用服务启动事件的监听实现
2022/04/06 Java/Android
nginx代理实现静态资源访问的示例代码
2022/07/07 Servers