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.

class SpaHDmap.model.GraphAutoEncoder(adj_matrix, num_spots, rank=20)[source]

A graph autoencoder for predicting spot embeddings.

Parameters:
  • adj_matrix (Tensor) – The adjacency matrix of the graph.

  • num_spots (int) – The number of spots in the dataset.

  • rank (int) – The rank of the graph autoencoder. Defaults to 20.

Example

>>> adj_matrix = torch.rand(10, 10)
>>> model = GraphAutoEncoder(adj_matrix, num_spots=5, rank=20)
>>> score = torch.rand(5, 20)
>>> model(score)
forward(score)[source]

Forward pass for the GraphAutoEncoder.

Parameters:

score – Input tensor representing the sequenced spot embeddings.

Returns:

y

Reconstructed spot embedding whose values are limited to [0, 1].

Note

For implementation of the UNet model, we refer to the model HINet and its open-source code.

Thanks for the authors for their great work.