You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

scVI模型训练后提取潜变量报错:无get_latents属性求协助

解决scVI模型调用get_latents()时的AttributeError问题

问题重现

训练完scVI模型后,执行代码获取潜变量用于细胞注释:

# Get latent representations of the data
latent = model.get_latents()

触发如下错误:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[48], line 5
      1 ### Using directives from ChatGPT - Step 7. Use scVI to Extract Latent Variables
      2 # Once the model is trained, you can use it to extract low-dimensional representations (latent variables) of the data that capture the underlying structure of the cell types.
      3 
      4 # Get latent representations of the data
----> 5 latent = model.get_latents()

AttributeError: 'SCVI' object has no attribute 'get_latents'

解决方案

  • 替换方法名:get_latents()是scVI旧版本的API,在scvi-tools v1.0及以上版本中,该方法已被更名为get_latent_representation(),修改代码即可解决:
    # 获取数据的潜变量表示
    latent = model.get_latent_representation()
    
    如果需要指定非训练集的输入数据,可传入对应的AnnData对象:
    latent = model.get_latent_representation(adata=your_adata_object)
    
  • 确认版本兼容性:检查当前scvi-tools版本,执行以下命令查看:
    import scvi
    print(scvi.__version__)
    
    若版本低于v1.0,可选择升级到最新版本(推荐),或保持旧版本继续使用get_latents()方法。

内容的提问来源于stack exchange,提问作者Elvis Kidzeru

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 05:22:05