How to load FastAI learner with custom functions inside __init__() function of class?

Hi All,

fastai version: 2.7.9.

I need to load a fastai learner inside a class __init__() method. The learner has a few custom functions such as get_image_mask, combo_loss, etc. which need to be present in the namespace for successfully loading the learner through the load_learner() method.

I tried defining these functions inside the class as static functions but received the error saying custom classes or functions exported with leaner are not available in the namespace. And the loading fails.

Shall I put these as nested functions inside the __init__() for this to make it work or what are the guidelines for such a use case?

Any ideas will be greatly appreciated.

Many thanks and

Kind Regards,