Example region and patches for testing (CC BY 4.0, see below)
About the CONCH variant
CONCH is distributed by MahmoodLab
under CC-BY-NC-ND 4.0, which prohibits redistribution. Only the task head is
released here — the encoder is not included and must be obtained by you.
Two important caveats:
You must request access to CONCH yourself (gated, non-commercial research
use only) and install the conch package.
This head will not reproduce the paper's CONCH results. The reported
numbers used an encoder that was fine-tuned jointly with the head; pairing
this head with the original frozen CONCH encoder is a different model. It is
provided for architecture reference and completeness only.
Predicted cell types
Group
Cell types
Lymphoid
CD4, CD8, B, Plasma
Myeloid
Macrophage, DC
Stromal
endothelial, Fibroblast
Tumor
malignant, NormalEpithelial, dead
Predictions are relative quantile values in [0, 1], not absolute cell counts.
1. Background removal. The slide is tiled into small blocks; blocks whose
mean HSV saturation falls below a threshold are treated as background and
zeroed out. This removes white glass and empty regions before normalization,
so background pixels do not distort the colour statistics.
2. Reinhard colour normalization. Stain colour is matched to a reference
slide in LAB space, channel by channel. Background (zero) pixels are excluded
from the mean/std computation and left untouched. This reduces variation
between scanners and staining batches. LAB conversion is chunked so large
slides do not exhaust memory.
3. Patch extraction. Patches are cropped on a regular grid and kept only if
they pass a saturation floor and a maximum background-fraction check.
Requirements
bash
1pip install numpy pillow tifffile scikit-image
2pip install h5py # only for --save-h5
--target is a reference slide whose stain appearance you want to match. Use
the same reference across your whole cohort — switching references mid-way
introduces exactly the batch effect this step is meant to remove.
Key options
Option
Default
Description
--patch-size
256
Crop size in pixels
--stride
= patch size
Step between patches; smaller values overlap
--resize
none
Resize patches (use 224 for the model)
--bg-sat-threshold
0.10
Saturation below which a block is background
--patch-sat-threshold
0.10
Minimum mean saturation to keep a patch
--black-threshold
0.10
Max fraction of background pixels per patch
--no-background-removal
off
Skip stage 1
--no-normalize
off
Skip stage 2
--save-intermediate
off
Also write the normalized slide and a JPEG preview
--save-h5
off
Additionally bundle patches into an HDF5 file
Thresholds are starting points, not tuned values — inspect the output with
--save-intermediate and adjust them for your slides.
Resolution
The encoder expects roughly 0.27 microns per pixel. preprocess.py crops in
pixel units and does not read scanner MPP metadata, so choose --patch-size
and --resize to match your source resolution. For example, a slide at
0.25 um/px needs a 448-pixel crop resized to 224 to land at ~0.5 um/px.
Sample data
sample_data/ contains a small H&E region and a few prepared patches so you
can verify the pipeline end to end without downloading a full slide.
bash
1# run the model on a prepared patch2python inference.py sample_data/patches/patch_00000.png --backbone hoptimus
34# or start from the region crop5python preprocess.py --input sample_data/region.tif \6 --target sample_data/region.tif --output my_patches/ --resize 224
These images derive from a publicly available 10x Genomics dataset licensed
under CC BY 4.0, cropped and
tiled for this repository. See sample_data/README.md for the dataset link and
full attribution.
The sample images are distributed under CC BY 4.0 (inherited from the
source dataset), not under the Apache-2.0 licence covering the code and
weights.
Each cell type is routed through its lineage branch, then through a task-specific
gate before its regression head.
If a checkpoint was trained with different architecture settings, pass them
explicitly — the defaults must match how the weights were trained:
model = load_model(weights, backbone="resnet50", input_proj_dim=None)
Limitations and intended use
Research use only. Not a medical device; not validated for clinical or
diagnostic use.
Performance on unseen tissue types, scanners, or staining protocols may degrade.
Outputs are relative quantile values, not absolute cell counts or densities.
Accuracy varies by cell type; rarer populations are predicted less reliably.
Consult the evaluation table before relying on any individual cell type.
License and attribution
The code and the hoptimus / resnet50 weights are released under the
Apache License 2.0.
The hoptimus weights are a derivative work of H-optimus-0 (Bioptimus),
also Apache-2.0. The encoder weights have been modified (fine-tuned) from
the original release. The original copyright notice is retained in NOTICE.
1@software{hoptimus0,
2 author = {Saillard, Charlie and Jenatton, Rodolphe and Llinares-L{\'o}pez, Felipe
3 and Mariet, Zelda and Cahan{\'e}, David and Durand, Eric and Vert, Jean-Philippe},
4 title = {H-optimus-0},
5 year = {2024},
6 url = {https://github.com/bioptimus/releases/tree/main/models/h-optimus/v0}
7}
89@article{lu2024conch,
10 title = {A visual-language foundation model for computational pathology},
11 author = {Lu, Ming Y and Chen, Bowen and Williamson, Drew F K and others},
12 journal = {Nature Medicine},
13 year = {2024}
14}