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实现方法
Nov 18 Python
Python中使用tarfile压缩、解压tar归档文件示例
Apr 05 Python
tensorflow 用矩阵运算替换for循环 用tf.tile而不写for的方法
Jul 27 Python
Python实现合并excel表格的方法分析
Apr 13 Python
python代码实现逻辑回归logistic原理
Aug 07 Python
Django框架 querySet功能解析
Sep 04 Python
softmax及python实现过程解析
Sep 30 Python
Python中的Cookie模块如何使用
Jun 04 Python
python给list排序的简单方法
Dec 10 Python
Pandas中DataFrame交换列顺序的方法实现
Dec 14 Python
python-for x in range的用法(注意要点、细节)
May 10 Python
Python tensorflow卷积神经Inception V3网络结构
May 06 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
浅谈web上存漏洞及原理分析、防范方法(安全文件上存方法)
2013/06/29 PHP
PHP+sqlite数据库操作示例(创建/打开/插入/检索)
2016/05/26 PHP
CentOS7编译安装php7.1的教程详解
2019/04/18 PHP
在b/s开发中经常用到的javaScript技术
2006/08/23 Javascript
IE6中使用position导致页面变形的解决方案(js代码)
2011/01/09 Javascript
在页面中js获取光标/鼠标的坐标及光标的像素坐标
2013/11/11 Javascript
解决js下referer兼容各大浏览器的方法
2014/11/03 Javascript
javascript使用for循环批量注册的事件不能正确获取索引值的解决方法
2014/12/20 Javascript
jquery结合CSS使用validate实现漂亮的验证
2015/01/29 Javascript
JQuery实现防止退格键返回的方法
2015/02/12 Javascript
jQuery超简单选项卡完整实例
2015/09/26 Javascript
Jquery ui datepicker设置日期范围,如只能隔3天【实现代码】
2016/05/04 Javascript
原生js封装的一些jquery方法(详解)
2016/09/20 Javascript
简单实现JavaScript图片切换效果
2016/11/28 Javascript
Angular的$http与$location
2016/12/26 Javascript
详解如何实现一个简单的Node.js脚手架
2017/12/04 Javascript
mongoose更新对象的两种方法示例比较
2017/12/19 Javascript
彻底弄懂 JavaScript 执行机制
2018/10/23 Javascript
iview在vue-cli3如何按需加载的方法
2018/10/31 Javascript
vue-iview动态新增和删除的方法
2020/06/17 Javascript
python2.7无法使用pip的解决方法(安装easy_install)
2018/04/03 Python
利用python打开摄像头及颜色检测方法
2018/08/03 Python
Python实现将多个空格换为一个空格.md的方法
2018/12/20 Python
Python3.7+tkinter实现查询界面功能
2019/12/24 Python
python中shell执行知识点
2020/05/06 Python
python热力图实现简单方法
2021/01/29 Python
Qoo10马来西亚:全球时尚和引领潮流的购物市场
2016/08/25 全球购物
澳大利亚家用电器在线商店:Billy Guyatts
2020/05/05 全球购物
最受欢迎的自我评价
2013/12/22 职场文书
管理失职检讨书
2014/02/12 职场文书
五年后的职业生涯规划
2014/03/04 职场文书
文秘档案管理岗位职责
2014/03/06 职场文书
琅琊山导游词
2015/02/05 职场文书
2016年教师党员公开承诺书
2016/03/24 职场文书
python requests模块的使用示例
2021/04/07 Python
Python实现制作销售数据可视化看板详解
2021/11/27 Python