scvi-tools icon indicating copy to clipboard operation
scvi-tools copied to clipboard

Error when updating format

Open ccruizm opened this issue 2 years ago • 3 comments

Good day,

I am trying to update a model I created with an older version of scvi scvi.model.SCVI.convert_legacy_save('./results/reference_signatures/', './results/eference_signatures_updated/') but get the error below:

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
Input In [12], in <cell line: 1>()
----> 1 scvi.model.SCVI.convert_legacy_save('./results/gbm_all_cell2location_gbmverse/reference_signatures/', 
      2                          './results/gbm_all_cell2location_gbmverse/reference_signatures_updated/')

File ~/miniconda3/envs/cell2loc_env/lib/python3.9/site-packages/scvi/model/base/_base_model.py:673, in BaseModelClass.convert_legacy_save(cls, dir_path, output_dir_path, overwrite, prefix)
    671     unlabeled_category_key = "unlabeled_category_"
    672     unlabeled_category = attr_dict.get(unlabeled_category_key, None)
--> 673     attr_dict["registry_"] = registry_from_setup_dict(
    674         cls,
    675         scvi_setup_dict,
    676         unlabeled_category=unlabeled_category,
    677     )
    679 model_save_path = os.path.join(output_dir_path, f"{file_name_prefix}model.pt")
    680 torch.save(
    681     dict(
    682         model_state_dict=model_state_dict,
   (...)
    686     model_save_path,
    687 )

File ~/miniconda3/envs/cell2loc_env/lib/python3.9/site-packages/scvi/data/_compat.py:130, in registry_from_setup_dict(model_cls, setup_dict, unlabeled_category)
    128     field_summary_stats.update(field_state_registry)
    129 elif attr_name == _constants._ADATA_ATTRS.OBS:
--> 130     categorical_mapping = categorical_mappings[attr_key]
    131     # Default labels field for TOTALVI
    132     if (
    133         model_cls.__name__ == "TOTALVI"
    134         and new_registry_key == REGISTRY_KEYS.LABELS_KEY
    135     ):

KeyError: '_indices'

I am using scvi-tools 0.16.4 and the model was created with version 0.13.0

Thanks in advance

ccruizm avatar Jul 02 '22 09:07 ccruizm

Was the original model an SCVI model? Or was it e.g., stereoscope, etc.

adamgayoso avatar Jul 02 '22 13:07 adamgayoso

Sorry forgot to mention, it was a model generated using cell2location

ccruizm avatar Jul 02 '22 13:07 ccruizm

I am trying now to generate the model again with the new version but once I reach scvi.data.setup_anndata I get the error below:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [22], in <cell line: 2>()
      1 # prepare anndata for the regression model
----> 2 scvi.data.setup_anndata(adata=adata_ref,
      3                         # 10X reaction / sample / batch
      4                         batch_key='author',
      5                         # cell type, covariate used for constructing signatures
      6                         labels_key='cell_type',
      7                         # multiplicative technical effects (platform, 3' vs 5', donor effect)
      8                         categorical_covariate_keys=['platform', 'method']
      9                        )
     10 scvi.data.view_anndata_setup(adata_ref)

AttributeError: module 'scvi.data' has no attribute 'setup_anndata'

As I mentioned earlier the version is 0.16.4 and I installed using pip install scvi-tools in a fresh conda env

ccruizm avatar Jul 02 '22 23:07 ccruizm

was this resolved?

adamgayoso avatar Mar 22 '23 04:03 adamgayoso

Closing due to inactivity

martinkim0 avatar Nov 22 '23 12:11 martinkim0