AttributeError: 'Model' object has no attribute 'state_dict'

See original GitHub issue

While saving the best weights, I am facing this error.

torch.save(model.state_dict, 'checkpoint.pth')

Environment: Google Colab

  • torch version: 1.7
  • torchvision version: 0.6.1 Could you please suggest a corrective measure for this error!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
kiraanscommented, Jan 4, 2021

Thank you! This worked for me.

0reactions
saminnasrcommented, Jul 22, 2022

@alankbi Hi, I have a question when I run this code : { start_time = time.time() m.trainer.fit(m) print(f"— Training on GPU: {(time.time() - start_time):.2f} seconds —") print(m.trainer.fit(m))

import tempfile tmpdir = tempfile.TemporaryDirectory()

#save the prediction dataframe after training and compare with prediction after reload checkpoint img_path = get_data(“/content/orthomosaic.jpg”) m.create_trainer() pred_after_train = m.predict_image(path = img_path)

#Create a trainer to make a checkpoint m.trainer.save_checkpoint(“/content/checkpoint.pl”)

m.trainer.save_checkpoint(“/content/checkpoint.pl”,format(tmpdir))

#reload the checkpoint to model object after = main.deepforest.load_from_checkpoint(“{}/checkpoint.pl”.format(tmpdir)) pred_after_reload = after.predict_image(path = img_path)

assert not pred_after_train.empty assert not pred_after_reload.empty pd.testing.assert_frame_equal(pred_after_train,pred_after_reload) } I get this error: AttributeError: ‘NoneType’ object has no attribute ‘state_dict’ would you please help me?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Load a saved model on Pytorch AttributeError: 'dict' object has ...
AttributeError : 'dict' object has no attribute 'seek'. You can only torch.load from a file that is seekable. Please pre-load the data into...
Read more >
Torch has not attribute load_state_dict? - PyTorch Forums
I am trying to load a model with: import torch import pyautogui as ... as (AttributeError: 'list' object has no attribute 'load_state_dict'
Read more >
Saving and Loading Models — PyTorch Tutorials 1.0.0 ...
Notice that the load_state_dict() function takes a dictionary object, NOT a path to a saved object. This means that you must deserialize the...
Read more >
AttributeError: 'Model' object has no attribute 'state_dict' | by Bro
please help. “AttributeError: 'Model' object has no attribute 'state_dict'” is published by Bro.
Read more >
AttributeError when converting onnx model using ... - Kneron
state_dict = module.state_dict(keep_vars=True). AttributeError: 'collections.OrderedDict' object has no attribute 'state_dict'. Tagged:.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found