Model¶
The Model module of SpaHDmap encapsulates the model architecture, including the SpaHDmapUnet and the GraphAutoEncoder.
- class SpaHDmap.model.SpaHDmapUnet(rank=20, num_genes=2000, num_channels=3, reference=None)[source]¶
A deep learning architecture for image and spot expression prediction. It integrates Non-negative Matrix Factorization (NMF) and low-rank representation, enabling efficient prediction and high-definition pixel-wise embedding output.
- Parameters:
rank (
int) – The rank of the low-rank representation. Defaults to 20.num_genes (
int) – The number of genes in the dataset. Defaults to 2000.num_channels (
int) – The number of channels in the input image. Defaults to 3.reference (
Optional[dict]) – Dictionary of query and reference pairs, e.g., {‘query1’: ‘reference1’, ‘query2’: ‘reference2’}. Only used for multi-section analysis. Defaults to None.
Example
>>> model = SpaHDmapUnet(rank=20, num_genes=1000, num_channels=3) >>> image = torch.rand(1, 3, 256, 256) >>> feasible_coord = {} >>> vd_score = torch.rand(1) >>> model(image, feasible_coord, vd_score)
- forward(image, section_name=None, feasible_coord=None, vd_score=None, encode_only=False)[source]¶
Forward pass for the SpaHDmapUnet model.
- Parameters:
image – Input image tensor.
section_name – Section name for batch effect removal. Default to None.
feasible_coord – Dictionary of feasible coordinates. Default to None.
vd_score – Input tensor representing the sequenced spot embeddings. Default to None.
encode_only – Whether to only perform encoding. Default to False.
- Returns:
- image_pred
Predicted image.
- spot_exp_pred
Predicted spot expression (if feasible coordinates are provided).
- HR_score
High-resolution pixel-wise embedding output.