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

DeepChem GraphConvModel调用save保存模型时报参数数量错误如何解决

错误产生原因

  • 你使用的DeepChem版本中,GraphConvModel自带的save()为无参内部方法,不支持传入自定义保存路径,你调用时传入的"HIV_test1.h5"属于多余的第二个位置参数,因此触发参数数量不匹配的TypeError。
  • DeepChem的模型类未沿用原生Keras模型的save传参逻辑,直接按Keras使用习惯传入路径调用save方法不符合DeepChem的接口设计规范。

正确保存训练模型的方案

方案1:保存完整模型(官方推荐)

使用DeepChem提供的save_to_directory接口,可完整保存模型结构、权重、配套参数,后续加载无需重新定义模型结构:

# 保存模型到指定文件夹
model.save_to_directory("./hiv_graphconv_model")

对应加载模型的代码:

from deepchem.models import GraphConvModel
loaded_model = GraphConvModel.load_from_directory("./hiv_graphconv_model")

方案2:仅保存权重为h5格式

如果需要单独输出h5格式的权重文件,可提取模型底层的Keras实例再调用save方法:

# 获取底层Keras模型并保存权重为h5文件
model.model.save("HIV_test1.h5")

对应加载权重的代码:

# 先初始化结构完全一致的GraphConvModel
n_tasks = len(tasks)
new_model = dc.models.GraphConvModel(n_tasks, mode='classification')
# 加载预训练权重
new_model.model.load_weights("HIV_test1.h5")

内容的提问来源于stack exchange,提问作者최고당

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.19 17:36:07