spared.spot_features.compute_patches_predictions
- spared.spot_features.compute_patches_predictions(adata: AnnData, backbone: str = 'densenet', model_path: str = 'None', patch_size: int = 224) None[source]
Compute predictions for patches.
This function computes gene expression predictions 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 predictions are stored inadata.obsm[f'predictions_{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.All models will be declared to have the same number of outputs as genes in the
adataobject (adata.n_vars). Please also note that if you try to predict with a model that has only been pretrained on ImageNet, the predictions will be random and not useful. So always try to use models pretrained in spatial transcriptomics datasets.- 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.