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中pass语句用法实例分析
Apr 30 Python
python实现复制整个目录的方法
May 12 Python
浅谈Python数据类型判断及列表脚本操作
Nov 04 Python
Python存取XML的常见方法实例分析
Mar 21 Python
django实现前后台交互实例
Aug 07 Python
Python3 适合初学者学习的银行账户登录系统实例
Aug 08 Python
python用列表生成式写嵌套循环的方法
Nov 08 Python
Python实现对字典分别按键(key)和值(value)进行排序的方法分析
Dec 19 Python
Python爬虫爬取百度搜索内容代码实例
Jun 05 Python
Python sorted对list和dict排序
Jun 09 Python
Keras 使用 Lambda层详解
Jun 10 Python
Python用Jira库来操作Jira
Dec 28 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压缩HTML函数轻松实现压缩html/js/Css及注意事项
2013/01/27 PHP
使用php判断浏览器的类型和语言的函数代码
2013/02/28 PHP
Laravel 5框架学习之日期,Mutator 和 Scope
2015/04/08 PHP
PHP实现的通过参数生成MYSQL语句类完整实例
2016/04/11 PHP
js 多种变量定义(对象直接量,数组直接量和函数直接量)
2010/05/24 Javascript
jquery 清空file域示例(兼容个浏览器)
2013/10/11 Javascript
Javascript 命名空间模式
2013/11/01 Javascript
js判断IE浏览器版本过低示例代码
2013/11/22 Javascript
关于JavaScript命名空间的一些心得
2014/06/07 Javascript
iPhone手机上搭建nodejs服务器步骤方法
2015/07/06 NodeJs
js代码实现点击按钮出现60秒倒计时
2021/01/28 Javascript
pc加载更多功能和移动端下拉刷新加载数据
2016/11/07 Javascript
jQuery实现的手风琴侧边菜单效果
2017/03/29 jQuery
vue的基本用法与常见指令
2017/08/15 Javascript
浅谈Vue.nextTick 的实现方法
2017/10/25 Javascript
关于Webpack dev server热加载失败的解决方法
2018/02/22 Javascript
微信小程序实现换肤功能
2018/03/14 Javascript
利用jquery和BootStrap实现动态滚动条效果
2018/12/03 jQuery
JS实现移动端点击按钮复制文本内容
2019/07/28 Javascript
layui多iframe页面控制定时器运行的方法
2019/09/05 Javascript
微信小程序开发(三):返回上一级页面并刷新操作示例【页面栈】
2020/06/01 Javascript
Python模拟鼠标点击实现方法(将通过实例自动化模拟在360浏览器中自动搜索python)
2017/08/23 Python
Python实现字典按照value进行排序的方法分析
2017/12/23 Python
Python之ReportLab绘制条形码和二维码的实例
2018/01/15 Python
使用Python和xlwt向Excel文件中写入中文的实例
2018/04/21 Python
修复 Django migration 时遇到的问题解决
2018/06/14 Python
5行Python代码实现图像分割的步骤详解
2020/05/25 Python
python绘制汉诺塔
2021/03/01 Python
html5 svg 中元素点击事件添加方法
2013/01/16 HTML / CSS
消防战士优秀事迹材料
2014/02/13 职场文书
违反工作纪律检讨书
2014/02/15 职场文书
化妆品活动策划方案
2014/05/23 职场文书
护士年终考核评语
2014/12/31 职场文书
电影红河谷观后感
2015/06/11 职场文书
2016年最美孝心少年事迹材料
2016/02/26 职场文书
Django模型层实现多表关系创建和多表操作
2021/07/21 Python