# Is it possible to add extra covariate categories to a trained SCVI model?

**URL:** <https://discourse.scverse.org/t/is-it-possible-to-add-extra-covariate-categories-to-a-trained-scvi-model/3276>\
**Category:** scvi-tools\
**Tags:** scrna-seq, integration, scanvi, scvi\
**Created:** [October 2, 2024, 3:07pm UTC](https://discourse.scverse.org/t/is-it-possible-to-add-extra-covariate-categories-to-a-trained-scvi-model/3276 "2024-10-02T15:07:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![wikiselev](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/wikiselev/32/260_2.png) [@wikiselev](https://discourse.scverse.org/u/wikiselev)\
**Post date:** [October 2, 2024, 3:07pm UTC](https://discourse.scverse.org/t/is-it-possible-to-add-extra-covariate-categories-to-a-trained-scvi-model/3276/1 "2024-10-02T15:07:22Z")

</div>

I execute the following steps to predict cell types in a query dataset using a reference dataset:

1. Train an SCVI model on a reference dataset with categorical covariates.
2. Concatenate query and reference datasets.
3. Create a SCANVY model using the concatenated dataset and the SCVI model above.
4. Train the SCANVY model.

During the creation of the SCANVY model I get an error saying that the covariate categories of the query dataset are different from that of the reference.

The only workaround to this problem that I’ve found is to add the query categories to the reference adata object before training the reference. But it does not seem like a sustainable solution as I will need to retrain the SCVI model for every new query dataset.

Is there any way to add extra covariate categories to an already trained SCVI model?

---

<div class="post-metadata">

**Author:** ![cane11](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/cane11/32/241_2.png) [@cane11](https://discourse.scverse.org/u/cane11)\
**Post date:** [October 2, 2024, 5:38pm UTC](https://discourse.scverse.org/t/is-it-possible-to-add-extra-covariate-categories-to-a-trained-scvi-model/3276/2 "2024-10-02T17:38:27Z")

</div>

Hi, we added support for scArches and categorical covariates in 1.2 (extending categorical covariates). However, the [`from_scvi_model`](https://docs.scvi-tools.org/en/stable/api/reference/scvi.model.SCANVI.html#scvi.model.SCANVI.from_scvi_model) function doesn’t extend batches or covariates but you would need to use [`load_query_data`](https://docs.scvi-tools.org/en/stable/api/reference/scvi.model.SCANVI.html#scvi.model.SCANVI.load_query_data). For this you should first convert your SCVI model to a SCANVI model (from\_scvi\_model) and can then without training use the load\_query\_data function. This API is meant so across models only load\_query\_data extend categories.

---

<div class="post-metadata">

**Author:** ![wikiselev](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/wikiselev/32/260_2.png) [@wikiselev](https://discourse.scverse.org/u/wikiselev)\
**Post date:** [October 4, 2024, 2:04pm UTC](https://discourse.scverse.org/t/is-it-possible-to-add-extra-covariate-categories-to-a-trained-scvi-model/3276/3 "2024-10-04T14:04:55Z")

</div>

Great, many thanks for your answer, it helped a lot! However, I did need to train SCANVI model before `load_query_data`, otherwise the predictions did not work. I’ve also found [this resource](https://www.sc-best-practices.org/cellular_structure/integration.html#vae-integration-using-cell-labels), which also suggests to train the SCANVI model.

---

<div class="post-metadata">

**Author:** ![cane11](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/cane11/32/241_2.png) [@cane11](https://discourse.scverse.org/u/cane11)\
**Post date:** [October 4, 2024, 2:56pm UTC](https://discourse.scverse.org/t/is-it-possible-to-add-extra-covariate-categories-to-a-trained-scvi-model/3276/4 "2024-10-04T14:56:12Z")

</div>

After initializing the SCANVI model, you can also train it and afterwards integrate query data with load\_query\_data. In the approach above, you have to unfreeze the network using _unfrozen=False_ in load\_query\_data otherwise it doesn’t train the SCANVI model (sorry for the oversight).
