Attribute Error: collections.OrderedDict' object has no attribute 'eval'

I save my model using the following code.

Path = “Model/model.pth”, Path)

Now, i am trying to load the trained model using following code,

model = torch.load(“Model/model.pth”)

But the following error occurred.
AttributeError: ‘collections.OrderedDict’ object has no attribute ‘eval’

You have to do something like this:
Save:, PATH)


model = TheModelClass(*args, **kwargs)

For more information:

1 Like

It worked.
Thank you so much :slight_smile:

I save my model using the following code.

def save(self, file_path, e):, os.path.join(file_path, ‘spt_{:03d}.pth’.format(e))), os.path.join(file_path, ‘tmp_{:03d}.pth’.format(e)))

def load(self, file_path):

But I meet this problem,can you help me?Thank you very much !!!
Traceback (most recent call last):
File “/home/wuting/anaconda3/envs/python=3.8/lib/python3.8/site-packages/torch/”, line 308, in _check_seekable
AttributeError: ‘EasyDict’ object has no attribute ‘seek’

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “”, line 109, in
File “”, line 64, in main
File “/home/wuting/Spatialtem-multi/tools/”, line 70, in main
File “/home/wuting/Spatialtem-multi/tools/”, line 78, in setup_net = TwoStreamNet(self.device)
File “/home/wuting/Spatialtem-multi/lib/netwrapper/”, line 39, in init
File “/home/wuting/Spatialtem-multi/lib/netwrapper/”, line 53, in create_load
File “/home/wuting/Spatialtem-multi/lib/netwrapper/”, line 207, in load
File “/home/wuting/anaconda3/envs/python=3.8/lib/python3.8/site-packages/torch/”, line 581, in load
with _open_file_like(f, ‘rb’) as opened_file:
File “/home/wuting/anaconda3/envs/python=3.8/lib/python3.8/site-packages/torch/”, line 235, in _open_file_like
return _open_buffer_reader(name_or_buffer)
File “/home/wuting/anaconda3/envs/python=3.8/lib/python3.8/site-packages/torch/”, line 220, in init
File “/home/wuting/anaconda3/envs/python=3.8/lib/python3.8/site-packages/torch/”, line 311, in _check_seekable
raise_err_msg([“seek”, “tell”], e)
File “/home/wuting/anaconda3/envs/python=3.8/lib/python3.8/site-packages/torch/”, line 304, in raise_err_msg
raise type(e)(msg)
AttributeError: ‘EasyDict’ object has no attribute ‘seek’. You can only torch.load from a file that is seekable. Please pre-load the data into a buffer like io.BytesIO and try to load from it instead.

I change torch.oad as this,like that it is work.

def load(self, file_path):

note:PATH is Specific weight paths。But I don not know why?maybe it needs the real path?

but in this way,the loss is ery biggest.Why?can you help me ?