Skip to content

Commit

Permalink
Add Fine-tune RidgeClassifier example notebook
Browse files Browse the repository at this point in the history
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 <samuel.robert.stevens@gmail.com>
  • Loading branch information
johnbradley and samuelstevens committed Jan 10, 2025
1 parent 34016d0 commit 7dfd6f7
Show file tree
Hide file tree
Showing 2 changed files with 946 additions and 0 deletions.
7 changes: 7 additions & 0 deletions docs/python-tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,13 @@ As can be seen from comparing the confusion matrices, fine-tuning an SVM classif

This work is based on code from [biobench](https://github.com/samuelstevens/biobench).

### Fine-tune with RidgeClassifier
[FineTuneRidgeClassifier.ipynb](https://github.com/Imageomics/pybioclip/blob/main/examples/FineTuneRidgeClassifier.ipynb) Fine-tunes BioCLIP by combining an [RidgeClassifier](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.RidgeClassifier.html) with BioCLIP image embeddings. <a target="_blank" href="https://colab.research.google.com/github/Imageomics/pybioclip/blob/main/examples/FineTuneRidgeClassifier.ipynb">
<img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a>
As can be seen from comparing the confusion matrices, fine-tuning a RidgeClassifier classifier on BioCLIP image embeddings may yield better results than using BioCLIP in "zero-shot mode", i.e., predicting on a list of custom labels.

This work is based on code from [biobench](https://github.com/samuelstevens/biobench).

## PIL Images
The predict() functions used in all the examples above allow passing a list of paths or a list of [PIL Images](https://pillow.readthedocs.io/en/stable/reference/Image.html).
When a list of PIL images is passed the index of the image will be filled in for `file_name`. This is because PIL images may not have an associated file name.
Loading

0 comments on commit 7dfd6f7

Please sign in to comment.