I tried to load two different models from different directories; however, it seems like pytorch would first search the file model.py in the current directory to choose the loaded model’s structure. As I want to load two models, I cannot put two different model.py file in the same directory. How can I handle this case?
You can save your models as model1.py
and model2.py
with model names as my_model1
and my_model2
respectively then in main.py
you can import these model as -
from model1 import my_model1
from model2 import my_model2
I guess this should work.
Or simply just save the state_dict as shown here, because this way you won’t save an instance of torch.nn.Module
.
Have a look at this post for details when saving instances of nn.Module
That’s really helpful. Thanks!