設置默認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