Why does learn.load return self?

In the code of the Learner class in Basic_train, the load method start by performing a bunch of operations in place and ends by returning self.

def load(self, ...)
    return self

Is there a reason to both perform the loading in place and return the learner?

After doing :

learn = Learner(...)


learn = learn.load(...)



seems to achieve the same result. Is there one of those to chose over the other? And if so, why?

Both are the same, it’s just useful to return the learner when you want to chain methods.

1 Like

Ok, so for example, if you want to access the model with the loaded weights, you can do
new_model = learn.load().model
in a one liner instead of

new_model = learn.model

Is this the only reason for this method to return self, or is there more to it?

This is the only reason, it allows to chain things nicely.

1 Like