dinov2 icon indicating copy to clipboard operation
dinov2 copied to clipboard

Possible to continue pretraining?

Open rohan-mehta opened this issue 1 year ago • 10 comments

I know the general recommendation is to leave the backbone frozen and train task-specific heads. However I'm interested in continuing pre-training to better fit the backbone features to my dataset. Is this feasible?

I did try it, with the steps below, but found that KNN performance started to degrade very quickly - after 20-30K images, it dropped below 10%. My approach:

  1. Load the provided backbone weights into the [SSLMetaArch](https://github.com/facebookresearch/dinov2/blob/main/dinov2/train/ssl_meta_arch.py#L31) model. This provides weights for everything except the dino/ibot heads, so train just those heads on a few 100K samples (i.e. rest of the model is frozen). At the end of this, the model still has good KNN performance.
  2. Unfreeze the entire model, and run train.py on ImageNet-1K (I first tried on my own dataset, but switched to ImageNet just to make sure its not a dataset issue). When I do this, the performance degrades quickly. After 10K images, KNN performance goes from 80%->25%. After another 10K, its ~10%. And it keeps dropping like that.

I'm using the standard VIT-L config provided in the repo.

So I'm looking for any advice or thoughts here - am I approaching this wrong? Or is this somehow not possible? Thanks!

rohan-mehta avatar Sep 05 '23 16:09 rohan-mehta

So this is not possible because we don't provide the training heads at the moment. We haven't explored this case in depth so I can't tell you what would be the right way, but we may plan to do it in the future.

qasfb avatar Sep 06 '23 07:09 qasfb

@qasfb the codebase does have a “dino_head” and a “ibot_head”. Are those not the training heads?

And as mentioned I first trained just those heads

rohan-mehta avatar Sep 06 '23 15:09 rohan-mehta

@rohan-mehta did you manage to make some progress on this in between? Currently facing the same issue and would like to continue pre-training to adapt to the domain of my use case. How long did you kept the Backbone frozen in the first step?

tZimmermann98 avatar Nov 07 '23 12:11 tZimmermann98

@tZimmermann98 didn't manage to make it work unfortunately. I kept the backbone frozen for between 50k and 300k samples. That part went fine. But then as mentioned above, when I unfroze the entire model and started training, performance on KNN degraded quickly.

rohan-mehta avatar Nov 07 '23 17:11 rohan-mehta

So, actually we can't execute training on a custom dataset?

MarioAvolio avatar Nov 15 '23 18:11 MarioAvolio

@qasfb fwiw, we'd be really interested in doing this as well!

csaroff avatar Dec 08 '23 18:12 csaroff

In my case, my training dataset will periodically grow over time, continuously incorporating images from new categories. I hope to train the model with long-life learning. Any ideas?

echochoc avatar Jan 04 '24 02:01 echochoc

@csaroff @MarioAvolio @rohan-mehta , Here's what I did: Initially, I froze the feature extractor and solely focused on training the classifier head. This approach yielded approximately 85% accuracy. However, I then decided to fine-tune both the feature extractor and the classifier head, resulting in an 8% increase in accuracy. Just to give you some context, I'm working with a custom dataset comprising roughly 38,000 samples.

Badar-e-Alam avatar May 02 '24 22:05 Badar-e-Alam

@Badar-e-Alam Thank you Alam. I am doing continue pretraining on my custom dataset. May I have your Facebook Id, I want to chat with you.

vanpersie32 avatar May 24 '24 03:05 vanpersie32

@Badar-e-Alam Thank you Alam. I am doing continue pretraining on my custom dataset. May I have your Facebook Id, I want to chat with you.

Hi @vanpersie32 can we get in contact somehow? :)

dimidagd avatar Jul 29 '24 08:07 dimidagd