python - the_model = TheModelClass(*args, **kwargs) 是什么意思?
问题描述
我正在使用 PyTorch 进行图像分类。训练最多后,我想保存训练好的模型。
我不明白是什么意思
the_model = TheModelClass(*args, **kwargs)
这行代码由 PyTorch 网站 ( https://pytorch.org/docs/master/notes/serialization.html ) 提供。
解决方案
这个问题the_model = TheModelClass(*args, **kwargs)
意味着您必须首先定义一个 ModelClass 对象。然后您可以使用模型对象来加载磁盘顺序对象。例如:
in_feats = data.x.shape[1]
n_hidden = params["n_hidden"]
n_classes = 2
best_model = OwnGCN(in_c=in_feats, hid_c=n_hidden, out_c=n_classes)
best_model.load_state_dict(torch.load(PATH))
推荐阅读
- haskell - 新类型读取器 monad 的强制对其值类型进行强制
- arrays - 数组结果存储在 firebase 数据库中并显示在集合视图中
- macos - scp 无法在 Mac 上解析主机名
- cucumber - Cucumber:在每个功能文件中使用完全相同的小黄瓜设置步骤
- php - 无法将字符串转换为 XML 对象
- python - Python Pygame:在对象中使用 python.draw.rect 时出错
- r - 如果它们与另一个 data.table 中的值匹配,如何更新 data.table 中的选定行
- r - 如何用几个定性变量绘制 ggplot + geom(line)?
- reactjs - 为什么 React 应用程序会在 Heroku 上占用大量内存?
- java - 如何根据当前日期突出显示表格布局中的列