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负载均衡的简单实现方法
Feb 04 Python
Python3之简单搭建自带服务器的实例讲解
Jun 04 Python
可能是最全面的 Python 字符串拼接总结【收藏】
Jul 09 Python
Python3 安装PyQt5及exe打包图文教程
Jan 08 Python
Python中整数的缓存机制讲解
Feb 16 Python
python3+PyQt5 自定义窗口部件--使用窗口部件样式表的方法
Jun 26 Python
Pytorch: 自定义网络层实例
Jan 07 Python
tensorflow 保存模型和取出中间权重例子
Jan 24 Python
python烟花效果的代码实例
Feb 25 Python
python 读取、写入txt文件的示例
Sep 27 Python
Pycharm中使用git进行合作开发的教程详解
Nov 17 Python
Python实现文字pdf转换图片pdf效果
Apr 03 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 include的妙用,实现路径加密
2008/07/29 PHP
php用ini_get获取php.ini里变量值的方法
2015/03/04 PHP
php使用变量动态创建类的对象用法示例
2017/02/06 PHP
PHP 无限级分类
2017/05/04 PHP
php实现的二叉树遍历算法示例
2017/06/15 PHP
js表数据排序 sort table data
2009/02/18 Javascript
jquery attr 设定src中含有&(宏)符号问题的解决方法
2011/07/26 Javascript
用javascript替换URL中的参数值示例代码
2014/01/27 Javascript
JS使用for循环遍历Table的所有单元格内容
2014/08/21 Javascript
jQuery中replaceWith()方法用法实例
2014/12/25 Javascript
JS使用正则表达式除去字符串中重复字符的方法
2015/11/05 Javascript
每天一篇javascript学习小结(RegExp对象)
2015/11/17 Javascript
jQuery 全选 全部选 反选 实现代码
2016/08/17 Javascript
JavaScript数组去重由慢到快由繁到简(优化篇)
2016/08/26 Javascript
Bootstrap基本插件学习笔记之轮播幻灯片(23)
2016/12/08 Javascript
canvas实现爱心和彩虹雨效果
2017/03/09 Javascript
es6的数字处理的方法(5个)
2017/03/16 Javascript
Angularjs cookie 操作实例详解
2017/09/27 Javascript
js判断文件类型大小并给出提示的实现方法
2018/01/03 Javascript
详解webpack4升级指南以及从webpack3.x迁移
2018/06/12 Javascript
解决layui中table异步数据请求不支持自定义返回数据格式的问题
2018/08/19 Javascript
解决vue项目中某一页面不想引用公共组件app.vue的问题
2020/08/14 Javascript
浅谈鸿蒙 JavaScript GUI 技术栈
2020/09/17 Javascript
使用Python的Scrapy框架编写web爬虫的简单示例
2015/04/17 Python
Python中str is not callable问题详解及解决办法
2017/02/10 Python
Python、PyCharm安装及使用方法(Mac版)详解
2017/04/28 Python
Python与人工神经网络:使用神经网络识别手写图像介绍
2017/12/19 Python
python批量下载网站马拉松照片的完整步骤
2018/12/05 Python
python整合ffmpeg实现视频文件的批量转换
2019/05/31 Python
北大青鸟学生求职信
2013/09/24 职场文书
税务干部鉴定材料
2014/02/11 职场文书
2014年班主任自我评价范文
2014/04/23 职场文书
党员个人公开承诺书
2014/08/29 职场文书
先进工作者推荐材料
2014/12/23 职场文书
餐饮服务食品安全承诺书
2015/04/29 职场文书
javascript条件式访问属性和箭头函数介绍
2021/11/17 Javascript