tensor(): argument ‘dtype‘ must be torch.dtype, not torch.tensortype

12 篇文章 1 订阅

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

torch.float32 or torch.float

torch.*.FloatTensor

64-bit floating point

torch.float64 or torch.double

torch.*.DoubleTensor

64-bit complex

torch.complex64 or torch.cfloat

128-bit complex

torch.complex128 or torch.cdouble

16-bit floating point 1

torch.float16 or torch.half

torch.*.HalfTensor

16-bit floating point 2

torch.bfloat16

torch.*.BFloat16Tensor

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

Boolean

torch.bool

torch.*.BoolTensor

传参数传入对应的dytpe即可。

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值