pytorch - 在不使用互联网的情况下在 Kaggle 内核中加载预训练的 FastAI 模型
问题描述
我正在尝试在不打开 Internet 的情况下在 Kaggle 内核中加载一个 densenet121 模型。我已经完成了所需的步骤,例如将预训练的权重添加到我的输入目录并将其移动到“.cache/torch/checkpoints/”。它仍然无法正常工作并引发 gaierror。
以下是代码片段:
!mkdir -p /tmp/.cache/torch/checkpoints
!cp ../input/fastai-pretrained-models/densenet121-a639ec97.pth /tmp/.cache/torch/checkpoints/densenet121-a639ec97.pth
learn_cd = create_cnn(data_cd, models.densenet121, metrics=[error_rate, accuracy],model_dir = Path('../kaggle/working/models'),path=Path('.'),).to_fp16()
我已经为此苦苦挣扎了很长时间。任何帮助都会非常有帮助
解决方案
所以 kaggle 内核中的输入路径“../input/”是只读的。在“kaggle/working”中创建一个文件夹,然后将模型权重复制到那里。下面的例子
if not os.path.exists('/root/.cache/torch/hub/checkpoints/'):
os.makedirs('/root/.cache/torch/hub/checkpoints/')
!mkdir '/kaggle/working/resnet34'
!cp '/root/.cache/torch/hub/checkpoints/resnet34-333f7ec4.pth' '/kaggle/working/resnet34/resnet34.pth'
推荐阅读
- ios - iOS 获取系统可访问性缩放类型
- php - 我在 LAMP 上创建的目录在 WAMP 中不起作用
- javascript - 获取异步函数的价值,在 SAPUI5 中完成
- css - 如何从角度组件中访问本地 css 类名
- mercurial - 带有 --filemap 的 Mercurial 转换因任何虚拟重命名而失败
- c# - 在控制器(ASP.NET Core)中进行 DI 时如何在 SignalR 中使用 Clients.Caller 和 Clients.Others?
- javascript - 如何从没有 mySql(PHP、AJAX、JQuery、JS)的表单控件中修复空数组
- c# - c# 创建一个可重用的方法来访问对象内部的属性
- php - 从父母那里选择地址
- c# - 如何使用方法替换特定字符串?