设置默认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,示例错误?或者版本问题?


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM