Pytorch
风度丶
这个作者很懒,什么都没留下…
展开
-
Pytorch中经常见到的View( )函数
Pytorch里经常会见到tensor.view( a, b ,c ......),a, b, c等等都是函数内的参数,可以理解为reshape功能,重构张量的维度。比如:a = torch.Tensor(2, 3)print(a)# tensor([[0.0000, 0.0000, 0.0000],# [0.0000, 0.0000, 0.0000]])b = a.view(3, 2)print(b)# tensor([[0.0000, 0.0000],# ...原创 2021-07-08 10:27:31 · 2484 阅读 · 0 评论 -
Pytorch中tensor与numpy类型数据在GPU和CPU之间的转换
1. CPU tensor转GPU tensor:cpu_imgs.cuda()2. GPU tensor 转CPU tensor:gpu_imgs.cpu()3. numpy转为CPU tensor:torch.from_numpy( imgs )4.CPU tensor转为numpy数据:cpu_imgs.numpy()5. note:GPU tensor不能直接转为numpy数组,必须先转到CPU tensor。6. 如果tensor是标量的话,可以直接使用 i转载 2021-06-28 14:55:04 · 2190 阅读 · 0 评论