How to Save Notebook (With GPU state etc)

  1. How can I save the notebook to load it later? If I hibernate the notebook, it doesn’t seem to work after I reboot.

  2. Alternatively, how can I save the weights to reload them later? If I save the weights like in lesson 1 (such as : " learn.save('224_lastlayer') "), I still have to retrain to load new ones (requiring rer-running : " learn = ConvLearner.pretrained(arch, data, precompute=True) "). Isn’t there a way to just dump the whole thing so it can be created based on a saved file maybe with h5py or something?

2 Likes

fastai provides a very nice api for this :slight_smile:

learn.save('file_name')
learn.load('file_name')
1 Like

yes, but how can you create the Object “learn” without training again?

You initialize the model how you initialized it initially (define layers, use pretrained arch, etc) and then call load on it.

1 Like

Is this the best way then?

If this was how you created the learner that you saved, than I think that would be the way to go.

1 Like

so by doing that, we can skip doing “learn.fit” again?

yes, your model should be able to make predictions like at the moment when you called save on it, the weights should be restored

2 Likes

Hello, I wanted to know about loading the saved model in the enhance notebook.
m = to_gpu(SrResnet(64, scale))
m = nn.DataParallel(m, [0])
learn = Learner(md, SingleModel(m), opt_fn=optim.Adam)
learn.load(“sr1-a”)

Is this the correct way?
Getting the following error!
KeyError: ‘unexpected key “features.0.0.weight” in state_dict’