Pytorch tensor 数据类型快速转换三种方法
最佳答案 问答题库728位专家为你答疑解惑
目录
1 通用,简单,CPU/GPU tensor 数据类型转换
2 tensor.type()方法
CPU tensor 数据类型转换
GPU tensor 数据类型转换
3 tensor.to() 方法,CPU/GPU tensor 数据类型转换
1 通用,简单, CPU/GPU tensor 数据类型转换
tensor.double():把一个张量tensor转为torch.float64 数据类型
tensor.float():把一个张量tensor转为torch.float32 数据类型
tensor.int():把一个张量tensor转为torch.int32 数据类型
tensor.long(): 把一个张量tensor转为torch.int64 数据类型
2 tensor.type()方法
CPU tensor 数据类型转换
tensor.type(torch.DoubleTensor) 或者 tensor.type(‘torch.DoubleTensor’)
tensor.type(torch.FloatTensor) 或者 tensor.type('torch.FloatTensor')
tensor.type(torch.LongTensor) 或者 tensor.type('torch.LongTensor')
GPU tensor 数据类型转换
tensor.type(torch.cuda.DoubleTensor) 或者 tensor.type(‘torch.cuda.DoubleTensor’)
tensor.type(torch.cuda.FloatTensor) 或者 tensor.type('torch.cuda.FloatTensor')
tensor.type(torch.cuda.LongTensor) 或者 tensor.type('torch.cuda.LongTensor')
3 tensor.to() 方法, CPU/GPU tensor 数据类型转换
tensor.to(dtype=torch.float64)
tensor.to(dtype=torch.float32)
tensor.to(dtype=torch.int8)
tensor.to(dtype=torch.long)
99%的人还看了
相似问题
猜你感兴趣
版权申明
本文"Pytorch tensor 数据类型快速转换三种方法":http://eshow365.cn/6-34365-0.html 内容来自互联网,请自行判断内容的正确性。如有侵权请联系我们,立即删除!