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 finetune the model? #4

Open
1960675737 opened this issue Sep 1, 2019 · 2 comments
Open

How to finetune the model? #4

1960675737 opened this issue Sep 1, 2019 · 2 comments

Comments

@1960675737
Copy link

How to finetune the model when changing the NUM_CLASSES?

@ys0823
Copy link

ys0823 commented Sep 9, 2019

How to finetune the model when changing the NUM_CLASSES?

Maybe you need do like this to delete the last layer for the .pth model

 _d=torch.load(path)
newdict=_d
def removekey(d, listofkeys):
    r=d
    for key in listofkeys:
        del r[key]
    return r

newdict['model'] = removekey(_d['model'], ['module.roi_heads.box.predictor.cls_score.bias','module.roi_heads.box.predictor.cls_score.weight','module.roi_heads.box.predictor.bbox_pred.bias','module.roi_heads.box.predictor.bbox_pred.weight','module.roi_heads.mask.predictor.mask_fcn_logits.weight','module.roi_heads.mask.predictor.mask_fcn_logits.bias'])
torch.save(newdict, 'mymodel.pth')

@wondervictor
Copy link
Member

Thanks @ys0823
You can initialize the weights/bias of the output layer in RoIHeads.

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

3 participants