FaceX-Zoo icon indicating copy to clipboard operation
FaceX-Zoo copied to clipboard

How to finetune pretrained model with other dataset

Open tonhathuy opened this issue 3 years ago • 2 comments

My task is face recognition with a real dataset from Surveillance camera. My training set have 3000 Id .but when I set --resume and --pretrain_model './model_pretrain/Attention92/Epoch_17.pt' . I got a error image please let me know how to fix it, thank you.

tonhathuy avatar Nov 24 '21 16:11 tonhathuy

The point is that you should not load the parameters of the head, but only load the parameters of the backbone. You can refer to the function of load_model in "test_protocol/utils/model_loader.py" and modify the code for loading a pre-trained model in line 113-116 of "training_mode/conventional_training/train.py".

wang21jun avatar Nov 25 '21 03:11 wang21jun

I follow your tutorial, my code is this:

model_dict = model.state_dict()
if conf.resume:
    ori_epoch = torch.load(args.pretrain_model)['epoch'] + 1
    pretrained_dict = torch.load(args.pretrain_model)['state_dict']
    print(pretrained_dict.keys())
    new_pretrained_dict = {}
    for k in model_dict:
        new_pretrained_dict[k] = pretrained_dict['backbone.'+k]
    model_dict.update(new_pretrained_dict)
    model.load_state_dict(model_dict)

I got a error : image I try to change new_pretrained_dict[k] = pretrained_dict['backbone.'+k] to if k != "head.weight": new_pretrained_dict[k] = pretrained_dict[k]. but it is not working, I'm sorry, I'm new in pytorch

tonhathuy avatar Nov 25 '21 10:11 tonhathuy