TypeError: can't convert np.ndarray of type numpy.uint16.

报错代码为:

label = torch.FloatTensor(label)

报错  TypeError: can't convert np.ndarray of type numpy.uint16. The only supported types are: float64, float32, float16, int64, int32, int16, int8, and uint8.

       我没有百度到一样的问题,但看着是数据类型不对——现在是int,需要的是float,解决方法请往下翻,在5.中。

       期间我试了很多int转float的方法,具体如下(由于接触python时间不长,可能有点……嗯……):

1. label = torch.FloatTensor(float(label))

    报错:TypeError: only size-1 arrays can be converted to Python scalars

2. label.astype(float)

    这是百度到的 1.中的报错找到的方案,1.的报错是解决了,但是并没有转化了数据类型,还是报错

    TypeError: can't convert np.ndarray of type numpy.uint16.……

3. 到此,我想,是不是得用pytorch中专用的类型转化函数呢?于是,改为:

     label = label.to(torch.float64)

     报错   AttributeError: 'numpy.ndarray' object has no attrib

评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值