连续张量理解和contiguous()方法使用,view和reshape的区别
连续张量理解和contiguous()方法使用,view和reshape的区别
待办
内存共享:
下边的x内存布局是从0开始的,y内存布局,不是从0开始的张量
For example: when you call transpose(), PyTorch doesn't generate new tensor with new layout, it just modifies meta information in Tensor object so offset and stride are for new shape. The transposed tensor and original tensor are indeed sharing the memory!
^[
> x = torch.randn(3,2) y = torch.transpose(x, 0, 1) x[0, 0] = 42
> print(y[0,0])
> # prints 42
]
This is where the concept of contiguous comes in. Above x is contiguous but y is not because its memory layout is different than a tensor of same shape made from scratch. Note that the word "contiguous" is bit misleading because its not that the content of tensor is spread out around disconnected blocks of memory. Here bytes are still allocated in one block of memory but the order of the elements is different!
When you call contiguous(), it actually makes a copy of tensor so the order of elements would be same as if tensor of same shape created from scratch.
Normally you don't need to worry about this. If PyTorch expects contiguous tensor but if its not then you will get RuntimeError: input is not contiguous and then you just add a call to contiguous()
view 和 reshape 的区别
Another difference is that reshape() can operate on both contiguous
and non-contiguous tensor while view() can only operate on contiguous
tensor. Also see here about the meaning of contiguous.
如果出现不是连续张量的问题,解决方案
Another difference is that reshape() can operate on both contiguous
and non-contiguous tensor while view() can only operate on contiguous
tensor. Also see here about the meaning of contiguous.
连续张量理解和contiguous()方法使用,view和reshape的区别的更多相关文章
- (MTT)连续能量函数最小化方法
(MTT)连续能量函数最小化方法 Multitarget tracking Multi-object tracking 连续能量函数 读"A.Milan,S. Roth, K. Schind ...
- js中的回调函数的理解和使用方法
js中的回调函数的理解和使用方法 一. 回调函数的作用 js代码会至上而下一条线执行下去,但是有时候我们需要等到一个操作结束之后再进行下一个操作,这时候就需要用到回调函数. 二. 回调函数的解释 因为 ...
- 【JVM虚拟机】(8)--深入理解Class中--方法、属性表集合
#[JVM虚拟机](8)--深入理解Class中--方法.属性表集合 之前有关class文件已经写了两篇博客: 1.[JVM虚拟机](5)---深入理解JVM-Class中常量池 2.[JVM虚拟机] ...
- 理解 ES6 Generator-next()方法
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 【读书笔记《Android游戏编程之从零开始》】11.游戏开发基础(SurfaceView 游戏框架、View 和 SurfaceView 的区别)
1. SurfaceView 游戏框架实例 实例效果:就是屏幕上的文本跟着点击的地方移动,效果图如下: 步骤: 新建项目“GameSurfaceView”,首先自定义一个类"MySurfac ...
- View和ViewGroup的区别 -- Touch事件处理
View.java源码: /frameworks/base/core/java/android/view/View.java View.java的 dispatchTouchEvent 方法: 经过一 ...
- 从tcp原理角度理解Broken pipe和Connection reset by peer的区别
从tcp原理角度理解Broken pipe和Connection reset by peer的区别 http://lovestblog.cn/blog/2014/05/20/tcp-broken-pi ...
- Android界面的View以及ViewGroup的区别
因为这个问题会经常成为面试的热点,所以我们来谈谈View以及ViewGroup的区别. 先看看View及ViewGroup类关系 Android View和ViewGroup从组成架构上看,似乎 ...
- Python join() 方法与os.path.join()的区别
Python join() 方法与os.path.join()的区别 pythonJoinos.path.join 今天工作中用到python的join方法,有点分不太清楚join() 方法与os.p ...
随机推荐
- asp.net mvc 使用AuthorizeAttribute做授权验证
授权验证,比如登陆验证 1.自定义属性继承AuthorizeAttribute 2.重写OnAuthorization方法 3.通过AllowAnonymousAttribute特性处理无需授权的Ac ...
- 两种从 TensorFlow 的 checkpoint生成 frozenpb 的方法
1. 从 ckpt-.data,ckpt-.index 和 .meta 生成 frozenpb import os import tensorflow as tf from tensorflow.py ...
- # ConfigureAwait常见问题解答
原文: https://devblogs.microsoft.com/dotnet/configureawait-faq/ .NET 在七多年前在语言和类库添加了 async/await .在那个时候 ...
- MySQL概述及入门(三)
MySql概述及入门(三) MySQL性能优化 主要优化安全和性能方面 安全方面 : 数据可持续性 性能方面 : 数据的高性能访问 性能优化——慢查询 在MySQL数据库中有一个慢查询日志功能,去获取 ...
- 又一种获取redis cluster slots分布的小脚本
需要:昨晚学习了cluster slots命令,之前写的脚本,有可以换种方法获取到redis cluster slots 分布情况. cluster slots的结果如下: 4 5460 5.5.5. ...
- oracle 取某个时间的数据(每周几的上午几点到几点)
select count(*),t.分组字段 from (select t.* ,to_char(t.时间,'HH24') stime,to_char(t.时间,'HH24mi') fz,to_cha ...
- c#Socket通信基本使用
基本流程 Server private void btnStart_Click(object sender, EventArgs e) { try { //当点击开始监听时在服务器端创建一个负责监视I ...
- honeywell1900扫描枪的使用说明
霍尼韦尔1900扫描枪驱动是honeywell1900扫描枪的USB驱动,就是扫描枪usb转com,如果你的系统是32位的,就直接运行Install_x86.bat,如果是64位的,就运行Instal ...
- 生成随机数(C++)
// generate random number #include <iostream> #include <iomanip> #include <cstdlib> ...
- SpringBoot导出excel数据报错Could not find acceptable representation
转自:https://blog.csdn.net/mate_ge/article/details/93518286?utm_source=distribute.pc_relevant.none-tas ...