热门
最新
红包
立Flag
投票
同城
我的
发布
view函数只能由于contiguous的张量上,具体而言,就是在内存中连续存储的张量。
具体而言,可以参看https://blog.csdn.net/qq_37385726/article/details/81811254
所以,当tensor之前调用了transpose, permute函数就会是tensor内存中变得不再连续,就不能调用view函数。
所以,应该提前做tensor.contiguous()的操作
————————————————
reshape函数调用是不依赖于tensor在内存中是不是连续的。
即
reshape ≈ tensor.contiguous().view
---------------------------------------------
torch.Tensor.view_as(other) → Tensor
返回的 tensor 与 other 的 size 相同,即构造一个与 other 相同维度的新 tensor。相当于 self.view(other.size()) 的效果。
CSDN App 扫码分享
评论
点赞
打赏
- 复制链接
- 举报