question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Training on new data with my own pretrained model - model fine tuning

See original GitHub issue

❓ Questions and Help

I have trained a model on my own dataset (4 classes + background) starting from catalog://ImageNetPretrained/MSRA/R-50.

Now I want to use the output model from the training mentioned above model_final.pth as the new starting point (instead of R-50) to train on new labeled data. I set the MODEL.WEIGHT in my config to the path of “model_final.pth” and it is able to load the model and it has the right number of layers and dimensions. However, when running training, specifically model.train() inside engine/trainer.py function do_train(…), it skips all training and immediately finishes. As shown here:

2019-01-23 00:13:49,014 maskrcnn_benchmark.trainer INFO: Start training
2019-01-23 00:13:49,082 maskrcnn_benchmark.trainer INFO: Total training time: 0:00:00.067745 (0.0001 s / it)

Am I missing a step? If I am fine tuning with the same number of classes, I don’t think I need to remove any layers (e.g. cls_score), even when I remove those the model does not train.

Thanks for the help in advanced!

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:15 (8 by maintainers)

github_iconTop GitHub Comments

16reactions
fmassacommented, Jan 25, 2019

Hi @adrifloresm ,

In order to do that, all you need to do is to open a python interpreter, load the weights and save a new dict with only the state_dict in it.

Something like

import torch

original = torch.load('path/to/your/checkpoint.pth')

new = {"model": original["model"]}
torch.save(new, 'path/to/new/checkpoint.pth')

Let me know if it solves your problem.

3reactions
fmassacommented, Feb 8, 2019

A tutorial on how to finetune a model for a new dataset would be great!

I’d like to hold on a bit on adding yet more options in the config for now. I think that once we have the tutorial we would be able to see what are the biggest pain points, and have a better idea on how to address them.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fine-tune a pretrained model - Hugging Face
When you use a pretrained model, you train it on a dataset specific to your task. This is known as fine-tuning, an incredibly...
Read more >
Transfer learning and fine-tuning | TensorFlow Core
A pre-trained model is a saved network that was previously trained on a large dataset, typically on a large-scale image-classification task. You either...
Read more >
Transfer Learning | Pretrained Models in Deep Learning
Ways to fine tune your model; Use the pre-trained model for identifying digits. Retraining the output dense layers only; Freeze the weights ...
Read more >
Tutorial: Fine-Tuning a Model on Your Own Data - Haystack
Once you have collected training data, you can fine-tune your base models. We initialize a reader as a base model and fine-tune it...
Read more >
Fine-Tune a Model - Amazon SageMaker
Fine -tuning trains a pretrained model on a new dataset without training from scratch. This process, also known as transfer learning, can produce...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found