hou-yz / MVDet

[ECCV 2020] Codes and MultiviewX dataset for "Multiview Detection with Feature Perspective Transformation".
https://hou-yz.github.io/publication/2020-eccv2020-mvdet
165 stars 29 forks source link

Error when load checkpoint: Missing key(s) in state_dict & Unexpected key(s) in state_dict #7

Closed antenna-fast closed 3 years ago

antenna-fast commented 3 years ago

Help: An error occured to me as shown in below, how to solve it?

Missing key(s) in state_dict: "map_classifier.0.weight", "map_classifier.0.bias", "map_classifier.2.weight", "map_classifier.2.bias", "map_classifier.4.weight".

Unexpected key(s) in state_dict: "world_classifier.0.weight", "world_classifier.0.bias", "world_classifier.2.weight", "world_classifier.2.bias", "world_classifier.4.weight".

antenna-fast commented 3 years ago

I noticed there is no "world_classifier" in model, but "map_classifier" exist

antenna-fast commented 3 years ago

I fixed it using the code below:

    # create a new state_dict [debug] [world->map]
    resume_dict = torch.load(resume_fname)

    new_state_dict = OrderedDict()
    for k, v in resume_dict.items():
        if 'world' in k:
            new_k = k.replace('world', 'map')
        else:
            new_k = k
        new_state_dict[new_k] = v

    model.load_state_dict(new_state_dict)
    model.eval()
hou-yz commented 2 years ago

thanks for the issue and the fix. the problem was due to module renaming at a certain stage.