Margin-aware robustness metrics for pathology foundation models.
Project description
croma
croma is a Python package for evaluating pathology foundation model robustness to non-biological confounders.
It implements three complementary metrics:
RI: Robustness IndexMaRI: Margin-aware Robustness IndexCCMR: Cross-Confounder Margin Ratio
croma provides a clean implementation of RI together with MaRI -- its margin-aware extension -- as well as a new robustness metric, CCMR -- which overcomes some of the limitations of RI/MaRI and enables tail-aware analysis for more detailed robustness characterization. RI was originally introduced in the PathoROB study.
The package also comes with optional benchmarking utilities for multi-model evaluation.
Install
Core package:
pip install cross-margin
With benchmark utilities:
pip install "cross-margin[bench]"
Python Quickstart
import numpy as np
import pandas as pd
from croma import CCMR, MaRI, RI
manifest = pd.read_csv("manifest.csv")
features = np.load("embeddings.npy")
ri = RI.compute(
features,
manifest,
confounder_column="confounder",
evaluation_design="paired_2x2",
k_candidates=[5, 11, 21],
)
mari = MaRI.compute(
features,
manifest,
confounder_column="confounder",
evaluation_design="paired_2x2",
k_candidates=[5, 11, 21],
tau=0.2,
)
ccmr = CCMR.compute(
features,
manifest,
confounder_column="confounder",
evaluation_design="paired_2x2",
m=1,
)
CLI Quickstart
Compute RI:
croma ri \
--manifest /path/to/manifest.csv \
--embeddings /path/to/embeddings.npy \
--confounder-column confounder \
--evaluation-design paired_2x2 \
--k-candidates 5,11,21
Compute MaRI:
croma mari \
--manifest /path/to/manifest.csv \
--embeddings /path/to/embeddings.npy \
--confounder-column confounder \
--evaluation-design paired_2x2 \
--k-candidates 5,11,21 \
--tau 0.2
Compute CCMR:
croma ccmr \
--manifest /path/to/manifest.csv \
--embeddings /path/to/embeddings.npy \
--confounder-column confounder \
--evaluation-design paired_2x2 \
--m 1
Benchmarking
cross-margin also includes an optional benchmarking pipeline for comparing multiple foundation models on the same manifest. The benchmark handles embedding extraction, metric computation, cached re-runs, and summary artifact generation in a single workflow.
Run it with:
python scripts/benchmark.py \
--manifest /path/to/manifest.csv \
--confounder-column confounder \
--output-dir /path/to/benchmark
For benchmark options, outputs, caching behavior, and downstream analysis, see docs/benchmarking.md.
Manifest Contract
Required columns:
sample_idimage_pathlabelslide_id- the user-selected confounder column passed as
confounder_column=or--confounder-column
Default contract:
- row
iinembeddings.npyshould match rowiin the manifest
Optional:
subset: required forevaluation_design="paired_2x2"
Evaluation Designs
paired_2x2: uses explicit manifest-defined subsets and reports occurrence-level outputsdataset_wide: evaluates the retained dataset once and reports sample-level outputs
paired_2x2 is strict by design: the manifest must define valid 2x2 (label x confounder) subsets via the subset column.
Documentation
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cross_margin-1.0.0.tar.gz.
File metadata
- Download URL: cross_margin-1.0.0.tar.gz
- Upload date:
- Size: 97.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
de35d9bc75a063075757f592adfc37bb902b7b6f8e600b07ef8a883c68c82eff
|
|
| MD5 |
0117f2862e83a5d72bece26ec9bdef35
|
|
| BLAKE2b-256 |
7a57820411e7513db79a347b5cc62a726164d0523d0c3c5691bf539fce5050f9
|
File details
Details for the file cross_margin-1.0.0-py3-none-any.whl.
File metadata
- Download URL: cross_margin-1.0.0-py3-none-any.whl
- Upload date:
- Size: 32.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
418b42db2d2988fb572da845c6eb43bb0a96c9f9201211c7ec270f1d818e4c95
|
|
| MD5 |
6e03e5a4183f100af6d02333bdaca19a
|
|
| BLAKE2b-256 |
0456acf03bd8fd206a9ece294573cc22a16c6466846c72437da65b0ec61cd143
|