译者:阿远
每个 torch.Tensor
对象都有以下几个属性: torch.dtype
, torch.device
, 和 torch.layout
。
class torch.dtype
torch.dtype
属性标识了 torch.Tensor
的数据类型。PyTorch 有八种不同的数据类型:
Data type | dtype | Tensor types |
---|---|---|
32-bit floating point | torch.float32 or torch.float |
torch.*.FloatTensor |
64-bit floating point | torch.float64 or torch.double |
torch.*.DoubleTensor |
16-bit floating point | torch.float16 or torch.half |
torch.*.HalfTensor |
8-bit integer (unsigned) | torch.uint8 |
torch.*.ByteTensor |
8-bit integer (signed) | torch.int8 |
torch.*.CharTensor |
16-bit integer (signed) | torch.int16 or torch.short |
torch.*.ShortTensor |
32-bit integer (signed) | torch.int32 or torch.int |
torch.*.IntTensor |
64-bit integer (signed) | torch.int64 or torch.long |
torch.*.LongTensor |
class torch.device
torch.device
属性标识了torch.Tensor
对象在创建之后所存储在的设备名称,而在对象创建之前此属性标识了即将为此对象申请存储空间的设备名称。
torch.device
包含了两种设备类型 (‘cpu‘
或者 ‘cuda‘
) ,分别标识将Tensor对象储存于cpu内存或者gpu内存中,同时支持指定设备编号,比如多张gpu,可以通过gpu编号指定某一块gpu。 如果没有指定设备编号,则默认将对象存储于current_device()当前设备中; 举个例子, 一个torch.Tensor
对象构造函数中的设备字段如果填写‘cuda‘
,那等价于填写了‘cuda:X‘
,其中X是函数 torch.cuda.current_device()
的返回值。
PyTorch 1.0 中文文档:Tensor(张量)的属性
原文:https://www.cnblogs.com/wizardforcel/p/10392199.html