bubbliiiing / yolox-pytorch

这是一个yolox-pytorch的源码,可以用于训练自己的模型。
Apache License 2.0
890 stars 185 forks source link

请问这个您的yolo.py可以用旷视训练好的yolox_s的直接做预测推理吗? #152

Open Maxwell2016LeChouchou opened 1 year ago

Maxwell2016LeChouchou commented 1 year ago

请问这个您的yolo.py和predict.py可以用旷视训练好的yolox_s的直接做预测推理吗? 我看您的predict.py有可视化heatmap,就想用我在旷视训练好的yolox_s(自己标注的训练集)在您的代码上直接做heatmap可视化。 但是报一大堆backbone的错误,主要是这些:

(open-mmlab) C:\Maxwell_W\detection\yolox-pytorch>python predict.py img/clean_AI_00822.png
Traceback (most recent call last):
  File "predict.py", line 14, in <module>
    yolo = YOLO()
  File "C:\Maxwell_W\detection\yolox-pytorch\yolo.py", line 85, in __init__
    self.generate()
  File "C:\Maxwell_W\detection\yolox-pytorch\yolo.py", line 95, in generate
    self.net.load_state_dict(torch.load(self.model_path, map_location=device))
  File "C:\Users\potentialmotors\miniconda3\envs\open-mmlab\lib\site-packages\torch\nn\modules\module.py", line 1671, in load_state_dict
    raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format(
RuntimeError: Error(s) in loading state_dict for YoloBody:
        Missing key(s) in state_dict: "backbone.backbone.stem.conv.conv.weight", "[backbone.backbone.stem.conv.bn](http://backbone.backbone.stem.conv.bn/).weight", "[backbone.backbone.stem.conv.bn](http://backbone.backbone.stem.conv.bn/).bias", "backbone.backbone.stem.conv.bn.running_mean",
"""""""
这里报一大堆的backbone nn的错误 
"""""""
        Unexpected key(s) in state_dict: "start_epoch", "model", "optimizer", "best_ap", "curr_ap".
illrayy commented 10 months ago

模型的权重是通过字典加载的:

pretrained_dict = torch.load(model_path, map_location = device)
pretrained_dict = {k: v for k, v in pretrained_dict.items() if np.shape(model_dict[k]) == np.shape(v)}

官方仓库训练的模型和这个仓库的key不同,你可以对一下两个权重的shape,看看这个仓库的key是什么样的,然后自己改一下官方的key