Platform: Kaggle Kernels


I was able to get the model weights to output. If you save the model in the main directory it will output the weights. Please see this kernel

Share your work here ✅
Share your work here ✅
(Jon Burrell) #84

FYI kaggle now seems to be using fastai 1.0.45

(深度碎片) #85

yes, you are right.

To be more specific, we can save model with `’/kaggle/working/model_1’)

(Francisco Ferreira) #86

If I’m on a competition where it’s not allowed internet connection on kernels, how can i use a pre-trained fast-ai resnet34 cnn?

(Kazeem Hakeem) #87

yeah, ‘1.0.45’

(Kazeem Hakeem) #88

you can upload your pre-trained AWD LSTM as a dataset in kaggle, then in your kaggle kernel you can “Add Data” and select your dataset.

(Stan Sidel) #89

I tried using this approach. But the learner fails to load the pretrained model, even thought that’s the one it downloaded itself a few minutes before.

The notebook describes all the steps and errors occurred. Do you know what’s wrong there?

(Sanyam Bhutani) #90

I update the kernels every weekend so any updates pushed out mid-week cause some breakage now and then.
Sorry for the issues, I’ll try to update them mid-week :slight_smile:

(Kazeem Hakeem) #91

learn = create_cnn(data, models.resnet34, metrics=error_rate, pretrained=False, model_dir=str(models_path.absolute())) in your notebook.
this was how i did it.
model_path = “/kaggle/input/resnet34/resnet34”
i copied my dowloaded resnet34 into kaggle/working/models/
!cp -r /kaggle/input/resnet34/ /kaggle/working/models/
initialised my model
model = create_cnn(data, models.resnet34, metrics=accuracy, path=".", pretrained=False, model_dir=’/kaggle/working/models/resnet34/resnet34’)
then you can fit with that

(深度碎片) #92

Kaggle kernel allows us to run !pip install fastai==1.0.46 to install the latest version fine, but when load the library, the latest is not used.

see this proof in Kaggle

(Stan Sidel) #93

Thank you for the suggestion. I don’t quite get how it’s different from my solution, except for the missing step of loading the copied model. As far as my understanding of the process goes, it only creates a new network with resnet34 architecture and randomly initialized weights. It doesn’t use the copied file in any way.

I’ve updated the notebook with your example. It supports my guess that the weights from the resnet34.pth weren’t used. I might have messed up with the directories somehow, though. Could you please tell the output of the following commands?

# What's in your datasource directory
!ls -lah /kaggle/input/resnet34/
# The working directory should have the content of /kaggle/input/resnet34/ I guess
# Why is it /kaggle/working/models/resnet34/resnet34 you're using for your model_dir?
# Is there any special file that create_cnn can read?
!ls -lah /kaggle/working/models/
!ls -lah /kaggle/working/models/resnet34
!ls -lah /kaggle/working/models/resnet34/resnet34

And just to be sure, did you compare the results of using the model from dataset, as you suggest, to the ones from loading it (on another machine maybe)?

(Jerry Melcore) #94

I have a few beginner questions, as doing the course using Kernels doesn’t seem to be working for me.

Most importantly, how can you actually save your work? I’m trying to do lesson 1, and have been trying for about 2 days to get through it. It’s taking between up to 40 minutes to train a model, and sometimes this is long enough for the Kernel to stop responding/time out. No error message, just stops responding completely. When I reload the kernel, I would like to be able to load the model so I don’t have to spend 60+ minutes going through the notebook. Unfortunately, I can’t figure out how to load the data, as the saved models don’t seem to persist if I have to refresh the page. Is this even possible with kernels?

I also tried looking into exporting the pth files after saving the model, but in order to do this, it looks like you have to ‘commit’ the kernel - but this process takes over 90 minutes, and requires running the notebook start to finish, with no promise that it won’t time out, so I unfortunately haven’t been able to save my work this way.

I assume I’m just not understanding the workflow I should be using to work using kernels. Can someone provide me some guidance? As it is, I can’t really even get through the first lesson, as it is taking so long, and I don’t have a way of saving progress. Do other platforms have similar limitations?

(Bhuvana Kundumani) #95


You can use Google Colab for fast ai. Please check this link to get started


Same question for Lesson 2 – I’m wanting to pull the weights and labels.csv for a dataset I spent time cleaning-up.


The timeout is a known problem of the Kaggle Kernels if you do not commit. But if you commit, it should not timeout and you should be able to export your model as pth files.


Where is this export you speak of :wink:

#99 should work…


As near as I can tell, is just dropping output onto ephemeral storage. Once the Kaggle Kernal session expires so do any files created during the session.


@Steve It depends on the path of the model… If it’s in the main directory it should be under the output tab after committing. Please see this kernel and this kernel as examples.

People have asked so many times on how to do this I ought to have a dedicated kaggle kernel and a post here to demonstrate…


@ilovescience I can see the .pth files being created in the /kaggle/working/models directory while running through the notebook. I can commit the notebook and view it in Kernels --> My Work --> Output. I can click on the notebook and see the Notebook, Data, Log, and Comments links on the left-hand rail but under Data I only see the Source Data not the .pth files.

I also see Data Files under Output but just see a message that, “You haven’t created any kernels yet.” when I select Data Files. I’ve been poking at this for awhile now and need a break. Thank you for your assistance!!