Struggled with this for a while, some tips for Kaggle kernels where you don’t have internet access to download pre-trained weights:
- Under draft-environment in your kernel, click the “add-data” button, search for the relevant pytorch model. For example I wanted to use the Resnet-50, so I added the Resnet-50 Pytorch (not the Keras) model to my kernel (click “Add”).
- This will give you a new Resnet-50 directory and the *.pth weight file inside of that directory. Now you need to copy the *.pth file into the torch model directory using the same filename it’s looking for. One way to do this is to try to run the model without copying anything. I would get an error like:
failed download to /tmp/.torch/models/resnet50-19c8e357.pth
- So we need to copy the resnet50.pth file from the ResNet50 directory that was just automatically added we to the directory where it’s just errored out. My resnet50 file was in:
- Therefore, run a copy command that takes the file you have and put in the place where it’s looking for it, using the same model-sha_hash naming convention.
!cp ../input/resnet50/resnet50.pth /tmp/.torch/models/resnet50-19c8e357.pth
- Make sure you remember that your …/input directory is read only and the models are going to be changed during the learning process so you need to go up one level when creating your learner:
./: put path here
./input: read only, don’t put path here