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的pycurl包用法简介
Nov 13 Python
python实现感知器算法详解
Dec 19 Python
python机器学习之神经网络(一)
Dec 20 Python
python3之模块psutil系统性能信息使用
May 30 Python
python中文编码与json中文输出问题详解
Aug 24 Python
python中的print()输出
Apr 12 Python
将matplotlib绘图嵌入pyqt的方法示例
Jan 08 Python
python 实现多维数组(array)排序
Feb 28 Python
Python yield的用法实例分析
Mar 06 Python
Python 如何实现访问者模式
Jul 28 Python
如何用Python 实现全连接神经网络(Multi-layer Perceptron)
Oct 15 Python
python的列表生成式,生成器和generator对象你了解吗
Mar 16 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中的日期加减方法示例
2014/08/21 PHP
php转换颜色为其反色的方法
2015/04/27 PHP
PHP使用mongoclient简单操作mongodb数据库示例
2019/02/08 PHP
laravel添加前台跳转成功页面示例
2019/10/22 PHP
理解JavaScript的caller,callee,call,apply
2009/04/28 Javascript
基于datagrid框架的查询
2013/04/08 Javascript
HTML,CSS,JavaScript速查表推荐
2014/12/02 Javascript
使用Meteor配合Node.js编写实时聊天应用的范例
2015/06/23 Javascript
JavaScript基本数据类型及值类型和引用类型
2015/08/25 Javascript
Jquery插件之Fancybox丰富的弹出层效果附源码下载
2015/12/02 Javascript
理解javascript函数式编程中的闭包(closure)
2016/03/08 Javascript
javascript实现PC网页里的拖拽效果
2016/03/14 Javascript
JQuery 两种方法解决刚创建的元素遍历不到的问题
2016/04/13 Javascript
详解JavaScript中的自定义事件编写
2016/05/10 Javascript
微信公众号 客服接口的开发实例详解
2016/09/28 Javascript
浅谈sass在vue注意的地方
2017/08/10 Javascript
AngularJS实现的select二级联动下拉菜单功能示例
2017/10/25 Javascript
详解jQuery中的isPlainObject()使用方法
2018/02/27 jQuery
使用zrender.js绘制体温单效果
2019/10/31 Javascript
vue实现购物车列表
2020/06/30 Javascript
绘制微信小程序验证码功能的实例代码
2021/01/05 Javascript
Python中文编码那些事
2014/06/25 Python
python通过字典dict判断指定键值是否存在的方法
2015/03/21 Python
Python下Fabric的简单部署方法
2015/07/14 Python
asyncio 的 coroutine对象 与 Future对象使用指南
2016/09/11 Python
Python使用xlrd实现读取合并单元格
2020/07/09 Python
html5理解head_动力节点Java学院整理
2017/07/13 HTML / CSS
为娇小女性量身打造:Petite Studio
2018/11/01 全球购物
俄罗斯建筑和装饰材料在线商店:Stroilandia
2020/07/25 全球购物
Windows和Linux动态库应用异同
2016/07/28 面试题
自我鉴定范文300字
2013/10/01 职场文书
教师节活动主持词
2014/04/02 职场文书
《音乐之都维也纳》教学反思
2014/04/16 职场文书
五一促销活动总结
2014/07/01 职场文书
Vue项目中如何封装axios(统一管理http请求)
2021/05/02 Vue.js
zabbix配置nginx监控的实现
2022/05/25 Servers