Is it possible to get the saved model from h5ad file?

I am new to python for scRNAseq. My collaborator shared a h5ad file with “processed data”. They did integration and UMAP etc with scvi.

I wonder if it is possible to get the trained model out from the h5ad file. I tried to google but with no luck and many tutorials are start with raw data. I do not want to rerun the integration but to get the normalized count from the file. Would it be possible (i.e. whether the model was not saved in h5ad)?

I have tried these:

import scanpy as sc
import scvi
adata = sc.read_h5ad('shared.h5ad')
model = scvi.model.SCVI(adata)

However, I got the following error which guide me to rerun the model training etc.

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/miniconda3/envs/pythonsc/lib/python3.10/site-packages/scvi/model/", line 112, in __init__
  File "/miniconda3/envs/pythonsc/lib/python3.10/site-packages/scvi/model/base/", line 92, in __init__
    self._adata_manager = self._get_most_recent_anndata_manager(
  File "/miniconda3/envs/pythonsc/lib/python3.10/site-packages/scvi/model/base/", line 289, in _get_most_recent_anndata_manager
    raise ValueError(
ValueError: Please set up your AnnData with SCVI.setup_anndata first.

I have also tried the method mentioned here, but seems I do not have the “” file.

Hi, you need access to the files generated from in order to load in the trained model, which includes the model parameters as well as the gene names used to set up the model. There is no way to get the trained model from just the AnnData.

Once you have access to the model parameters (which should come in a folder), you can load in the saved model with

adata = anndata.read_h5ad(adata_path)
model = scvi.model.SCVI.load(model_path, adata=adata)

Thanks for your reply. Do you mean the model is not saved in the h5ad file? I would like to know what is the file type I should ask for (in case I will need to email my collaborator).

No, the h5ad will only contain the data that the model was trained on. You should be asking for the file outputted from You can see an example of this in our tutorial.

1 Like