pytorch系统默认的数据类型是32位浮点型torch.float32,整型默认的是64位整型torch.int64。
pytorch一共支持9中数据类型。
dtype属性 cpu gpu
32位浮点型:torch.float32或torch.float torch.FloatTensor torch.cuda.FloatTensor
64位浮点型:torch.float64或torch.double torch.DoubleTensor torch.cuda.DoubleTensor
16位浮点型:torch.float16或torch.half torch.HalfTensor torch.cuda.HalfTensor 8无符号整型:torch.uint8 torch.ByteTensor torch.cuda.ByteTensor
8整型: torch.int8 torch.CharTensor torch.cuda.CharTensor
16位整型: torch.int16或torch.short torch.ShortTensor torch.cuda.ShortTensor
32位整型: torch.int32或torch.int torch.IntTensor torch.cuda.IntTensor
64位整型: torch.int64或torch.long torch.LongTensor torch.LongTensor
布尔型: torch.bool torch.BoolTensor(1.2版后弃用) torch.cuda.BoolTensor(1.2版后弃用)
#8无符号整型:torch.uint8通常用于存储像素值、二进制图像或其他在像素级别上表示的数据。由于它是无符号类型,因此它的取值范围是从0到255。
#在 PyTorch 1.2 版本之后,torch.BoolTensor和torch.cuda.BoolTensor 张量类型已经被弃用了。实际上,从 PyTorch 1.0 版本开始,所有的张量
类型都被整合到了torch.Tensor 类型中。