在不使用Internet的情况下将预训练的FastAI模型加载到Kaggle内核中

时间:2020-02-12 10:15:29

标签: pytorch kaggle fast-ai densenet

我试图在Kaggle内核中加载densitynet121模型,而无需打开Internet。 我已经完成了必要的步骤,例如将预训练的权重添加到我的输入目录中,然后将其移动到“ .cache / torch / checkpoints /”。它仍然无法正常工作,并引发gaierror。

以下是代码SNIPPET:

!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()

我一直为此苦苦挣扎。任何帮助都会有很大帮助

1 个答案:

答案 0 :(得分:0)

因此,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'