Pickled model fails, but generated model works

I’m trying to get everything to run locally in Windows 10 in Visual Studio Code and so I’m still working through the code in 01_intro.ipynb.

When I run learn.show_results(max_n=6, figsize=(7,8)) using the model generated for camvid_tiny (Deep Learning Is Not Just for Image Classification) Target/Prediction is displayed as expected. However, when I export the model and then load it with:

#export the model to pickle it for later use to avoid performing the process above every time
#run this to load the camvid_tiny model, model copied over and renamed
path = 'C:\HOME\.fastai\data\camvid_tiny\model\camvid_tiny_model.pkl'
learn = load_learner(path)

to spare myself from running from scratch, I get the following error:

ValueError                                Traceback (most recent call last)
<ipython-input-11-97dc52a4ec2e> in <module>
----> 1 learn.show_results(max_n=6, figsize=(7,8))

C:\Users\jbiss\AppData\Local\Programs\Python\Python36\lib\site-packages\fastai\learner.py in show_results(self, ds_idx, dl, max_n, shuffle, **kwargs)
    260     def show_results(self, ds_idx=1, dl=None, max_n=9, shuffle=True, **kwargs):
    261         if dl is None: dl = self.dls[ds_idx].new(shuffle=shuffle)
--> 262         b = dl.one_batch()
    263         _,_,preds = self.get_preds(dl=[b], with_decoded=True)
    264         self.dls.show_results(b, preds, max_n=max_n, **kwargs)

C:\Users\jbiss\AppData\Local\Programs\Python\Python36\lib\site-packages\fastai\data\load.py in one_batch(self)
    134     def to(self, device): self.device = device
    135     def one_batch(self):
--> 136         if self.n is not None and len(self)==0: raise ValueError(f'This DataLoader does not contain any batches')
    137         with self.fake_l.no_multiproc(): res = first(self)
    138         if hasattr(self, 'it'): delattr(self, 'it')

ValueError: This DataLoader does not contain any batches

What am I missing about generating models, exporting and then loading them that makes them act differently from them when run directly? I use the pickled model generated from the pet images without any such problems. Is this covered fully later in the course?

Exported models have their data wiped, so you’re trying to show results without any data (I believe this is mentioned in the doc string and documentation as well)

1 Like