Pytorch permute,contiguous
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的更多相关文章
- 连续张量理解和contiguous()方法使用,view和reshape的区别
连续张量理解和contiguous()方法使用,view和reshape的区别 待办 内存共享: 下边的x内存布局是从0开始的,y内存布局,不是从0开始的张量 For example: when yo ...
- [转载]PyTorch上的contiguous
[转载]PyTorch上的contiguous 来源:https://zhuanlan.zhihu.com/p/64551412 这篇文章写的非常好,我这里就不复制粘贴了,有兴趣的同学可以去看原文,我 ...
- pytorch contiguous的使用
contiguous一般与transpose,permute,view搭配使用 即使用transpose或permute进行维度变换后,调用contiguous,然后方可使用view对维度进行变形. ...
- [转载]PyTorch中permute的用法
[转载]PyTorch中permute的用法 来源:https://blog.csdn.net/york1996/article/details/81876886 permute(dims) 将ten ...
- pytorch中的cat、stack、tranpose、permute、unsqeeze
Cat 对数据沿着某一维度进行拼接.cat后数据的总维数不变. 比如下面代码对两个2维tensor(分别为2*3,1*3)进行拼接,拼接完后变为3*3还是2维的tensor. import torch ...
- 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 ...
- Pytorch学习笔记(二)---- 神经网络搭建
记录如何用Pytorch搭建LeNet-5,大体步骤包括:网络的搭建->前向传播->定义Loss和Optimizer->训练 # -*- coding: utf-8 -*- # Al ...
- Pytorch版本yolov3源码阅读
目录 Pytorch版本yolov3源码阅读 1. 阅读test.py 1.1 参数解读 1.2 data文件解析 1.3 cfg文件解析 1.4 根据cfg文件创建模块 1.5 YOLOLayer ...
- PyTorch Notes | PyTorch 编程实践笔记
[ 今天最开心的事情! ] PyTorch的stable版本更新为1.0之后,原本3D模型无脑out of memory.3D模型torch.backends.cudnn.benchmark必须Fal ...
随机推荐
- 修改多渠道打包的App名
archiveNameFormat = '${flavorName}-${projectName}-${versionName}-${versionCode}'
- 多媒体开发之rtsp---rtsp client 端的实现
http://blog.csdn.net/xyz_lmn/article/details/6055179 java实现 http://www.cnblogs.com/wohexiaocai/p/454 ...
- Linux JAVA 配置
wget http://download.oracle.com/otn-pub/java/jdk/7u25-b15/jdk-7u25-linux-x64.tar.gz tar zxvf jdk-7u2 ...
- ChemDraw使用不了怎么办
ChemDraw作为一款专业级的化学绘图软件,不仅可以帮助用户绘制图像在数据计算方面也起了很大作用,因此,ChemDraw非常受用户的欢迎.但是我们在使用过程中难免会遇到各种问题,特别是对于新手用户, ...
- Nginx配置里的fastcgi_index和index
在配置nginx时有时会遇到, 所以记录一下 location ^~ /wechat/ { index index.php; fastcgi_pass 127.0.0.1:9000; fastcgi_ ...
- Linq------错误:EntityType: EntitySet 'Products' is based on type 'Product' that has no keys defined.
解决方法: [Table("bma_products")] public class Product { //加上[Key]即可 [Key] public int pid{get; ...
- POJ 2567 Code the Tree & POJ 2568 Decode the Tree Prufer序列
题目大意:2567是给出一棵树,让你求出它的Prufer序列.2568时给出一个Prufer序列,求出这个树. 思路:首先要知道Prufer序列.对于随意一个无根树,每次去掉一个编号最小的叶子节点,并 ...
- UE4插件
源代码中包含一些插件例子 C:\Program Files\Epic Games\UE_4.15\Engine\Plugins\Developer 一下截图来自官网https://docs.unrea ...
- DOM API querySelector与querySelectorAll的用法
DOM API querySelector与querySelectorAll的用法: http://www.qttc.net/201309371.html querySelectorAll与quer ...
- docker-compose 部署 selenium-grid
目录 一.安装Docker 二.安装Docker-Compose库 三.准备docker-compose.yaml文件 四.运行 上篇:详细介绍selenium-grid 一.安装Docker 必须要 ...