torch.dtype和torch.tensortype的区别。
最近调试代码,报错TypeError: tensor(): argument ‘dtype’ must be torch.dtype, not torch.tensortype,原因则是因为在dtype参数中错误的传递了torch.tensortype。
PyTorch有十二种不同的数据类型,简单来说,torch.dtype是现行描述数据类型的形式,存在着Legacy Constructors,他们之间的对应关系如下:
Data type | dtype | Legacy Constructors |
---|---|---|
32-bit floating point |
|
|
64-bit floating point |
|
|
64-bit complex |
| |
128-bit complex |
| |
16-bit floating point 1 |
|
|
16-bit floating point 2 |
|
|
8-bit integer (unsigned) |
|
|
8-bit integer (signed) |
|
|
16-bit integer (signed) |
|
|
32-bit integer (signed) |
|
|
64-bit integer (signed) |
|
|
Boolean |
|
|
传参数传入对应的dytpe即可。