最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
Pytorch之contiguous如何用 Pytorch之contiguous用法解析
时间:2019-12-31 编辑:袖梨 来源:一聚教程网
本篇文章小编给大家分享一下Pytorch之contiguous用法解析,小编觉得挺不错的,现在分享给大家供大家参考,有需要的小伙伴们可以来看看。
contiguous
tensor变量调用contiguous()函数会使tensor变量在内存中的存储变得连续。
contiguous():view只能用在contiguous的variable上。如果在view之前用了transpose, permute等,需要用contiguous()来返回一个contiguous copy。
一种可能的解释是:
有些tensor并不是占用一整块内存,而是由不同的数据块组成,而tensor的view()操作依赖于内存是整块的,这时只需要执行contiguous()这个函数,把tensor变成在内存中连续分布的形式。
is_contiguous
判断是否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()
相关文章
- Golang ProtoBuf的基本语法详解 10-20
- Python识别MySQL中的冗余索引解析 10-20
- Python+Pygame绘制小球代码展示 10-18
- Python中的数据精度问题介绍 10-18
- Python随机值生成的常用方法介绍 10-18
- python3解压缩.gz文件分析 09-27