Python3 日常报错(持续更新)

Python3 日常报错(持续更新)

TypeError: ‘odict_items’ object does not support indexing 或TypeError: ‘dict_items’

res = model.features._modules.items()[layer_index]
修改为 res = list(model.features._modules.items())[layer_index]

RuntimeError: bool value of Tensor with more than one value is ambiguous

这段是bias复制出问题,pytorch的conv.py要求bias是bool类型
any([True False False])
表示只要有一个True 就返回 True,
all([True False False])
表示所有元素为True才会返回True, 否则返回False.

TypeError: slice indices must be integers or None or have an index method

这里是python进行矩阵操作的时候出现错误,我做了这样一个操作,矩阵位置索引出了问题

new_weights[:, : filter_index * params_per_input_channel] = old_weights[:, : filter_index * params_per_input_channel]

其中params_per_input_channel是float,filter_index是int,结果是float,增加类型转换后正常了
PS:还有一种情况是内部存在除法,修改方法是将 / 转换为 // 。

TypeError: can’t convert CUDA tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.

在CUDA tensor格式的数据转换为numpy时,先将其转换成cpu float-tensor,比如:
ele_cumpy = ele_tensor.data.cpu().numpy()

TypeError: new(): argument ‘size’ must be tuple of ints, but found element of type float at pos 2

数据类型的问题,根据需要强制转换就OK了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值