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_pathor a pretrained model from pytorch. The embeddings are stored inadata.obsm[f'embeddings_{backbone}']. The patches must already be stored in a flattened format insideadata.obsm[f'patches_scale_{patch_scale}']and must be of shape(n_patches, patch_size*patch_size*3). Thepatch_scalekey can be whatever you want as long as there is only one key with the wordpatches_scalein theobsmkeys. Normally, the key ispatches_scale_1.0.The function only modifies the AnnData object in place. The patch information should be in
intformat from0to255. 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.