How to export dataloaders with learner?

Hi, and sorry for what looks like a trivial question.

I am trying to export my learner, including the data loaders. I have noticed that export explicitly resets this information. See the line, from the source code of Learner.export:

self.dls = self.dls.new_empty()

So it is no wonder that after using load_learner (and then learner.load for good measure) my data loaders are empty (print(len(learner.dls.train)) returns 0).

So my two questions are:

  1. What is the logic behind this? It does not look like accidental behaviour or a bug!
  2. Is there a proper way to export my data loaders or do I need to create them each time?

It’s meant for inference, where you don’t have (or want) your data

You can just save it with torch. IE torch.save(dls, “dls.pkl”) (or even do learn directly)

2 Likes

It makes sense, yes. I was trying to separate the code for setting up my learner and the code for training, which is why I found this problem. But your suggestion seems good enough!