Skip to main content
The Inference pipeline replaces the multi-step manual pipeline (Backbone + mask provider + SlideInference + writer) with a single, reusable object. The constructor is the pipeline config; the methods do the work. It caches tissue masks, organizes outputs into a structured workspace, and can serialize its config for reproducibility.

Configure the pipeline

Pick your backend and model — the rest of the guide follows the same steps.
from bioptimus.inference import Inference
from bioptimus.models.types import Models

infer = Inference(
    model_name=Models.H1,
    api_url="http://localhost:8080",
    tissue=True,
    mask_threshold=0.5,
    output_path="/data/output",
    experiment="h1-embedding-demo",
    run=1,
    description="H1 embeddings with tissue masking",
)

Run the pipeline

infer.tissue(wsi_path)                 # generate (or load cached) tissue mask
result_path = infer.embed(wsi_path)    # -> <workspace>/h1/embeddings/<slide>.zarr
The tissue mask is cached to <workspace>/tissue/<slide>.png and reused automatically on later calls.

Reproducibility

The config is auto-saved to <workspace>/config.yaml on first use. Reconstruct the exact pipeline later:
infer.save_config()
infer2 = Inference.from_workspace(workspace_dir)   # same workspace; cached masks reused
The same object works across multiple slides — call infer.embed([s1, s2]) (or infer.predict([s1, s2]) for M-Optimus) rather than creating a new Inference per slide. For full cohorts with bulk RNA, see Cohorts.

Workspaces & variants

Your workspace is the directory where all outputs are written. It’s resolved from the config you pass:
<output_path>/<experiment>/run_<run>/<variant>/
Only output_path is required; experiment, run, and variant are appended when set:
SegmentConfig fieldAppended when
<output_path>output_pathalways (required)
<experiment>experimentset
run_<run>runset
<variant>variantset
variant (a string) adds a final sub-folder so you can keep multiple runs side by side — useful for experiments (e.g. comparing mask thresholds or model versions) without overwriting earlier outputs:
infer = Inference(model_name=Models.H1, api_url="http://localhost:8080",
                  output_path="/data/output", experiment="tcga_coad", run=1,
                  variant="mask_0.5")
# -> /data/output/tcga_coad/run_1/mask_0.5/
A populated workspace looks like:
<output_path>/<experiment>/run_<run>/<variant>/
  config.yaml
  manifest.yaml
  tissue/<slide>.png
  h1/embeddings/<slide>.zarr