Pytorch torch.load ModuleNotFoundError: No module named 'utils'
I'm trying to load a pretrained model with torch.load.
I get the following error:
ModuleNotFoundError: No module named 'utils'

I've checked that the path I am using is correct by opening it from the command line. What could be causing this?
Here's my code:
import torch
import sys

PATH = './gan.pth'

model = torch.load(PATH)
model.eval()


EDIT:
Entire error stack:
Traceback (most recent call last):
  File &quot;load.py&quot;, line 6, in &lt;module&gt;
    model = torch.load(PATH)
  File &quot;C:\Users\user\anaconda3\envs\pytorch-flask\lib\site-packages\torch\serialization.py&quot;, line 595, in load
    return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args)
  File &quot;C:\Users\user\anaconda3\envs\pytorch-flask\lib\site-packages\torch\serialization.py&quot;, line 774, in _legacy_load
    result = unpickler.load()
ModuleNotFoundError: No module named 'utils'


EDIT this answer doesn't provide the answer for the question but addresses another issue in the given code
the .pth file just stores the parameters of a model, not the model itself. When you want to load a model you will need the .pt/-h file and the python code of your model class. Then you can load it like this:

# your model
class YourModel(nn.Modules):
    def __init__(self):
        super(YourModel, self).__init__()
        . . .

    def forward(self, x):
        . . .

# the pytorch save-file in which you stored your trained model
model_file = &quot;&lt;your path&gt;&quot;

model = Model()
model = model.load_state_dict(torch.load(model_file))

model.eval()

