machine-learning - Fastai 学习者未加载
问题描述
所以我正在尝试使用以下方法加载模型:
learn = create_cnn(data, models.resnet50, lin_ftrs=[2048], metrics=accuracy)
learn.clip_grad();
learn.load(f'{name}-stage-2.1')
但我收到以下错误
RuntimeError: Error(s) in loading state_dict for Sequential:
size mismatch for 1.8.weight: copying a param with shape torch.Size([5004, 2048]) from checkpoint, the shape in current model is torch.Size([4542, 2048]).
size mismatch for 1.8.bias: copying a param with shape torch.Size([5004]) from checkpoint, the shape in current model is torch.Size([4542]).
唯一不同的是我添加了一个stage-2.1
模型中不存在的随机验证拆分,当我删除拆分并且没有验证集时,因为stage-2.1
训练一切顺利。
发生了什么?
解决方案
使用cnn_learner
方法和最新Pytorch
与最新FastAI
。有一个breaking change
不连续的,所以你现在受苦了。
fastai 网站有很多例子,例如this one
.
learn = cnn_learner(data, models.resnet50, metrics=accuracy)
推荐阅读
- json - 无聊的 Ssl iOS 12
- lstm - 使用RNN(LSTM)时如何处理不随时间变化的特征
- apache-spark - 如何在pyspark中找到每列的平均长度?
- python - 从创建的列表框中突出显示项目(Tkinter)
- node.js - 文件名存储在环境变量中时无法使用nodejs fs模块读取文件
- python - Pandas 脚本卡在 Unix 服务器上,但不在 Windows 上
- php - 如何通过在下拉列表中选择并在表格中显示来获取所有项目名称
- javascript - Lodash 的 _.debounce() 在 Vue.js 中不起作用
- python - 如何在内部跟踪 Python 枚举值?
- java - 收到错误“此方法必须返回 java.lang.String 类型的结果”