FaceX-Zoo
FaceX-Zoo copied to clipboard
How to finetune pretrained model with other dataset
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
please let me know how to fix it, thank you.
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".
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 :
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