yolo3-pytorch icon indicating copy to clipboard operation
yolo3-pytorch copied to clipboard

[predict.py]Error(s) in loading state_dict for YoloBody

Open EternalHXP opened this issue 4 years ago • 7 comments

麻烦帮忙看看是啥问题么?谢谢 在根据B站教程中的P8测试完成后,运行predict.py后报错,报错日志如下:

(pytorch_gpu_0627) G:\0-App\8-Code\0CodeProject\yolo3-pytorch>python predict.py
Loading weights into state dict...
Traceback (most recent call last):
  File "predict.py", line 7, in <module>
    yolo = YOLO()
  File "G:\0-App\8-Code\0CodeProject\yolo3-pytorch\yolo.py", line 44, in __init__
    self.generate()
  File "G:\0-App\8-Code\0CodeProject\yolo3-pytorch\yolo.py", line 65, in generate
    self.net.load_state_dict(state_dict)
  File "G:\0-App\8-Code\Anaconda\envs\pytorch_gpu_0627\lib\site-packages\torch\nn\modules\module.py", line 845, in load_state_dict
    self.__class__.__name__, "\n\t".join(error_msgs)))
RuntimeError: Error(s) in loading state_dict for YoloBody:
        size mismatch for last_layer0.6.weight: copying a param with shape torch.Size([75, 1024, 1, 1]) from checkpoint, the shape in current model is torch.Size([15, 1024, 1, 1]).
        size mismatch for last_layer0.6.bias: copying a param with shape torch.Size([75]) from checkpoint, the shape in current model is torch.Size([15]).
        size mismatch for last_layer1.6.weight: copying a param with shape torch.Size([75, 512, 1, 1]) from checkpoint, the shape in current model is torch.Size([15, 512, 1, 1]).
        size mismatch for last_layer1.6.bias: copying a param with shape torch.Size([75]) from checkpoint, the shape in current model is torch.Size([15]).
        size mismatch for last_layer2.6.weight: copying a param with shape torch.Size([75, 256, 1, 1]) from checkpoint, the shape in current model is torch.Size([15, 256, 1, 1]).
        size mismatch for last_layer2.6.bias: copying a param with shape torch.Size([75]) from checkpoint, the shape in current model is torch.Size([15]).

EternalHXP avatar Jun 30 '20 02:06 EternalHXP

注意修改model_path和classpath,训练的时候需要修改config里面的numclasses

bubbliiiing avatar Jun 30 '20 13:06 bubbliiiing

注意修改model_path和classpath,训练的时候需要修改config里面的numclasses

谢谢,另外请教一下,如果希望用外置摄像头进行视频的解析,怎么做呢? 有没有什么建议,感谢

EternalHXP avatar Jul 01 '20 02:07 EternalHXP

您好,请问一下这个问题您解决了么?那个上面所说的config文件在哪阿?我用的pytorch跑的,也在预测的时候出现了这个问题,很头疼,麻烦您了

xyc-1112 avatar Oct 12 '20 14:10 xyc-1112

@EternalHXP 您好,请问您的这个问题解决了吗?是怎么解决的?

msn321 avatar Oct 29 '20 09:10 msn321

RuntimeError: Error(s) in loading state_dict for YoloBody: size mismatch for last_layer0.6.weight: copying a param with shape torch.Size([21, 1024, 1, 1]) from checkpoint, the shape in current model is torch.Size([18, 1024, 1, 1]). size mismatch for last_layer0.6.bias: copying a param with shape torch.Size([21]) from checkpoint, the shape in current model is torch.Size([18]). size mismatch for last_layer1.6.weight: copying a param with shape torch.Size([21, 512, 1, 1]) from checkpoint, the shape in current model is torch.Size([18, 512, 1, 1]). size mismatch for last_layer1.6.bias: copying a param with shape torch.Size([21]) from checkpoint, the shape in current model is torch.Size([18]). size mismatch for last_layer2.6.weight: copying a param with shape torch.Size([21, 256, 1, 1]) from checkpoint, the shape in current model is torch.Size([18, 256, 1, 1]). size mismatch for last_layer2.6.bias: copying a param with shape torch.Size([21]) from checkpoint, the shape in current model is torch.Size([18]). 你好我也碰到了同样的问题,但是我都改了的

zhuleia avatar Jun 21 '21 03:06 zhuleia

多加了1

bubbliiiing avatar Jun 22 '21 08:06 bubbliiiing

@bubbliiiing 好的,谢谢。

msn321 avatar Jun 22 '21 08:06 msn321