一.数据类型转换
1.pytorch的tensor类型转numpy类型
numpy类型数据=tensor类型数据.numpy()
2.numpy类型转pytorch的tensor类型
tensor类型数据=torch.from_numpy(numpy类型数据)
3.python的list类型转pytorch的tensor类型
暂时还没有遇到
4.pytorch的tensor类型转python的list类型
tensor类型数据=torch.Tensor(list类型数据)
5.numpy的array转python的list类型
list类型数据=(numpy的array类型数据).tolist()
list类型数据=list(numpy的array类型数据)
6.python的list类型转numpy的array
numpy的array类型数据=numpy.array(list类型数据)
7.tensor数据类型的device由cpu转cuda
tensor(cpu中数据)=tensor类型数据.cpu()
8.tensor数据类型的device由cuda转cpu
tensor(cuda中数据)=tensor类型数据.cuda()
二.数据维度
1.图像image,[1, 3, 500, 355] - - - > [3, 500, 355],对数据维度进行压缩
image = image[0]
2.图像image,[3, 500, 355] - - - > [1, 3, 500, 355],对数据维度进行扩充
image = image.unsqueenze_()
3.判断python的list类型数据,指定维度的长度
len(list类型数据[0])
三.一些错误
1.Torch.from_numpy not support negative strides
Torch.from_numpy(data..copy())
参考
[1].Pytorch中的variable, tensor与numpy相互转化的方法
[2].list转torch tensor
[3].[numpy] ndarray 与 list 互相转换
[4].python判断list是否为空
[5].对Pytorch张量tensor数据类型的理解