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实现的多线程http压力测试代码
Feb 08 Python
Python实现计算两个时间之间相差天数的方法
May 10 Python
pandas.DataFrame 根据条件新建列并赋值的方法
Apr 08 Python
使用pandas中的DataFrame数据绘制柱状图的方法
Apr 10 Python
对web.py设置favicon.ico的方法详解
Dec 04 Python
Python 3.3实现计算两个日期间隔秒数/天数的方法示例
Jan 07 Python
python生成带有表格的图片实例
Feb 03 Python
Django Rest framework频率原理与限制
Jul 26 Python
Django项目基础配置和基本使用过程解析
Nov 25 Python
python shutil文件操作工具使用实例分析
Dec 25 Python
django序列化时使用外键的真实值操作
Jul 15 Python
python+selenium+chrome实现淘宝购物车秒杀自动结算
Jan 07 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
声音就能俘获人心,蕾姆,是哪个漂亮小姐姐配音呢?
2020/03/03 日漫
来自PHP.NET的入门教程
2006/10/09 PHP
php模拟socket一次连接,多次发送数据的实现代码
2011/07/26 PHP
php常用数组array函数实例总结【赋值,拆分,合并,计算,添加,删除,查询,判断,排序】
2016/12/07 PHP
Thinkphp开发--集成极光推送
2017/09/15 PHP
表头固定(利用jquery实现原理介绍)
2012/11/08 Javascript
js下拉框二级关联菜单效果代码具体实现
2013/08/03 Javascript
JS字符串截取函数实例
2013/12/27 Javascript
js实现获取焦点后光标在字符串后
2014/09/17 Javascript
jQuery实现表格行上移下移和置顶的方法
2015/05/22 Javascript
基于Node.js的JavaScript项目构建工具gulp的使用教程
2016/05/20 Javascript
Vue.js报错Failed to resolve filter问题的解决方法
2016/05/25 Javascript
Node.js的npm包管理器基础使用教程
2016/05/26 Javascript
BootStrap组件之进度条的基本用法
2017/01/19 Javascript
boostrapTable的refresh和refreshOptions区别浅析
2017/01/22 Javascript
用纯Node.JS弹出Windows系统消息提示框实例(MessageBox)
2017/05/17 Javascript
微信小程序http连接访问解决方案的示例
2018/11/05 Javascript
[01:15:44]首部DOTA2纪录片今日23时全网上映
2014/03/19 DOTA
Python的面向对象思想分析
2015/01/14 Python
在Python中使用CasperJS获取JS渲染生成的HTML内容的教程
2015/04/09 Python
Python语言实现获取主机名根据端口杀死进程
2016/03/31 Python
浅析Python3爬虫登录模拟
2018/02/07 Python
Python文本处理之按行处理大文件的方法
2018/04/09 Python
Python通过调用有道翻译api实现翻译功能示例
2018/07/19 Python
Python3 利用face_recognition实现人脸识别的方法
2020/03/13 Python
pycharm下配置pyqt5的教程(anaconda虚拟环境下+tensorflow)
2020/03/25 Python
pandas.DataFrame.drop_duplicates 用法介绍
2020/07/06 Python
Python远程linux执行命令实现
2020/11/11 Python
详解Python中list[::-1]的几种用法
2020/11/16 Python
Html5中localStorage存储JSON数据并读取JSON数据的实现方法
2017/02/13 HTML / CSS
中学生团员自我评价分享
2013/12/07 职场文书
党员批评与自我批评
2014/10/15 职场文书
鸟的天堂导游词
2015/01/31 职场文书
2016反腐倡廉警示教育心得体会
2016/01/13 职场文书
mysql5.7使用binlog 恢复数据的方法
2021/06/03 MySQL
CSS中Single Div 绘图技巧的实现
2021/06/18 HTML / CSS