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查看多台服务器进程的脚本分享
Jun 11 Python
使用PDB简单调试Python程序简明指南
Apr 25 Python
基于python select.select模块通信的实例讲解
Sep 21 Python
python实现内存监控系统
Mar 07 Python
Django实战之用户认证(初始配置)
Jul 16 Python
Python判断对象是否相等及eq函数的讲解
Feb 25 Python
PyQt4实时显示文本内容GUI的示例
Jun 14 Python
Python 通过截图匹配原图中的位置(opencv)实例
Aug 27 Python
Python实现随机取一个矩阵数组的某几行
Nov 26 Python
浅析Python 多行匹配模式
Jul 24 Python
python实战之用emoji表情生成文字
May 08 Python
Python sklearn分类决策树方法详解
Sep 23 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面向对象程序设计之类与反射API详解
2016/12/02 PHP
PHP使用星号替代用户名手机和邮箱的实现代码
2018/02/07 PHP
浅谈PHP中pack、unpack的详细用法
2018/03/12 PHP
jQuery 借助插件Lavalamp实现导航条动态美化效果
2013/09/27 Javascript
js操作label给label赋值及取label的值示例
2013/11/07 Javascript
详解Javascript动态操作CSS
2014/12/08 Javascript
javascript日期格式化方法汇总
2015/10/04 Javascript
jQuery-1.9.1源码分析系列(十)事件系统之事件体系结构
2015/11/19 Javascript
js如何准确获取当前页面url网址信息
2020/09/13 Javascript
jQuery中$.grep() 过滤函数 数组过滤
2016/11/22 Javascript
Nodejs中crypto模块的安全知识讲解
2018/01/03 NodeJs
JavaScript使用math.js进行精确计算操作示例
2018/06/19 Javascript
JavaScript实现表单注册、表单验证、运算符功能
2018/10/15 Javascript
使用node搭建自动发图文微博机器人的方法
2019/03/22 Javascript
vue实现自定义H5视频播放器的方法步骤
2019/07/01 Javascript
原生js基于canvas实现一个简单的前端截图工具代码实例
2019/09/10 Javascript
ES6如何用一句代码实现函数的柯里化
2020/01/18 Javascript
[00:33]2018DOTA2亚洲邀请赛TNC出场
2018/04/04 DOTA
[01:19:46]EG vs Secret 2019国际邀请赛淘汰赛 胜者组 BO3 第二场 8.21.mp4
2020/07/19 DOTA
解决python写的windows服务不能启动的问题
2014/04/15 Python
python 爬取微信文章
2016/01/30 Python
Python读写Json涉及到中文的处理方法
2016/09/12 Python
Python中用字符串调用函数或方法示例代码
2017/08/04 Python
利用Python自带PIL库扩展图片大小给图片加文字描述的方法示例
2017/08/08 Python
python+pyqt5实现24点小游戏
2019/01/24 Python
python向字符串中添加元素的实例方法
2019/06/28 Python
python+jinja2实现接口数据批量生成工具
2019/08/28 Python
pygame实现成语填空游戏
2019/10/29 Python
Python实现使用dir获取类的方法列表
2019/12/24 Python
python中count函数简单用法
2020/01/05 Python
使用python-Jenkins批量创建及修改jobs操作
2020/05/12 Python
Python中的流程控制详解
2021/02/18 Python
跨域修改iframe页面内容详解
2019/10/31 HTML / CSS
2015年助理工程师工作总结
2015/04/03 职场文书
学习党史心得体会2016
2016/01/23 职场文书
如何解决goland,idea全局搜索快捷键失效问题
2022/04/03 Golang