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 18 Python
Python实现根据指定端口探测服务器/模块部署的方法
Aug 25 Python
Python中处理字符串的相关的len()方法的使用简介
May 19 Python
python实现爬虫统计学校BBS男女比例之多线程爬虫(二)
Dec 31 Python
Python的Tornado框架的异步任务与AsyncHTTPClient
Jun 27 Python
Python排序搜索基本算法之冒泡排序实例分析
Dec 09 Python
详解python中的线程
Feb 10 Python
Python向Excel中插入图片的简单实现方法
Apr 24 Python
Python开发网站目录扫描器的实现
Feb 21 Python
Python+PyQT5的子线程更新UI界面的实例
Jun 14 Python
浅谈keras通过model.fit_generator训练模型(节省内存)
Jun 17 Python
python实现腾讯滑块验证码识别
Apr 27 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
海河写的 Discuz论坛帖子调用js的php代码
2007/08/23 PHP
Linux下CoreSeek及PHP扩展模块的安装
2012/09/23 PHP
php合并js请求的例子
2013/11/01 PHP
PHP获取文件扩展名的4种方法
2015/11/24 PHP
javascript 表格排序和表头浮动效果(扩展SortTable)
2009/04/07 Javascript
js中单引号与双引号冲突问题解决方法
2013/10/04 Javascript
基于jquery实现左右按钮点击的图片切换效果
2021/01/27 Javascript
jQuery四种选择器使用及示例
2016/06/05 Javascript
JS上传图片预览插件制作(兼容到IE6)
2016/08/07 Javascript
Bootstrap 实现查询的完美方法
2016/10/26 Javascript
AngularJs 最新验证手机号码的实例,成功测试通过
2017/11/26 Javascript
详解vue-cli+es6引入es5写的js(两种方法)
2019/04/19 Javascript
微信小程序中显示倒计时代码实例
2019/05/09 Javascript
express框架下使用session的方法
2019/07/31 Javascript
vuex实现购物车功能
2020/06/28 Javascript
vue 解决addRoutes多次添加路由重复的操作
2020/08/04 Javascript
Python用GET方法上传文件
2015/03/10 Python
python并发编程之多进程、多线程、异步和协程详解
2016/10/28 Python
Python实现CAN报文转换工具教程
2020/05/05 Python
Django自关联实现多级联动查询实例
2020/05/19 Python
基于python模拟TCP3次握手连接及发送数据
2020/11/06 Python
python如何利用paramiko执行服务器命令
2020/11/07 Python
美国领先的家居装饰和礼品商店:Kirkland’s
2017/01/30 全球购物
澳大利亚吉他在线:Artist Guitars
2017/03/30 全球购物
Ooni英国官网:披萨烤箱
2020/05/31 全球购物
远程调用的原理
2014/07/05 面试题
电子商务专业在校生实习自我鉴定
2013/09/29 职场文书
弘扬职业精神演讲稿
2014/03/20 职场文书
法制报告会主持词
2014/04/02 职场文书
《二泉映月》教学反思
2014/04/15 职场文书
平面设计专业求职信
2014/08/09 职场文书
2014年作风建设心得体会
2014/10/22 职场文书
家庭聚会祝酒词
2015/08/11 职场文书
合理化建议书范文
2015/09/14 职场文书
只需要这一行代码就能让python计算速度提高十倍
2021/05/24 Python
Python日志模块logging用法
2022/06/05 Python