chuangchuangtan / NPR-DeepfakeDetection

94 stars 2 forks source link

load model error #11

Open ggamaz opened 1 week ago

ggamaz commented 1 week ago

Thanks for your great work sincerely! I wonder what's the difference between the NPR.pth and model_epoch_last_3090.pth,I want to load the NPR.pth, but there is an error, which looks like about model structure, i donot know how to do image

chuangchuangtan commented 1 week ago

You can load pre-trained models in the following ways:

try:
    model.load_state_dict(torch.load(opt.model_path, map_location='cpu'), strict=True)
except:
    from collections import OrderedDict
    from copy import deepcopy
    state_dict = torch.load(opt.model_path, map_location='cpu')['model']
    pretrained_dict = OrderedDict()
    for ki in state_dict.keys():
        pretrained_dict[ki[7:]] = deepcopy(state_dict[ki])
    model.load_state_dict(pretrained_dict, strict=True)