Error while loading model of Spatial data deconvolution using cell2location
0
0
Entering edit mode
12 days ago

Hello everyone,

I am trying to deconvolute the spatial data using single cell data annotation using cell2location. My first step is all fine. However, when I am loading the model again, it gives me the following error.

Code used :

adata_ref = adata_ref[:, selected].copy()
cell2location.models.RegressionModel.setup_anndata(adata=adata_ref,
                   # 10X reaction / sample / batch
                   batch_key='orig.ident',
                   # cell type, covariate used for constructing signatures
                   labels_key='celltype_sub',
                   # multiplicative technical effects (platform, 3' vs 5', donor effect)
                  )

# create the regression model
from cell2location.models import RegressionModel

mod = RegressionModel(adata_ref)

mod.train(max_epochs=300, use_gpu=True)
mod.save(f"{ref_run_name}", overwrite=True)
adata_file = f"{ref_run_name}/sc.h5ad"
adata_ref.write(adata_file)

# load the model
mod = cell2location.models.Cell2location.load(f"{run_name}", adata_ref)

Error I get :

ValueError                                Traceback (most recent call last)
Cell In[8], line 1
----> 1 mod = cell2location.models.Cell2location.load(f"{run_name}", adata_ref)
File ~/miniconda3/envs/cell2loc_env/lib/python3.9/site-packages/scvi/model/base/_base_model.py:702, in BaseModelClass.load(cls, dir_path, adata, use_gpu, accelerator, device, prefix, backup_url)
    700 registry = attr_dict.pop("registry_")
    701 if _MODEL_NAME_KEY in registry and registry[_MODEL_NAME_KEY] != cls.__name__:
--> 702     raise ValueError(
    703         "It appears you are loading a model from a different class."
    704     )
    706 if _SETUP_ARGS_KEY not in registry:
    707     raise ValueError(
    708         "Saved model does not contain original setup inputs. "
    709         "Cannot load the original setup."
    710     )
ValueError: It appears you are loading a model from a different class.

By any chance, has anyone else encountered same error, can someone please suggest the issue. I am mostly sure with the previous code.

Python cell2location • 126 views
ADD COMMENT

Login before adding your answer.

Traffic: 1040 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6