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的Flask框架中使用Flask-SQLAlchemy管理数据库的教程
Jun 14 Python
关于Django显示时间你应该知道的一些问题
Dec 25 Python
Flask Web开发入门之文件上传(八)
Aug 17 Python
python实现在cmd窗口显示彩色文字
Jun 24 Python
Python Numpy 实现交换两行和两列的方法
Jun 26 Python
python os.fork() 循环输出方法
Aug 08 Python
python时间与Unix时间戳相互转换方法详解
Feb 13 Python
Python实现链表反转的方法分析【迭代法与递归法】
Feb 22 Python
浅谈python元素如何去重,去重后如何保持原来元素的顺序不变
Feb 28 Python
Python实现寻找回文数字过程解析
Jun 09 Python
详解Python设计模式之策略模式
Jun 15 Python
Python代码执行时间测量模块timeit用法解析
Jul 01 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
世界收音机发展史
2021/03/01 无线电
SMARTY学习手记
2007/01/04 PHP
PHP独立Session数据库存储操作类分享
2014/06/11 PHP
使用 PHPStorm 开发 Laravel
2015/03/24 PHP
PHPMAILER实现PHP发邮件功能
2018/04/18 PHP
jQuery学习3:操作元素属性和特性
2010/02/07 Javascript
javascript 折半查找字符在数组中的位置(有序列表)
2010/12/09 Javascript
Chrome扩展页面动态绑定JS事件提示错误
2014/02/11 Javascript
分享2个jQuery插件--jquery.fileupload与artdialog
2014/12/26 Javascript
ExpressJS入门实例
2015/01/14 Javascript
JavaScript实现数字数组按照倒序排列的方法
2015/04/06 Javascript
跟我学习javascript的作用域与作用域链
2015/11/19 Javascript
基于Bootstrap的Metronic框架实现页面链接收藏夹功能
2016/08/29 Javascript
基于jQuery的表单填充实例
2017/08/22 jQuery
详解基于vue-cli优化的webpack配置
2017/11/06 Javascript
JS实现select选中option触发事件操作示例
2018/07/13 Javascript
vue读取本地的excel文件并显示在网页上方法示例
2019/05/29 Javascript
详解mpvue实现对苹果X安全区域的适配
2019/07/31 Javascript
nodejs简单抓包工具使用详解
2019/08/23 NodeJs
vue中对象数组去重的实现
2020/02/06 Javascript
javaScript 实现重复输出给定的字符串的常用方法小结
2020/02/20 Javascript
JavaScript中arguments的使用方法详解
2020/12/20 Javascript
[55:03]完美世界DOTA2联赛PWL S2 LBZS vs FTD.C 第二场 11.20
2020/11/20 DOTA
使用Python脚本操作MongoDB的教程
2015/04/16 Python
python绘制BA无标度网络示例代码
2019/11/21 Python
python装饰器使用实例详解
2019/12/14 Python
python用Tkinter做自己的中文代码编辑器
2020/09/07 Python
如何用Python 实现全连接神经网络(Multi-layer Perceptron)
2020/10/15 Python
纯CSS3实现圆角效果(含IE兼容解决方法)
2014/05/07 HTML / CSS
施工资料员岗位职责
2014/01/06 职场文书
学生打架检讨书1000字
2014/01/16 职场文书
《美丽的黄昏》教学反思
2014/02/28 职场文书
勾股定理课后反思
2014/04/26 职场文书
保密工作整改报告
2014/11/06 职场文书
python神经网络 tf.name_scope 和 tf.variable_scope 的区别
2022/05/04 Python
JS前端轻量fabric.js系列之画布初始化
2022/08/05 Javascript