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

Add fine-tuning documentation #76

Open
johnbradley opened this issue Dec 17, 2024 · 10 comments
Open

Add fine-tuning documentation #76

johnbradley opened this issue Dec 17, 2024 · 10 comments

Comments

@johnbradley
Copy link
Collaborator

Provide documentation on how users could fine-tune BioCLIP.

@johnbradley
Copy link
Collaborator Author

@johnbradley
Copy link
Collaborator Author

johnbradley commented Dec 18, 2024

My understanding of the three example above: These use only the visual part of the BioCLIP model and train SVM/ridge classifier/simpleshot based on the image embeddings. No text embeddings are used.

@samuelstevens
Copy link
Contributor

Yep, that's correct. biobench is a method to evaluate vision-only models like the vision encoder from BioCLIP, or DINOv2, etc.

johnbradley added a commit that referenced this issue Dec 30, 2024
Adds a notebook that trains a SVM that predicts species based on
image embeddings created by BioCLIP. The SVM logic is based on
https://github.com/samuelstevens/biobench by @samuelstevens.

Part of issue #76.
johnbradley added a commit that referenced this issue Dec 30, 2024
Adds a notebook that trains a SVM that predicts species based on
image embeddings created by BioCLIP. The SVM logic in init_svc()
is copied from https://github.com/samuelstevens/biobench by
@samuelstevens.

Part of issue #76.

Co-authored-by: Samuel Stevens <[email protected]>
Co-authored-by: Copilot <[email protected]>
johnbradley added a commit that referenced this issue Jan 7, 2025
Adds a notebook that trains a SVM that predicts species based on
image embeddings created by BioCLIP. The SVM logic in init_svc()
is copied from https://github.com/samuelstevens/biobench by
@samuelstevens.

Part of issue #76.

Co-authored-by: Samuel Stevens <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Hilmar Lapp <[email protected]>
johnbradley added a commit that referenced this issue Jan 10, 2025
Adds a notebook that trains a RidgeClassifier that predicts
species based on image embeddings created by BioCLIP. The
RidgeClassifier logic is simplified from init_svc() in
https://github.com/samuelstevens/biobench by @samuelstevens.

Part of issue #76.

Co-authored-by: Samuel Stevens <[email protected]>
johnbradley added a commit that referenced this issue Jan 10, 2025
Adds a notebook that trains a RidgeClassifier that predicts
species based on image embeddings created by BioCLIP. The
RidgeClassifier logic is simplified from init_svc() in
https://github.com/samuelstevens/biobench by @samuelstevens.

Part of issue #76.

Co-authored-by: Samuel Stevens <[email protected]>
johnbradley added a commit that referenced this issue Jan 16, 2025
Adds a notebook that trains a Simpleshot to predicts species based
on image embeddings created by BioCLIP. The Simpleshot logic
is based on from https://github.com/samuelstevens/biobench by
@samuelstevens.

Part of issue #76.

Co-authored-by: Samuel Stevens <[email protected]>
johnbradley added a commit that referenced this issue Jan 23, 2025
Adds a notebook that trains a RidgeClassifier that predicts
species based on image embeddings created by BioCLIP. The
RidgeClassifier logic is simplified from init_svc() in
https://github.com/samuelstevens/biobench by @samuelstevens.

Part of issue #76.

Co-authored-by: Samuel Stevens <[email protected]>
Co-authored-by: Copilot <[email protected]>
@johnbradley
Copy link
Collaborator Author

@samuelstevens I want to add some documentation comparing the different approaches above. How would you suggest a user go about deciding between the three options?

@hlapp
Copy link
Member

hlapp commented Jan 23, 2025

Maybe we should try and ask Copilot or ChatGPT, or as seems to be the latest rave, the most recent version of DeepSeek 😉 (Though only half joking)

johnbradley added a commit that referenced this issue Jan 23, 2025
Adds a notebook that trains a Simpleshot to predicts species based
on image embeddings created by BioCLIP. The Simpleshot logic
is based on from https://github.com/samuelstevens/biobench by
@samuelstevens.

Part of issue #76.

Co-authored-by: Samuel Stevens <[email protected]>
@samuelstevens
Copy link
Contributor

Yeah I actually think asking an LLM for a summary is a good idea. Fundamentally, BioCLIP embeddings are designed to be linearly separable. The SVM and ridge classifier are linear (unless you choose a nonlinear kernel in the SVM), while the KNN/Simpleshot is non-linear.

Another point is that SVM and ridge classifier are parametric ML methods that explicitly learn parameters, while KNN is non-parametric. But in practice, all three will produce similar results, and I'm not sure that I have any recommendations on what methods are likely to produce the best results based on different tasks.

BioBench would be a good way to test this but it's not set up to evaluate multiple ML methods on a given task right now---I am trying to write a short paper for CV4Animals about BioBench and some findings, but I won't get to that until February. If you're willing to wait, I am happy to share any insights I gain from that project.

@johnbradley
Copy link
Collaborator Author

Asking ChatGPT

Compare SVM, Ridge Classifier, and SimpleShot for fine tuning image embeddings 
that linearly separable for classification.

ChatGPT Output

Image

Recommendations

  • SVM: Best suited for tasks where embeddings are high-quality and you need precise decision boundaries.
  • Ridge Classifier: Ideal for large datasets where computational efficiency is crucial and embeddings are linearly separable with noise.
  • SimpleShot: Excellent for few-shot learning scenarios, or when you want a fast, non-parametric approach without retraining.

If your embeddings are linearly separable and classification is the goal, SVM often provides the best performance in terms of accuracy, but Ridge Classifier may be preferred for faster computation. If simplicity or few-shot adaptability is key, go for SimpleShot.

@johnbradley
Copy link
Collaborator Author

@hlapp
Copy link
Member

hlapp commented Jan 27, 2025

Perhaps @samuelstevens can double check what is true and what might be hallucinations, but I'd say pretty good on the face of it.

@samuelstevens
Copy link
Contributor

Perhaps the best strengths of each are:

  1. SVMs can support linear and non-linear boundaries and are suitable for binary classification or fewer than ~20 classes (because you train a one-vs-rest for each class).
  2. Ridge classifiers are best for linear classification tasks. They require training but are powerful classifiers for many, many tasks, especially with sufficient data.
  3. SimpleShot is extremely data-efficient and works well for multiple (20+) classes.

This table summarizes this well I think:

Method Maximum Classes Minimum Training Data
SVM ~20 5+ examples
Ridge Classifier No maximum 10+ examples per class
SimpleShot No maximum 1+ example per class

So if you have 3 classes with 5 examples each, I would expect SVMs > SimpleShot > Ridge Classifier. If you have 40 classes with 50 examples each, I would expect Ridge Classifier > SimpleShot, and I would expect SVMs to take too long to train reliably.

Does that clarify things?

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