spared.spot_features.compute_patches_embeddings

spared.spot_features.compute_patches_embeddings(adata: AnnData, backbone: str = 'densenet', model_path: str = 'None', patch_size: int = 224) None[source]

Compute embeddings for patches.

This function computes embeddings (last layer representations) for a given backbone model and adata object. It can optionally compute using a stored model in model_path or a pretrained model from pytorch. The embeddings are stored in adata.obsm[f'embeddings_{backbone}']. The patches must already be stored in a flattened format inside adata.obsm[f'patches_scale_{patch_scale}'] and must be of shape (n_patches, patch_size*patch_size*3). The patch_scale key can be whatever you want as long as there is only one key with the word patches_scale in the obsm keys. Normally, the key is patches_scale_1.0.

The function only modifies the AnnData object in place. The patch information should be in int format from 0 to 255. All needed transformations are done inside the function.

Parameters:
  • adata (ad.AnnData) – The AnnData object with the patches to process.

  • backbone (str, optional) – A string specifying the backbone model to use. Must be one of the following ['resnet', 'resnet50', 'ConvNeXt', 'EfficientNetV2', 'InceptionV3', 'MaxVit', 'MobileNetV3', 'ResNetXt', 'ShuffleNetV2', 'ViT', 'WideResnet', 'densenet', 'swin']. Defaults to 'densenet'.

  • model_path (str, optional) – The path to a stored model. If set to 'None', then an ImageNet pretrained model is used. Defaults to 'None'.

  • patch_size (int, optional) – The size of the patches. Defaults to 224.

Raises:

ValueError – If the backbone is not supported.