superlollipop123 / Cross-directional-Center-Network-and-MSVR310

Multi-spectral Vehicle Re-identification with Cross-directional Center Network and A High-quality Benchmark
7 stars 2 forks source link

Engine run is terminating due to exception: Object <class 'collections.OrderedDict'> should have `state_dict` method #1

Open moonstarL opened 1 year ago

moonstarL commented 1 year ago

我在跑代码时入到如下问题,望解答: 2023-08-29 09:14:40,402 reid_baseline.train INFO: Epoch[1] Iteration[15/31] Loss: 69.638, Acc: 0.001, Base Lr: 3.82e-05 2023-08-29 09:14:48,124 reid_baseline.train INFO: Epoch[1] Iteration[30/31] Loss: 62.420, Acc: 0.002, Base Lr: 3.82e-05 Engine run is terminating due to exception: Object <class 'collections.OrderedDict'> should have state_dict method Traceback (most recent call last): File "F:/All_Re_ID/fusion/code/Cross-directional-Center-Network-and-MSVR310-main/train.py", line 252, in main() File "F:/All_Re_ID/fusion/code/Cross-directional-Center-Network-and-MSVR310-main/train.py", line 248, in main train(cfg) File "F:/All_Re_ID/fusion/code/Cross-directional-Center-Network-and-MSVR310-main/train.py", line 89, in train do_train( File "F:\All_Re_ID\fusion\code\Cross-directional-Center-Network-and-MSVR310-main\engine\trainer.py", line 599, in do_train trainer.run(train_loader, max_epochs=epochs) File "D:\Anaconda3\envs\pytorch\lib\site-packages\ignite\engine\engine.py", line 698, in run return self._internal_run() File "D:\Anaconda3\envs\pytorch\lib\site-packages\ignite\engine\engine.py", line 771, in _internal_run self._handle_exception(e) File "D:\Anaconda3\envs\pytorch\lib\site-packages\ignite\engine\engine.py", line 466, in _handle_exception raise e File "D:\Anaconda3\envs\pytorch\lib\site-packages\ignite\engine\engine.py", line 748, in _internal_run self._fire_event(Events.EPOCH_COMPLETED) File "D:\Anaconda3\envs\pytorch\lib\site-packages\ignite\engine\engine.py", line 421, in _fire_event func(first, (event_args + others), **kwargs) File "D:\Anaconda3\envs\pytorch\lib\site-packages\ignite\handlers\checkpoint.py", line 876, in call self._check_objects(to_save, "state_dict") File "D:\Anaconda3\envs\pytorch\lib\site-packages\ignite\handlers\checkpoint.py", line 511, in _check_objects raise TypeError(f"Object {type(obj)} should have {attr} method") TypeError: Object <class 'collections.OrderedDict'> should have state_dict method

superlollipop123 commented 9 months ago

Make sure the version of ignite is correct. "pytorch-ignite==0.2.0" is ok to run. Or you may try set the "save_as_state_dict=True" in the following line in train.py: checkpointer = ModelCheckpoint(output_dir, cfg.MODEL.NAME, n_saved=10, save_interval = checkpoint_period, require_empty=False, save_as_state_dict=False)