Hello!
I created, trained and saved my model MyModel
in Jupiter as 'mymodel.pt'
. But then I want to load it in another application. To do this, I created the same class in the file where I load it:
class MyModel(nn.Module):
def __init__(self):
...
def forward(self, x):
...
This file is the file with the predictor class, which is run through uvicorn
. And when I run torch.load(path_to_pt)
, I see an error that there is no class MyModel
:
File "/usr/local/lib/python3.8/dist-packages/torch/serialization.py", line 851, in _load
result = unpickler.load()
AttributeError: Can't get attribute 'MyModel' on <module '__main__' from '/usr/local/bin/uvicorn'>
I understand that the MyModel
class is called differently:
>>> print(MyModel)
# <class 'classification.my_model.MyModel'>
And I understand that this shouldn’t be a problem when working through env
, but is there any way I can solve this problem without going to env
?