Skip to content
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

How to fine tune pretrained pascal person model on your own data? #33

Closed
rkhilnani9 opened this issue Jul 14, 2020 · 5 comments
Closed

Comments

@rkhilnani9
Copy link

Trying to use exp-schp-201908270938-pascal-person-part.pth model for fine tuning on data with number of classes = 3.

Where do I plug in the weights of the model?

Both --model-restore=./pretrain_model/exp-schp-201908270938-pascal-person-part.pth and --schp-restore=./pretrain_model/exp-schp-201908270938-pascal-person-part.pth are throwing errors.

--imagenet-pretrain has to be ./pretrain_model/resnet101-imagenet.pth. So where does the weights of the pascal pretrained model fit in train.py?

@Julymycin
Copy link

Well, I think both --model-restore and --schp-restore are used for resume training, not well fit for finetune, you can use the default value, and then, add:
state_dict = torch.load(pre_ckpt)['state_dict'] model.load_state_dict(state_dict) schp_model.load_state_dict(state_dict)
after you initialize model and schp_model,pre_ckpt means the path to your pretrained weight such as exp-schp-201908270938-pascal-person-part.pth.
Hope it can work.

@rkhilnani9
Copy link
Author

@Julymycin Thanks for your suggestion! I tried that, but I am getting this error :

size mismatch for module.decoder.conv4.weight: copying a param with shape torch.Size([7, 256, 1, 1]) from checkpoint, the shape in current model is torch.Size([3, 256, 1, 1]).

My data has 3 classes, and the pascal person dataset has 7. That can be the issue, but I'm struggling to figure out how to resolve. it.

@Julymycin
Copy link

@rkhilnani9 Well, there are two possibly helpful options for you.

  1. use the 7 classes as default network and load the state_dict, then change this layer to 3 classes, initial it.
  2. use your own 3 classes network, before you load the state_dict, locate the mismatch layer(s), change its shape or replace it with your custom(or random) tensor value.

@Stephenfang51
Copy link

@Julymycin

Dear Sir

I followed your step and I can load LIP pretrained model so far, however the errors shows

RuntimeError: module must have its parameters and buffers on device cuda:0 (device_ids[0]) but found one of them on device: cpu
> /home/liwei.fang/SCHP/train_qinzhou_pretrainfromlip.py(209)main()
-> preds = model(images)

I checked the model parameter and buffers on gpu using next(model.parameters()).is_cuda() and it return True
Did you sucessfully using pretrained model before ?
Thanks so much !

@Stephenfang51
Copy link

@Julymycin

Dear Sir

I followed your step and I can load LIP pretrained model so far, however the errors shows

RuntimeError: module must have its parameters and buffers on device cuda:0 (device_ids[0]) but found one of them on device: cpu
> /home/liwei.fang/SCHP/train_qinzhou_pretrainfromlip.py(209)main()
-> preds = model(images)

I checked the model parameter and buffers on gpu using next(model.parameters()).is_cuda() and it return True
Did you sucessfully using pretrained model before ?
Thanks so much !

I just solved the problem, the error happend becuase I modified the final fusion layer conv outputs to 3 nodes, and the weight I changed is on cpu, so need to model.to(device) afterall

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants