Skip to main content
Both H-Optimus and M-Optimus produce a 1536-dimensional embedding per tile (the CLS token). Principal components of these embeddings reveal the dominant axes of morphological variation — often corresponding to tissue vs. background, tumor vs. stroma, and immune-rich vs. immune-poor regions.

H-Optimus notebook

h1-jumpstart — a full, runnable H-Optimus embedding example.

M-Optimus notebook

m-jumpstart — the equivalent for M-Optimus.

1. Configure the model

Embeddings are available from both models. Import once, then pick your backend and model — the rest of the guide is identical.

2. Extract embeddings

On a single-GPU SageMaker endpoint (ml.g5.xlarge), lower max_concurrency (e.g. 32) to avoid out-of-memory from concurrent tile requests.

3. PCA

Load the embeddings and fit PCA in one call — bioptimus.utils.plot_pca_scatter fits, plots, and returns the scores plus the fitted PCA (explained-variance ratios are printed):
Scatter plot of the first two principal components of tile embeddings

PCA of tile embeddings on a TCGA-LUAD slide (TCGA-75-7027); PC1 explains 27.5%, PC2 13.0% of variance. Points are colored by tile index. Representative example.

4. Spatial visualization

plot_spatial_pca maps the PC scores back onto tile coordinates as per-PC spatial heatmaps — each component tends to isolate a distinct tissue compartment:
Three spatial heatmaps, one per principal component, overlaid on tile coordinates

Spatial heatmaps of PC1–PC3 on a TCGA-LUAD slide (TCGA-75-7027). Each principal component highlights a different tissue compartment. Representative example.

The same embeddings feed downstream models (classification, clustering, retrieval, MIL). For the high-level workflow with caching and workspaces, use the Inference pipeline with infer.embed(path).