Inference
MedOtter ships a curated zoo of segmentation models. load_model returns a
Predictor — an object with a single predict(image, spacing=None) method
that returns an integer label map matching the image’s spatial shape.
Listing what’s available
import medotter as mo
mo.list_models() # registered model names you can pass to load_model
mo.list_architectures() # architecture names valid for load_model(..., arch=)
Loading a model
load_model(source, **kwargs) accepts either a registered name (from
list_models()) or a checkpoint path ending in .pth, .pt, or .ckpt:
model = mo.load_model("sam2_hiera_small") # a registered model
model = mo.load_model("runs/best.pth", arch="CMUNeXt", num_classes=4)
sam2_hiera_small is one of the registered SAM2 baselines listed by
list_models(); "CMUNeXt" is a real architecture name from
list_architectures() (backed by models_train/model_id.json) — passing an
unregistered arch= raises ValueError before any weights are touched.
Running a prediction
sample = mo.load_dataset("ACDC", split="test")[0]
labels = model.predict(sample.image) # integer label map, same spatial shape
Note:
import medotteris dependency-light (only numpy). Torch is imported the first time you callload_model. A missing torch install surfaces as a clearImportErrorat that call, not at import.
Common errors
ValueError—sourceis neither a registered model name nor an existing/.pth/.pt/.ckpt-suffixed path, or a checkpoint’s explicitarch=is not a known architecture (list_architectures()shows the valid set).ImportError— surfaces the first time you callload_model(orpredict) iftorch(and, for SAM2, the model backbone) is not installed. Building the registry and importingmedotter.inferencenever triggers this — only callingload_modeldoes.