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-tunning your pretrained cooco model? #23

Open
YiLiangNie opened this issue Sep 28, 2018 · 5 comments
Open

How to fine-tunning your pretrained cooco model? #23

YiLiangNie opened this issue Sep 28, 2018 · 5 comments

Comments

@YiLiangNie
Copy link

How to fine tune your dataset on your trained coco model?
Could you provide the json file for fine-tunning params and update the load_pretrained_params() function in file : ./nnet/py_factory.py?

@heilaw
Copy link
Collaborator

heilaw commented Sep 28, 2018

All you need to do is add "pretrain": "/path/to/the/pretrained/model" in the system section of the configuration file. The code will load the pretrained file before it starts training.

@heilaw
Copy link
Collaborator

heilaw commented Sep 28, 2018

I just saw your another post.

The size match happens in the convolution layers for tl_heats and br_heats. The sizes of weights and biases in the pretrained model are [80, 256, 1, 1] and [80], which do not match your new dataset.

To prepare the model for fine-tuning on a different datasets, you can do the followings.

  1. In train.py, add nnet.save_params(0) after line 114. This forces the code to save a randomly initialized model with correct sizes before the training starts. After the model is saved, terminate the code by Ctrl + c.
  2. Replace the weights and biases in the trained model with the ones in the randomly initialized model. A PyTorch model is a dictionary, where the keys are the parameter names and values are the parameters. They can be loaded with torch.load. After loading, the parameters can be replaced by newmodel['param_name'] = oldmodel['param_name']. The parameter names you are looking for are:
  • 'module.tl_heats.0.1.weight'
  • 'module.tl_heats.0.1.bias'
  • 'module.tl_heats.1.1.weight'
  • 'module.tl_heats.1.1.bias'
  • 'module.br_heats.0.1.weight'
  • 'module.br_heats.0.1.bias'
  • 'module.br_heats.1.1.weight'
  • 'module.br_heats.1.1.bias'
  1. Save the model.
  2. Remove nnet.save_params(0) in step 1.
  3. Add "pretrain": "/path/to/the/pretrained/model" in the system section of the configuration file.

@YiLiangNie
Copy link
Author

Hi heilaw,
I find this function in /models/CornerNet.py, and I want to know what does the n=5 means? thank you.

class model(kp):
def init(self, db):
n = 5
dims = [256, 256, 384, 384, 384, 512]
modules = [2, 2, 2, 2, 2, 4]
out_dim = 80
super(model, self).init(
n, 2, dims, modules, out_dim,
make_tl_layer=make_tl_layer,
make_br_layer=make_br_layer,
make_pool_layer=make_pool_layer,
make_hg_layer=make_hg_layer,
kp_layer=residual, cnv_dim=256
)

@heilaw
Copy link
Collaborator

heilaw commented Oct 15, 2018

The number of downsamplings in each hourglass module.

@YiLiangNie
Copy link
Author

Hi heilaw,
If I want to change the project to python2.7, what files need to be modified? thx!

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

2 participants