KevinMusgrave / pytorch-metric-learning

The easiest way to use deep metric learning in your application. Modular, flexible, and extensible. Written in PyTorch.
https://kevinmusgrave.github.io/pytorch-metric-learning/
MIT License
5.88k stars 655 forks source link

Model overfitting, smooth triplet margin loss #690

Open taaresh7 opened 3 months ago

taaresh7 commented 3 months ago

Hi there!

Thank you for the awesome library!

I'm currently working on training a model using the CARS196 dataset with the following parameters:

distance = distances.CosineSimilarity()
reducer = reducers.ThresholdReducer(low=0)
loss_func = losses.TripletMarginLoss(margin=0.2, distance=distance, reducer=reducer, smooth_loss=True)
mining_func = miners.TripletMarginMiner(margin=0.2, distance=distance, type_of_triplets="all")

Initially, I didn't include the smooth_loss parameter, which caused the loss to get stuck at the margin of 0.2. However, after setting smooth_loss=True, I encountered an overfitting issue. Do you think the margin and type of triplets I've used are appropriate to begin with? Should I consider adjusting them?

Additionally, I'm using the VIT base 16 224 model and freezing the early layers to reduce parameters. Do you see any mistakes in my approach, or do you have any suggestions on what I should try next? I think It is possible to achieve at least Precision@1 of 0.8. Currently, I'm at 0.6 with some overfitting.

KevinMusgrave commented 3 months ago

Do you know what settings were used to get 0.8 accuracy?

taaresh7 commented 3 months ago

Not exactly, but I checked the open-metric-learning library

train-car196-oml

They achieved 0.9 P@1 (max 1000 epochs )with the above parameters and using oml I was able to achieve 0.8 P@1 on validation (220 epochs), while on train it was 0.9. Training for more epochs it can probably reach the benchmark of 0.9.

The main thing I was forgetting was augmentation, I could try again with pytorch-metric-learning this week.