Issue during test stage when load_from_checkpoint

hi guys! I’ve already accomplished training stage like this:
model = PL_Model(cfg)
trainer = Trainer(…)
trainer.fit(model)
now I need to test some data on the trained model, so I add
def test_step() and def test_end()
into the class PL_Model(), and test like this:
model = PL_Model(cfg).load_from_checkpoint(PATH)
trainer = Trainer(…)
trainer.test(model)
the error is:
File “…/lib/python3.6/site-packages/torch/nn/modules/module.py”, line 585, in getattr
type(self).name, name))
AttributeError: ‘PL_Model’ object has no attribute ‘load_from_checkpoint’
how can i fix it?

mind reproduce it with Google Colab??

thanks for your reply!!
but are there any solutions to test separately with an existed .ckpt file without AttributeError above?

the above error seems strange and should not occur since load_from_checkpoint is a classmethod in LightningModule. So I’m not sure why it’s not working for you. That’s why I requested a minimal reproducable code to check the issue.

I meet the same problem when using jupyter. After restart the jupyter, the problem is gone. I donot know why. But maybe it deserve to try Just Restart OR Reinstall.

1 Like

Personally, I found this problem is occurring because of the way I imported the model.
Fixed by changing:

import models.MyNetwork as MyNetwork

To:

from models.MyNetwork import MyNetwork