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 struct.unpack
Sep 06 Python
Python中用Spark模块的使用教程
Apr 13 Python
深入剖析Python的爬虫框架Scrapy的结构与运作流程
Jan 20 Python
python遍历文件夹,指定遍历深度与忽略目录的方法
Jul 11 Python
Python实现注册、登录小程序功能
Sep 21 Python
PyTorch 1.0 正式版已经发布了
Dec 13 Python
Python实现简单石头剪刀布游戏
Jan 20 Python
使用python画社交网络图实例代码
Jul 10 Python
Django ORM多对多查询方法(自定义第三张表&ManyToManyField)
Aug 09 Python
python使用matplotlib绘制雷达图
Oct 18 Python
Python实现常见的几种加密算法(MD5,SHA-1,HMAC,DES/AES,RSA和ECC)
May 09 Python
Python机器学习工具scikit-learn的使用笔记
Jan 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中获取系统信息的方法
2013/06/25 PHP
php图像处理函数大全(推荐收藏)
2013/07/11 PHP
Laravel5.4框架使用socialite实现github登录的方法
2019/03/20 PHP
JavaScript 函数参数是传值(byVal)还是传址(byRef) 分享
2013/07/02 Javascript
Js(JavaScript)中,弹出是或否的选择框示例(confirm用法的实例分析)
2013/07/09 Javascript
jQuery Animation实现CSS3动画示例介绍
2013/08/14 Javascript
JS+CSS 制作的超级简单的下拉菜单附图
2013/11/22 Javascript
JavaScript中的console.trace()函数介绍
2014/12/29 Javascript
全面解析jQuery $(document).ready()和JavaScript onload事件
2016/06/08 Javascript
AngularJs bootstrap搭载前台框架——准备工作
2016/09/01 Javascript
懒加载实现的分页&&网站footer自适应
2016/12/21 Javascript
ES6概念 Symbol.keyFor()方法
2016/12/25 Javascript
Bootstrap Fileinput 4.4.7文件上传实例详解
2018/07/25 Javascript
VUE+Element UI实现简单的表格行内编辑效果的示例的代码
2018/10/31 Javascript
vue中使用codemirror的实例详解
2018/11/01 Javascript
关于layui 实现点击按钮添加一行(方法渲染创建的table)
2019/09/29 Javascript
微信小程序开发(二):页面跳转并传参操作示例
2020/06/01 Javascript
[01:02:17]2014 DOTA2华西杯精英邀请赛 5 24 DK VS VG
2014/05/26 DOTA
python ElementTree 基本读操作示例
2009/04/09 Python
用Python实现一个简单的线程池
2015/04/07 Python
Python多线程爬虫简单示例
2016/03/04 Python
Python实现购物车购物小程序
2018/04/18 Python
Python使用min、max函数查找二维数据矩阵中最小、最大值的方法
2018/05/15 Python
Python脚本修改阿里云的访问控制列表的方法
2019/03/08 Python
使用python实现kNN分类算法
2019/10/16 Python
Python如何使用argparse模块处理命令行参数
2019/12/11 Python
python 元组的使用方法
2020/06/09 Python
英国第一家领先的在线处方眼镜零售商:Glasses Direct
2018/02/23 全球购物
Bibloo罗马尼亚网站:女装、男装、童装及鞋子和配饰
2019/07/20 全球购物
维修工先进事迹
2014/05/29 职场文书
单位活动策划方案
2014/08/17 职场文书
幼儿园六一亲子活动方案
2014/08/26 职场文书
2015年复活节活动总结
2015/02/27 职场文书
投资申请报告
2015/05/19 职场文书
《水上飞机》教学反思
2016/02/20 职场文书
《文化苦旅》读后感:阅读,让人诗意地栖居在大地上
2019/12/24 职场文书