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常用列表数据结构小结
Aug 06 Python
python使用xmlrpclib模块实现对百度google的ping功能
Jun 02 Python
Python实现求数列和的方法示例
Jan 12 Python
使用实现pandas读取csv文件指定的前几行
Apr 20 Python
谈谈Python中的while循环语句
Mar 10 Python
python各类经纬度转换的实例代码
Aug 08 Python
简单了解Django ORM常用字段类型及参数配置
Jan 07 Python
使用tensorboard可视化loss和acc的实例
Jan 21 Python
Tensorflow 多线程设置方式
Feb 06 Python
git查看、创建、删除、本地、远程分支方法详解
Feb 18 Python
python中使用.py配置文件的方法详解
Nov 23 Python
深入理解Pytorch微调torchvision模型
Nov 11 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 无线电
PHP 字符串 小常识
2009/06/05 PHP
php汉字转拼音的示例
2014/02/27 PHP
PHP开发微信支付的代码分享
2014/05/25 PHP
使用Thinkphp框架开发移动端接口
2015/08/05 PHP
Codeigniter里的无刷新上传的实现代码
2019/04/14 PHP
laravel 验证错误信息到 blade模板的方法
2019/09/29 PHP
Jquery Ajax学习实例7 Ajax所有过程事件分析示例
2010/03/23 Javascript
js语法学习之判断一个对象是否为数组
2014/05/13 Javascript
JS基于面向对象实现的放烟花效果
2015/05/07 Javascript
jquery仿百度百科底部浮动导航特效
2015/08/08 Javascript
javascript实现在下拉列表中显示多级树形菜单的方法
2015/08/12 Javascript
Jqgrid之强大的表格插件应用
2015/12/02 Javascript
JS Array创建及concat()split()slice()的使用方法
2016/06/03 Javascript
浅析JS获取url中的参数实例代码
2016/06/14 Javascript
Vuejs第八篇之Vuejs组件的定义实例解析
2016/09/05 Javascript
React创建组件的三种方式及其区别
2017/01/12 Javascript
动态Axios的配置步骤详解
2018/01/12 Javascript
解决vue2中使用axios http请求出现的问题
2018/03/05 Javascript
Layui组件Table绑定行点击事件和获取行数据的方法
2018/08/19 Javascript
JavaScript对JSON数组简单排序操作示例
2019/01/31 Javascript
Vue表单控件绑定图文详解
2019/02/11 Javascript
Python实现账号密码输错三次即锁定功能简单示例
2019/03/29 Python
python 使用turtule绘制递归图形(螺旋、二叉树、谢尔宾斯基三角形)
2019/05/30 Python
python利用re,bs4,requests模块获取股票数据
2019/07/29 Python
Python 利用高德地图api实现经纬度与地址的批量转换
2019/08/14 Python
Python迷宫生成和迷宫破解算法实例
2019/12/24 Python
Python 实现图片转字符画的示例(静态图片,gif皆可)
2020/11/05 Python
python中实现词云图的示例
2020/12/19 Python
HTML5中canvas中的beginPath()和closePath()的重要性
2018/08/24 HTML / CSS
使用HTML5做个画图板的方法介绍
2013/05/03 HTML / CSS
如何在存储过程中使用Loop
2016/01/05 面试题
党员民主评议自我评价
2014/10/20 职场文书
项目安全员岗位职责
2015/02/15 职场文书
解析Java中的static关键字
2021/06/14 Java/Android
Python办公自动化解决world文件批量转换
2021/09/15 Python