![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
#记录报错
来包番茄沙司
我是一条偶尔躺平的咸鱼
天津大学 研二
展开
-
RuntimeError: Attempting to deserialize object on CUDA device 1 but torch.cuda.device_count() is 1.
若你当前在只有 CPU 环境下运行的话,需要加上map_location=torch.device('cpu')。若你当前在有 CUDA环境下运行的话,需要加上map_location=torch.device('cuda')。checkpoint = torch.load('model5_4.pt')原创 2022-06-09 15:53:18 · 2867 阅读 · 1 评论 -
RuntimeError: zero-dimensional tensor (at position 0) cannot be concatenated
成功解决 RuntimeError: zero-dimensional tensor (at position 0) cannot be concatenated如果两个变量都是tensor([])的形式,则不报错;有一方不是这个形式,则objv_all = torch.cat((objv_all, objv))则会报错。解决方法的核心:使用np.expand_dims扩充维度但要注意扩展维度前的cuda和cpu之间的关系转换!原创 2022-03-21 11:56:05 · 9513 阅读 · 4 评论 -
RuntimeError: The size of tensor a (22) must match the size of tensor b (32) at non-singleton dimens
成功解决RuntimeError: The size of tensor a (22) must match the size of tensor b (32) at non-singleton dimension 3报错原因使用print查看了x的维度和out的维度,发现out = torch.Size([10, 300, 22, 22])x = torch.Size([10, 3, 32, 32])为什么输入x是图片是3232大小,out就变成了2222?仔细检查网络,发现具有3*3卷积原创 2022-02-15 20:54:57 · 21882 阅读 · 1 评论 -
IndexError: index 11 is out of bounds for dimension 0 with size 11
IndexError: index 11 is out of bounds for dimension 0 with size 11报错原因:创建的数组是大小(11,2),横坐标索引值是0-10、纵坐标索引值是0-1。而在循环语句中索引的最后一个值是11,超出了数组索引范围。解决方法:将数组维度扩充,或将循环减少。成功解决,不报错了!原创 2022-01-23 11:07:54 · 13909 阅读 · 2 评论 -
RuntimeError: scatter(): Expected dtype int64 for index
RuntimeError: scatter(): Expected dtype int64 for index1.报错原因:scatter要求数据是int64类型,而我在定义tensor时写的是torch.Tensor(x),应该写成torch.LongTensor(x),指定为int64类型。2.解决方法找到原数据的定义方式,改!一般在dtype=np.int64;dtype=np.float32中(多数定义函数都有dtype属性)最好int和float的位数要一致原创 2022-01-08 22:52:11 · 14817 阅读 · 1 评论 -
RuntimeError:Given input size:(256x1x1). Calculated output size: (256x0x0).Output size is too small
RuntimeError: Given input size: (256x1x1). Calculated output size: (256x0x0). Output size is too small报错原因:图片尺寸太小(初始尺寸32*32*3,而32=2^5,经过五层池化后尺寸就变为1),进入网络后池化不够大。解决方法:①修改pooling层,步长变为1。②减少pooling层,两层卷积后一层池化,池化一共3层。原创 2022-01-08 22:39:57 · 22640 阅读 · 3 评论 -
AttributeError: ‘int‘ object has no attribute ‘items‘_Python中使用items()方法遍历字典的例子
记录报错:AttributeError: 'int' object has no attribute 'items'items在python中什么意思?Python中使用items()方法遍历字典的例子原创 2022-01-07 10:06:58 · 8534 阅读 · 0 评论