question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ValueError: Object should have `state_dict` method.

See original GitHub issue

hi,when I train your reid_baseline model ,I met a error that I can’t solve. the error is as follows:

Traceback (most recent call last): File “/home/lc/Desktop/reid_baseline/tools/train.py”, line 87, in <module> main() File “/home/lc/Desktop/reid_baseline/tools/train.py”, line 83, in main train(cfg) File “/home/lc/Desktop/reid_baseline/tools/train.py”, line 46, in train num_query File “/home/lc/Desktop/reid_baseline/engine/trainer.py”, line 150, in do_train trainer.run(train_loader, max_epochs=epochs) File “/usr/local/lib/python3.5/dist-packages/pytorch_ignite-0.2.0-py3.5.egg/ignite/engine/engine.py”, line 388, in run File “/usr/local/lib/python3.5/dist-packages/pytorch_ignite-0.2.0-py3.5.egg/ignite/engine/engine.py”, line 352, in _handle_exception File “/usr/local/lib/python3.5/dist-packages/pytorch_ignite-0.2.0-py3.5.egg/ignite/engine/engine.py”, line 379, in run File “/usr/local/lib/python3.5/dist-packages/pytorch_ignite-0.2.0-py3.5.egg/ignite/engine/engine.py”, line 287, in _fire_event File “/usr/local/lib/python3.5/dist-packages/pytorch_ignite-0.2.0-py3.5.egg/ignite/handlers/checkpoint.py”, line 172, in call File “/usr/local/lib/python3.5/dist-packages/pytorch_ignite-0.2.0-py3.5.egg/ignite/handlers/checkpoint.py”, line 130, in _save File “/usr/local/lib/python3.5/dist-packages/pytorch_ignite-0.2.0-py3.5.egg/ignite/handlers/checkpoint.py”, line 144, in _internal_save ValueError: Object should have state_dict method.

How should I fix it?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:19

github_iconTop GitHub Comments

3reactions
vfdev-5commented, May 21, 2019

@yuliuyu your problem is here: https://github.com/L1aoXingyu/reid_baseline/blob/852bb8ae8bd6635527e5a39609f8beed81be26c0/engine/trainer.py#L108-L109

Change it to this and it should be fine:

trainer.add_event_handler(Events.EPOCH_COMPLETED, checkpointer, {'model': model, 'optimizer': optimizer})
0reactions
jhxingcommented, Jul 11, 2019

@jhxing you need to remove .state_dict()

trainer.add_event_handler(Events.EPOCH_COMPLETED, checkpointer, {'model': model,
                                                                     'optimizer': optimizer,
                                                                     'center_param': center_criterion,
'optimizer_center': optimizer_center})

Thank you for your patient help, I will try it. Thank you angin !

Read more comments on GitHub >

github_iconTop Results From Across the Web

Save and load model optimizer state - python - Stack Overflow
However, I need a method for saving and loading the states of the optimizers of my trainer models. It seems as though keras...
Read more >
Source code for ignite.handlers.checkpoint - PyTorch
Objects should have implemented ``state_dict`` and ... Function receives two objects: checkpoint as a dictionary and filename.
Read more >
flax.serialization
All Flax classes that carry state (e.g. ,Optimizer) can be turned into a state dict of numpy arrays for easy serialization. """ import...
Read more >
optim/optimizer.py · neilisaac/torch - Gemfury
Tensor): raise TypeError("params argument given to the optimizer should be ... if len(groups) != len(saved_groups): raise ValueError("loaded state dict has ...
Read more >
sqlalchemy.orm.attributes — pylidc documentation
Column` object, this attribute will return the :attr:`. ... _modified_event method will have no effect; this means the attribute will never show up...
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