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 UnicodeEncodeError: 'gbk' codec can't encode character 解决方法
Apr 24 Python
python图片验证码生成代码
Jul 02 Python
详解Python之数据序列化(json、pickle、shelve)
Mar 30 Python
Python实现的计算马氏距离算法示例
Apr 03 Python
python使用tornado实现登录和登出
Jul 28 Python
详解python调用cmd命令三种方法
Jul 08 Python
Python下利用BeautifulSoup解析HTML的实现
Jan 17 Python
django 读取图片到页面实例
Mar 27 Python
手把手教你如何用Pycharm2020.1.1配置远程连接的详细步骤
Aug 07 Python
简述 Python 的类和对象
Aug 21 Python
python 如何利用argparse解析命令行参数
Sep 11 Python
如何在Python项目中引入日志
May 31 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发送post请求的三种方法
2014/02/11 PHP
浅析PHP的静态成员函数效率更高的原因
2014/06/13 PHP
js 有框架页面跳转(target)三种情况下的应用
2013/04/09 Javascript
JS实现随机数生成算法示例代码
2013/08/08 Javascript
jQuery关于导航条背景切换效果实现示例
2013/09/04 Javascript
jQuery操作DOM之获取表单控件的值
2015/01/23 Javascript
js的toLowerCase方法用法实例
2015/01/27 Javascript
EasyUI中datagrid在ie下reload失败解决方案
2015/03/09 Javascript
JS实现按比例缩放图片的方法(附C#版代码)
2015/12/08 Javascript
jQuery给div,Span, a ,button, radio 赋值与取值
2016/06/24 Javascript
简单实现AngularJS轮播图效果
2020/04/10 Javascript
jQuery使用each遍历循环的方法
2018/09/19 jQuery
axios使用拦截器统一处理所有的http请求的方法
2018/11/02 Javascript
vue spa应用中的路由缓存问题与解决方案
2019/05/31 Javascript
通过Kettle自定义jar包供javascript使用
2020/01/29 Javascript
CKEditor扩展插件:自动排版功能autoformat插件实现方法详解
2020/02/06 Javascript
JS 逻辑判断不要只知道用 if-else 和 switch条件判断(小技巧)
2020/05/27 Javascript
原生js实现html手机端城市列表索引选择城市
2020/06/24 Javascript
Vue proxyTable配置多个接口地址,解决跨域的问题
2020/09/11 Javascript
python实现批量监控网站
2016/09/09 Python
django的settings中设置中文支持的实现
2019/04/28 Python
pyqt5 使用label控件实时显示时间的实例
2019/06/14 Python
解决python文件双击运行秒退的问题
2019/06/24 Python
Pandas之ReIndex重新索引的实现
2019/06/25 Python
Python3交互式shell ipython3安装及使用详解
2020/07/11 Python
pip install命令安装扩展库整理
2021/03/02 Python
数字天堂软件测试面试题
2012/12/23 面试题
Servlet都有哪些方法?主要作用是什么?
2014/03/04 面试题
应届行政管理专业个人自我评价
2013/12/28 职场文书
统计系教授推荐信
2014/02/28 职场文书
教师党员个人自我评价
2015/03/04 职场文书
2016入党积极分子心得体会
2016/01/06 职场文书
《开国大典》教学反思
2016/02/16 职场文书
《分数乘法》教学反思
2016/02/24 职场文书
再见,2019我们不负使命;你好,2020我们砥砺前行
2020/01/03 职场文书
微信小程序结合ThinkPHP5授权登陆后获取手机号
2021/11/23 PHP