Skip to main content

Documentation 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.

FinetuneableZoobotRegressor adapts a pretrained Zoobot encoder to predict continuous morphological measurements — bar strength, ellipticity, Sérsic index, merger probability as a fraction, or any other real-valued quantity. It attaches a single-output linear head to the encoder and trains with MSE or MAE loss. An optional sigmoid activation constrains predictions to the unit interval [0, 1].
from zoobot.pytorch.training.finetune import FinetuneableZoobotRegressor

Quick Example

finetune_regression.py
import pandas as pd
from galaxy_datasets.pytorch.galaxy_datamodule import CatalogDataModule
from zoobot.pytorch.training import finetune

labelled_df = pd.read_csv('/path/to/labelled_galaxies.csv')  # needs 'bar_strength', 'file_loc', 'id_str'

datamodule = CatalogDataModule(
    label_cols=['bar_strength'],
    catalog=labelled_df,
    batch_size=32
)

model = FinetuneableZoobotRegressor(
    name='hf_hub:mwalmsley/zoobot-encoder-convnext_nano',
    label_col='bar_strength',
    loss='mse',
    unit_interval=True   # sigmoid output, predictions between 0 and 1
)

trainer = finetune.get_trainer(save_dir='./results', max_epochs=50)
trainer.fit(model, datamodule)
There is also a Google Colab notebook demonstrating regression with Zoobot: Open in Colab.

Constructor Parameters

All parameters from FinetuneableZoobotAbstract are accepted. The following are specific to the regressor.
label_col
str
default:"'label'"
Name of the column in the batch dictionary containing the continuous target value. Must be a key in your catalog and listed in label_cols passed to CatalogDataModule.
loss
str
default:"'mse'"
Loss function to use during training. Options:
  • 'mse' or 'mean_squared_error' — mean squared error (L2 loss)
  • 'mae', 'mean_absolute_error', 'l1', or 'l1_loss' — mean absolute error (L1 loss)
MAE is more robust to outliers; MSE penalizes large errors more heavily.
unit_interval
bool
default:"False"
If True, applies a sigmoid activation to the head output, constraining predictions to [0, 1]. Useful when predicting fractions, probabilities, or any quantity bounded between 0 and 1.

Metrics Logged

MetricDescription
finetuning/train_lossLoss on training set (MSE or MAE, per epoch)
finetuning/val_lossLoss on validation set (per epoch)
finetuning/train_rmseRoot mean squared error on training set
finetuning/val_rmseRoot mean squared error on validation set
finetuning/test_rmseRMSE on test set (when trainer.test() is called)

Example with Fraction Prediction

For predicting a morphological fraction (e.g. the fraction of volunteers that called a galaxy a merger):
fraction_regression.py
model = FinetuneableZoobotRegressor(
    name='hf_hub:mwalmsley/zoobot-encoder-convnext_nano',
    label_col='merger_fraction',
    loss='mse',
    unit_interval=True,      # sigmoid ensures predictions are in [0, 1]
    learning_rate=1e-4,
    training_mode='full'
)

Reloading After Training

model = FinetuneableZoobotRegressor.load_from_checkpoint(
    'results/checkpoints/epoch=30.ckpt'
)
For choosing between training_mode='full' and 'head_only', and for guidance on learning rate and layer decay, see Choosing Parameters.

Build docs developers (and LLMs) love