Repository navigation
[Draft] Serve the BioCLIP 2.5 + LogReg classifier as a pipeline - #174
Draft
mohamedelabbas1996 wants to merge 1 commit into
Draft
mohamedelabbas1996 wants to merge 1 commit into
mohamedelabbas1996 wants to merge 1 commit into
Conversation
Adds two species classifiers built on a frozen BioCLIP 2.5 ViT-H/14 backbone with a linear logistic-regression head on top, one over the Newfoundland species list and one over the Panama list, and registers them as the bioclip_2_5_newfoundland and bioclip_2_5_panama pipelines. The head is an sklearn LogisticRegression exported to a single Linear layer, so a softmax over its output reproduces sklearn's predict_proba. The backbone is frozen, so a crop's embedding never changes. The forward pass returns that embedding alongside the logits, and a classification now carries it as `features`, so whatever consumes the classification can keep the vector that produced it without running the backbone over the same crop twice. Only serving is included here. Retraining a head from verified labels builds on this and is a separate change. Co-Authored-By: Claude <noreply@anthropic.com>
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: trueThanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
mohamedelabbas1996
added a commit
that referenced
this pull request
Sep 17, 2026
Brings the standalone BioCLIP 2.5 + LogReg serving change (#174) in as the base this retraining work builds on, so the model that gets retrained is the one that PR reviews and merges on its own. The serving code was already here; this records the relationship and adds the serving-only registration tests. Co-Authored-By: Claude <noreply@anthropic.com>
mohamedelabbas1996
added a commit
that referenced
this pull request
Sep 28, 2026
Brings the standalone BioCLIP 2.5 + LogReg serving change (#174) in as the base this retraining work builds on, so the model that gets retrained is the one that PR reviews and merges on its own. The serving code was already here; this records the relationship and adds the serving-only registration tests. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CnKz4AS4iFrYj1GrgkZQbq
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This adds the BioCLIP 2.5 + logistic-regression species classifiers to the processing service as pipelines. A frozen BioCLIP 2.5 ViT-H/14 backbone carries a linear head fit as an sklearn
LogisticRegressionover L2-normalised embeddings, so a softmax over the head reproduces sklearn'spredict_probaexactly. Two heads ship: one over the Newfoundland species list and one over the Panama list.Only serving is included here. Retraining a head from verified labels builds on top of this and is kept for a separate change (RolnickLab/antenna#1407 and #167), so this PR is small and reviewable on its own.
List of Changes
BioCLIP25NewfoundlandClassifierandBioCLIP25PanamaClassifierintrapdata/ml/models/bioclip.py, loading the backbone and a head from the Hubbioclip_2_5_newfoundlandandbioclip_2_5_panamainCLASSIFIER_CHOICES, withMothClassifierBioCLIP25*API wrappersfeaturesonClassificationResponseandClassifierResult; the forward pass returns(logits, features)open-clip-torchis availablepyproject.tomlanduv.lockDetailed Description
The backbone is frozen, so a crop's embedding never changes. The forward pass returns that embedding alongside the logits, and
post_process_batchcarries it through toClassificationResponse.features. Storing the vector means the backbone never has to run over the same crop twice, which is what makes a later head-retrain cheap; a model that returns logits alone is unaffected and itsfeaturesstaysNone.The Newfoundland head is read from a public Hugging Face repository; the Panama head is read from a directory the deployment provides via
BIOCLIP_PANAMA_HEAD_DIR. The label vocabulary for the Panama head travels inside the npz, so it is normalised throughlabels_from/BioCLIPVocabularyInHeadClassifier.scripts/run_bioclip_on_remote_gpu.shis the helper used to serve these on a remote GPU.Verification
trapdata/tests/test_bioclip_classifier.py(6 tests) covers: both classifiers are registered under their slugs, they extendAPIMothClassifierand the BioCLIP bases, they declare a backbone and a head, the forward pass returns an L2-normalised embedding matching the logits,post_process_batchkeeps the embedding on the result, andClassificationResponsecarriesfeatures. These check the wiring without downloading the backbone or a head.Run locally against this branch: the new tests and
test_registry.pypass;black,isort, andflake8are clean on the changed files.