背景
今天不知道怎么整的,get_map突然报错。
问题描述:
错误提示如下:
RuntimeError: Error(s) in loading state_dict for YoloBody:
size mismatch for yolo_head_P3.weight: copying a param with shape torch.Size([51, 128, 1, 1]) from checkpoint, the shape in current model is torch.Size([48, 128, 1, 1]).
size mismatch for yolo_head_P3.bias: copying a param with shape torch.Size([51]) from checkpoint, the shape in current model is torch.Size([48]).
size mismatch for yolo_head_P4.weight: copying a param with shape torch.Size([51, 256, 1, 1]) from checkpoint, the shape in current model is torch.Size([48, 256, 1, 1]).
size mismatch for yolo_head_P4.bias: copying a param with shape torch.Size([51]) from checkpoint, the shape in current model is torch.Size([48]).
size mismatch for yolo_head_P5.weight: copying a param with shape torch.Size([51, 512, 1, 1]) from checkpoint, the shape in current model is torch.Size([48, 512, 1, 1]).
size mismatch for yolo_head_P5.bias: copying a param with shape torch.Size([51]) from checkpoint, the shape in current model is torch.Size([48]).
原因分析:
我在博客上找呀找,不论是model_path还是classes_path我都是对的,但为什么还是出错了
"model_path" : r'logs\DNF_White_Ground.pth',
"classes_path" : r'model_data\my_classes.txt',
后来灵感来源于问题描述:长度问题!!!来,我们来看下面我的class.txt
enemyWomanOne
enemyWomanTwo
enemyManOne
enemyManTwo
enemyAngel
enemyStone
enemyDevil
enemyBall
enemyBossHalf
enemyBossEnd
Character
##这还有一行【只是一个换行符】
这种报错!!!算48的那个。
改进过后
enemyWomanOne
enemyWomanTwo
enemyManOne
enemyManTwo
enemyAngel
enemyStone
enemyDevil
enemyBall
enemyBossHalf
enemyBossEnd
Character###这里是一行【只是一个换行符】
###这里也是一行【只是一个换行符】
这样就OK了。算51了。
解决方案:
由上总结:故出现以上bug,先检查自己的model和classes的文件的路径。然后看看是不是像我这种像是文件长度出现问题【这样稍作修改便可以解决问题】。