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 ...
随机推荐
- API - 使用数据仓库 - 基础篇
数据仓库是集成在Spider Studio中的一个重要功能, 利用它可以非常方便的保存采集到的数据, 然后导出或者在其他脚本中再利用. 数据仓库的全部功能都集成在DataManager这个静态类里面, ...
- adb not responding的解决方案
查看谁占用了进程:netstat -aon|findstr "5037" 终止占用的进程: 假若"6908"占用了进程 taskkill /pid 6908 / ...
- [插件] 如何在一个页面中使用多个SWFUpload对象上传文件
首先需要引入相应的样式和JS文件,还需要借助jQuery的js 提供下载路径:http://pan.baidu.com/s/1EUzca ① 引入js <script type="te ...
- jquery -- 触屏设备touch事件
几种普及得比较好的触摸事件,你可以在绝大多数现代浏览器中来测试这一事件(必须是触屏设备哦): touchstart:触摸开始的时候触发 touchmove:手指在屏幕上滑动的时候触发 touchend ...
- WORD里怎样能做到局部“分栏”就是一页里有的分有的不分
选中你要分的部分再分栏如果不想分的部分也被分了,那就可以选中不想分的那部分,选择“分栏”->“一栏” 转自:http://zhidao.baidu.com/question/9873268.ht ...
- MFC存储图片到SQL Server数据库
第一步:建立数据库表,比如:id char,pic image. 第二步:建立MFC单文档应用程序,再添加类CMyRecordset,基类选择CRecordset,导入数据库的刚建立的表. 第三步:在 ...
- Swig 使用指南 (express模板)
如何使用 API swig.init({ allowErrors: false, autoescape: true, cache: true, encoding: 'utf8', filters: { ...
- Angular 表单(二) - 模板驱动表单
import { Component, OnInit } from '@angular/core'; import { Hero} from '../hero'; @Component({ selec ...
- 程序阅读:简单C++学生信息管理系统
课程首页在:http://blog.csdn.net/sxhelijian/article/details/11890759,内有完整教学方案及资源链接 [程序阅读]阅读并执行以下的程序,找出当中出现 ...
- Spring_day04--SSH框架整合过程
SSH框架整合过程 第一步 导入jar包 第二步 搭建struts2环境 (1)创建action,创建struts.xml配置文件,配置action (2)配置struts2的过滤器 第三步 搭建hi ...