permute(dims),常用的维度转换方法

将tensor的维度换位      参数:dim(int)---换位顺序

>>>x = torch.randn(2,3,5)
>>>x.size()
torch.size([2,3,5])
>>>x.permute(2,0,1).size()
torch.size([5,2,3])

contiguous()

contiguous:view只能用在contiguous的variable上。如果在view之前用了transpose, permute等,需要用contiguous()来返回一个contiguous copy。
一种可能的解释是:
有些tensor并不是占用一整块内存,而是由不同的数据块组成,而tensor的view()操作依赖于内存是整块的,这时只需要执行contiguous()这个函数,把tensor变成在内存中连续分布的形式。
判断是否contiguous用torch.Tensor.is_contiguous()函数。

import torch
x = torch.ones(10, 10)
x.is_contiguous() # True
x.transpose(0, 1).is_contiguous() # False
x.transpose(0, 1).contiguous().is_contiguous() # True

在pytorch的最新版本0.4版本中,增加了torch.reshape(), 这与 numpy.reshape 的功能类似。它大致相当于 tensor.contiguous().view()

Pytorch permute,contiguous的更多相关文章

  1. 连续张量理解和contiguous()方法使用,view和reshape的区别

    连续张量理解和contiguous()方法使用,view和reshape的区别 待办 内存共享: 下边的x内存布局是从0开始的,y内存布局,不是从0开始的张量 For example: when yo ...

  2. [转载]PyTorch上的contiguous

    [转载]PyTorch上的contiguous 来源:https://zhuanlan.zhihu.com/p/64551412 这篇文章写的非常好,我这里就不复制粘贴了,有兴趣的同学可以去看原文,我 ...

  3. pytorch contiguous的使用

    contiguous一般与transpose,permute,view搭配使用 即使用transpose或permute进行维度变换后,调用contiguous,然后方可使用view对维度进行变形. ...

  4. [转载]PyTorch中permute的用法

    [转载]PyTorch中permute的用法 来源:https://blog.csdn.net/york1996/article/details/81876886 permute(dims) 将ten ...

  5. pytorch中的cat、stack、tranpose、permute、unsqeeze

    Cat 对数据沿着某一维度进行拼接.cat后数据的总维数不变. 比如下面代码对两个2维tensor(分别为2*3,1*3)进行拼接,拼接完后变为3*3还是2维的tensor. import torch ...

  6. pytorch之expand,gather,squeeze,sum,contiguous,softmax,max,argmax

    目录 gather squeeze expand sum contiguous softmax max argmax gather torch.gather(input,dim,index,out=N ...

  7. Pytorch学习笔记(二)---- 神经网络搭建

    记录如何用Pytorch搭建LeNet-5,大体步骤包括:网络的搭建->前向传播->定义Loss和Optimizer->训练 # -*- coding: utf-8 -*- # Al ...

  8. Pytorch版本yolov3源码阅读

    目录 Pytorch版本yolov3源码阅读 1. 阅读test.py 1.1 参数解读 1.2 data文件解析 1.3 cfg文件解析 1.4 根据cfg文件创建模块 1.5 YOLOLayer ...

  9. PyTorch Notes | PyTorch 编程实践笔记

    [ 今天最开心的事情! ] PyTorch的stable版本更新为1.0之后,原本3D模型无脑out of memory.3D模型torch.backends.cudnn.benchmark必须Fal ...

随机推荐

  1. java---正则表达式的字符串简单实用及扩展链接

    一:什么是正则表达式 1.定义:正则表达式是一种可以用于模式匹配和替换的规范,一个正则表达式就是由普通的字符(例如字符a到z)以及特殊字符(元字符)组成的文字模式,它 用以描述在查找文字主体时待匹配的 ...

  2. 【Cubian】set up

    源: http://mirrors.163.com/.help/debian.html https://lug.ustc.edu.cn/wiki/mirrors/help/debian 下载地址: h ...

  3. WPF DataGrid DataGridTemplateColumn 控制模板中控件

    <DataGrid Name="DG">                <DataGrid.Columns>                    < ...

  4. UIWindow小记

    If you choose to create a window in Interface Builder, be sure to select the Full Screen at Launch o ...

  5. Node.js的全局对象和全局变量

    http://blog.csdn.net/leftfist/article/details/41877279

  6. nyoj1237 最大岛屿(河南省第八届acm程序设计大赛)

    题目1237 pid=1237" style="color:rgb(55,119,188)">题目信息 执行结果 本题排行 讨论区 最大岛屿 时间限制:1000 m ...

  7. ViewPageIndicator

    关于我的总结 1.写一个类extend HorizontalScrollView 实现ViewPagerIndicator,这样写index需要自己写有点啰嗦 2.自定义一个类extends Hori ...

  8. webpack 报错 path is not defind

    webpack.config.js里的内容是这样的,注意标红的地方: 首先,绝对路径'./dist'是 没有问题的 那么,查了很多,最后看到别人的webpack.config.js里面这样写着,现在c ...

  9. Django学习笔记第一篇--Hello,Django

    一.Django的安装: 1.python虚拟运行的环境的安装以及安装django: sudo pip install virtualenv export VIRTUALENV_DISTRINUTR= ...

  10. ORACLE WITH AS 用法,创建临时表

    语法: with tempName as (select ....) select ... –针对一个别名with tmp as (select * from tb_name) –针对多个别名with ...