Zoobot providesDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/mwalmsley/zoobot/llms.txt
Use this file to discover all available pages before exploring further.
FinetuneableZoobotClassifier, FinetuneableZoobotRegressor, and FinetuneableZoobotTree for the most common finetuning scenarios. But what if your task doesn’t fit neatly into classification, regression, or vote-count prediction?
This guide covers three advanced integration patterns:
- Using Zoobot’s encoder directly in your own pipeline
- Extracting frozen galaxy representations at scale
- Subclassing
FinetuneableZoobotAbstractto implement a custom head and loss
Using Zoobot’s Encoder Directly
Because Zoobot encoders are standardtimm models, you can plug them into any PyTorch pipeline.
Method 1: Via a FinetuneableZoobot Class
Load anyFinetuneableZoobot class and access its .encoder attribute:
Method 2: Via timm Directly
Because Zoobot encoders are published as timm-compatible HuggingFace Hub models, you can load them without Zoobot at all:
encoder like any other timm model — wrap it in a custom head, combine it with other networks, or pass it to a contrastive learning framework.
Extracting Frozen Representations
Once you have a pretrained or finetuned Zoobot encoder, you can store its output vectors as fixed-dimensional features for downstream tasks like similarity search, anomaly detection, or clustering. Zoobot includesZoobotEncoder, a PyTorch Lightning LightningModule wrapper that lets you pass the encoder to the same predict_on_catalog.predict() utility used for full model inference — handling batching, looping, and file I/O automatically.
zoobot/pytorch/examples/representations for a complete working example.
Dimensionality Reduction
Zoobot representations are typically high-dimensional (e.g. 1280 for EfficientNetB0) and therefore highly redundant. We recommend using PCA to compress them to a more manageable size (e.g. 40 dimensions) while retaining most of the information. This was the approach taken in the Practical Morphology Tools paper.Pre-calculated representations for all DESI galaxies are available — see the Science Data page. HSC representations are coming soon.
Subclassing FinetuneableZoobotAbstract
For tasks that don’t fit the built-in classes (for example, multi-output regression, ordinal classification, or custom loss functions), you can subclassFinetuneableZoobotAbstract and plug in your own head and loss.
Your subclass must:
- Set
self.head— atorch.nn.Modulethat maps encoder features to outputs. - Set
self.loss— a callable with signatureloss(y_pred, y). - Implement
batch_to_supervised_tuple(self, batch)— extracts(x, y)from a batch dict.
Example: Custom Regression Head
Imagine you want to finetune Zoobot on a regression task with a custom loss. Here’s how you’d implement it:FinetuneableZoobot class: