【PyTorch】 转换张量的数据类型
; 1、背景
Pytorch的tensor数据类型转换方法:
使用独立的函数如 int(),float()等进行转换;
使用torch.type()函数,直接显示输入需要转换的类型;
使用type_as()函数,将该tensor转换为另一个tensor的type;
2、独立的函数转换数据类型
常用的如下:
数据类型转化 torch_tensor.dtype torch_tensor.type() torch_tensor.double() torch.float64 torch.DoubleTensor 或 torch.cuda.DoubleTensor torch_tensor.float() torch.float32 torch.FloatTensor 或 torch.cuda.FloatTensor torch_tensor.half() torch.float16 torch.HalfTensor 或 torch.cuda.HalfTensor
Original: https://blog.csdn.net/jn10010537/article/details/121408740
Author: jn10010537
Title: 【PyTorch】 转换张量的数据类型
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/514728/
转载文章受原作者版权保护。转载请注明原作者出处!