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

username: aatiibutt
cooked: <p>I save my model using the following code.</p>
<p>Path = “Model/model.pth”<br>
torch.save(Network.state_dict(), Path)</p>
<p>Now, i am trying to load the trained model using following code,</p>
<p>model = torch.load(“Model/model.pth”)<br>
model.eval()</p>
<p>But the following error occurred.<br>
AttributeError: ‘collections.OrderedDict’ object has no attribute ‘eval’</p>

username: LeErnst
cooked: <p>You have to do something like this:<br>
<strong>Save:</strong></p>
<p>torch.save(model.state_dict(), PATH)</p>
<p><strong>Load:</strong></p>
<p>model = TheModelClass(*args, **kwargs)<br>
model.load_state_dict(torch.load(PATH))<br>
model.eval()</p>
<p>For more information: <a href="https://pytorch.org/tutorials/beginner/saving_loading_models.html" rel="nofollow noopener">https://pytorch.org/tutorials/beginner/saving_loading_models.html</a></p>

username: aatiibutt
cooked: <p>It worked.<br>
Thank you so much <img src="https://discuss.pytorch.org/images/emoji/apple/slight_smile.png?v=9" title=":slight_smile:" class="emoji" alt=":slight_smile:"></p>

username: wtt55
cooked: <p>I save my model using the following code.</p>
<p>def save(self, file_path, e):<br>
torch.save(self.spatial_stream.state_dict(), os.path.join(file_path, ‘spt_{:03d}.pth’.format(e)))<br>
torch.save(self.temporal_stream.state_dict(), os.path.join(file_path, ‘tmp_{:03d}.pth’.format(e)))</p>
<p>load:<br>
def load(self, file_path):<br>
self.load_state_dict(torch.load(file_path))</p>
<p>But I meet this problem,can you help me?Thank you very much !!!<br>
Traceback (most recent call last):<br>
File “/home/wuting/anaconda3/envs/python=3.8/lib/python3.8/site-packages/torch/serialization.py”, line 308, in _check_seekable<br>
f.seek(f.tell())<br>
AttributeError: ‘EasyDict’ object has no attribute ‘seek’</p>
<p>During handling of the above exception, another exception occurred:</p>
<p>Traceback (most recent call last):<br>
File “test.py”, line 109, in <br>
main()<br>
File “test.py”, line 64, in main<br>
epoch_loop.main()<br>
File “/home/wuting/Spatialtem-multi/tools/epoch_loop.py”, line 70, in main<br>
self.setup_net()<br>
File “/home/wuting/Spatialtem-multi/tools/epoch_loop.py”, line 78, in setup_net<br>
<a href="http://self.net" rel="noopener nofollow ugc">self.net</a> = TwoStreamNet(self.device)<br>
File “/home/wuting/Spatialtem-multi/lib/netwrapper/two_stream_net.py”, line 39, in <strong>init</strong><br>
self.create_load(device)<br>
File “/home/wuting/Spatialtem-multi/lib/netwrapper/two_stream_net.py”, line 53, in create_load<br>
self.load(cfg.CUS_PT_PATH)<br>
File “/home/wuting/Spatialtem-multi/lib/netwrapper/two_stream_net.py”, line 207, in load<br>
self.load_state_dict(torch.load(file_path))<br>
File “/home/wuting/anaconda3/envs/python=3.8/lib/python3.8/site-packages/torch/serialization.py”, line 581, in load<br>
with _open_file_like(f, ‘rb’) as opened_file:<br>
File “/home/wuting/anaconda3/envs/python=3.8/lib/python3.8/site-packages/torch/serialization.py”, line 235, in _open_file_like<br>
return _open_buffer_reader(name_or_buffer)<br>
File “/home/wuting/anaconda3/envs/python=3.8/lib/python3.8/site-packages/torch/serialization.py”, line 220, in <strong>init</strong><br>
_check_seekable(buffer)<br>
File “/home/wuting/anaconda3/envs/python=3.8/lib/python3.8/site-packages/torch/serialization.py”, line 311, in _check_seekable<br>
raise_err_msg([“seek”, “tell”], e)<br>
File “/home/wuting/anaconda3/envs/python=3.8/lib/python3.8/site-packages/torch/serialization.py”, line 304, in raise_err_msg<br>
raise type(e)(msg)<br>
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.</p>

username: wtt55
cooked: <p>I change  torch.oad as this,like that it is work.</p>
<p>def load(self, file_path):<br>
self.load_state_dict(torch.load(‘PATH’),strict=False)</p>
<p>note:PATH is Specific weight paths。But I don not know why?maybe it needs the real  path?</p>

username: wtt55
cooked: <p>but in this way,the loss is ery biggest.Why?can you help me ?</p>