设置默认tensor类型

python版本:Python 3.8.2

pytorch版本:1.5.0+cpu

import torch

torch.set_default_tensor_type('torch.IntTensor')   # tensor 类型设置默认类型语句:输入为字符:'  '

报错:

Traceback (most recent call last):
File "<input>", line 1, in <module>
File "D:\Python\lib\site-packages\torch\__init__.py", line 206, in set_default_tensor_type
_C._set_default_tensor_type(t)
TypeError: only floating-point types are supported as the default type

(仅支持浮点数作为默认类型)

改为:

torch.set_default_tensor_type('torch.DoubleTensor') 

torch.set_default_tensor_type('torch.FloatTensor') 

无报错

 

《深度学习框架Pytorch入门与实践》  P63,示例错误?或者版本问题?

posted @ 2020-05-21 09:47  珠江水手  阅读(1144)  评论(1编辑  收藏  举报