DeepSpotM¶

class DeepSpotM(repo_id_or_path='ratschlab/DeepSpotM', source='scgpt', genes=None, *, device='cpu', revision=None)[source]¶

DeepSpot-M model for virtual spatial transcriptomics from H&E.

Wraps the standalone deepspotm package as a tiatoolbox model. A forward pass maps a batch of 224x224 H&E tiles to predicted spatial gene expression; run it through tiatoolbox.models.engine.deep_feature_extractor.DeepFeatureExtractor to score a whole-slide image tile by tile.

Parameters:
  • repo_id_or_path (str) – Hugging Face repo id or a local directory holding the exported model (config.json, model.safetensors, tokens.csv). Default is "ratschlab/DeepSpotM" (gated).

  • source (str) – Gene-embedding source to activate, one of DEEPSPOTM_SOURCES. Default is "scgpt".

  • genes (str | Sequence[str] | None) – Restrict the prediction to these gene symbols (order preserved). Only the selected gene queries are computed, which is faster and keeps the output matrix small. Default None predicts the full panel (~19k genes). Unknown symbols raise KeyError.

  • device (str) – Device passed to the underlying loader. Default "cpu". The DeepFeatureExtractor engine manages device placement at run time, so this mainly matters when the model is used directly.

  • revision (str | None) – Optional Hugging Face revision (tag, branch, or commit).

model¶

The wrapped deepspotm model.

Type:

torch.nn.Module

image_processor¶

DeepSpot-M’s evaluation image transform (resize to 224, center-crop, normalize). Applied per tile in infer_batch().

Type:

Callable

gene_names¶

Ordered gene symbols; gene_names[i] labels output column i.

Type:

list[str]

gene_indices¶

Column indices of the selected genes, or None for the full panel.

Type:

torch.Tensor | None

Example

>>> import numpy as np
>>> model = DeepSpotM(source="scgpt", genes=["EPCAM"])
>>> tiles = np.random.randint(0, 255, (4, 224, 224, 3), dtype=np.uint8)
>>> features = DeepSpotM.infer_batch(model, tiles, device="cpu")[0]
>>> features.shape
(4, 1)

Initialize DeepSpotM.

Methods

forward

Predict gene expression for a batch of preprocessed tiles.

infer_batch

Run inference on a batch of raw H&E tiles.

Attributes

training

forward(imgs)[source]¶

Predict gene expression for a batch of preprocessed tiles.

Parameters:
Returns:

Predicted expression, shape (N, len(gene_names)).

Return type:

torch.Tensor

static infer_batch(model, batch_data, device='cpu')[source]¶

Run inference on a batch of raw H&E tiles.

Applies DeepSpot-M’s own image transform to each tile before predicting, and returns a single-element list so the DeepFeatureExtractor engine stores the predictions as an (n_tiles, n_genes) matrix (mirroring the feature-extractor contract).

Parameters:
  • model (ModelABC) – A DeepSpotM instance.

  • batch_data (np.ndarray | torch.Tensor) – A batch of tiles in NHWC (channel-last) RGB layout, as produced by the tiatoolbox WSI patch loader.

  • device (str) – Device to run inference on. Default "cpu".

Returns:

Single-element list holding the (n_tiles, n_genes) expression array.

Return type:

list[np.ndarray]