New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Size mismatch while loading pretrained model for fine-tuning with additional characters #210
Comments
Figured it out, thanks! |
@PrithaGanguly Hi, I have a similar doubt! |
@SrijithBalachander Hi, I was facing this issue when my character set was larger as compared to the pretrained model. Therefore, to make it work, while loading the pretrained model weights, I simply modified the code in train.py as follows: Hope this helps! |
@PrithaGanguly 'train.py' => I modified it in your way if opt.FT: but I got problem python train_test.py --train_data data_lmdb/training --workers 0 --valid_data data_lmdb/validation --Transformation TPS --FeatureExtraction ResNet --SequenceModeling BiLSTM --Prediction CTC --saved_model pretrained_models/TPS-ResNet-BiLSTM-CTC.pth --FT |
@kimlia545 indentation 확인해보시길 바랍니다
|
thanks! this solved my mismatch question! |
This works for me. if opt.FT:
current_model_dict = model.state_dict()
loaded_state_dict = torch.load(path, map_location=torch.device('cpu'))
new_state_dict={k:v if v.size()==current_model_dict[k].size() else current_model_dict[k] for k,v in
zip(current_model_dict.keys(), loaded_state_dict.values())}
model.load_state_dict(new_state_dict, strict=False)
else:
model.load_state_dict(torch.load(opt.saved_model)) |
Hi,
I have followed all the necessary steps for FT as given in the other threads but size mismatch error keeps recurring as the num of characters in the pre-trained model and custom dataset is not same.
Can somebody please guide me as to how to load the pre-trained model with a modified prediction layer such it can be used for fine-tuning?
Thanks in advance!
The text was updated successfully, but these errors were encountered: