Repository: open-mmlab/mmengine

Issue:
[bug]resume error
Thanks for your error report and we appreciate it a lot.

**Checklist**

1. I have searched related issues but cannot get the expected help.
2. I have read the [FAQ documentation](https://mmengine.readthedocs.io/en/latest/faq.html) but cannot get the expected help.
3. The bug has not been fixed in the latest version.

**Describe the bug**
A clear and concise description of what the bug is.

**Reproduction**

1. What command or script did you run?

when I try to resume the model by adding `resume=True, load_from='epoch_380.pth'` in the config, the newest version of mmeingne raise a RuntimeError:

```
RuntimeError: The model and loaded state dict do not match exactly

unexpected key in source state_dict: data_preprocessor.mean, data_preprocessor.std
```

The error disappears when checkout to v0.1.0



Discussion:
Hi~ Could you provide the full error message and the config which could reproduce this error? 

I think this error could be caused by #542 and you enable `EMAHook` in your config. If so, we'll fix it ASAP, and you may change `strict_load` to False temporarily in `EMAHook`. 
Yes, the problem seems to be that I have enabled emahook.

The error report is as follows:

```
Traceback (most recent call last):
  File "tools/train.py", line 106, in <module>
    main()
  File "tools/train.py", line 102, in main
    runner.train()
  File "/nvme/data/wanghonglie/mmengine/mmengine/runner/runner.py", line 1653, in train
    self.load_or_resume()
  File "/nvme/data/wanghonglie/mmengine/mmengine/runner/runner.py", line 1602, in load_or_resume
    self.load_checkpoint(self._load_from)
  File "/nvme/data/wanghonglie/mmengine/mmengine/runner/runner.py", line 2011, in load_checkpoint
    self.call_hook('after_load_checkpoint', checkpoint=checkpoint)
  File "/nvme/data/wanghonglie/mmengine/mmengine/runner/runner.py", line 1723, in call_hook
    getattr(hook, fn_name)(self, **kwargs)
  File "/nvme/data/wanghonglie/mmengine/mmengine/hooks/ema_hook.py", line 189, in after_load_checkpoint
    load_state_dict(
  File "/nvme/data/wanghonglie/mmengine/mmengine/runner/checkpoint.py", line 108, in load_state_dict
    raise RuntimeError(err_msg)
RuntimeError: The model and loaded state dict do not match exactly

unexpected key in source state_dict: data_preprocessor.mean, data_preprocessor.std

Resolving patch:
diff --git a/mmengine/hooks/ema_hook.py b/mmengine/hooks/ema_hook.py
--- a/mmengine/hooks/ema_hook.py
+++ b/mmengine/hooks/ema_hook.py
@@ -27,11 +27,12 @@ class EMAHook(Hook):
             Defaults to 'ExponentialMovingAverage'.
         strict_load (bool): Whether to strictly enforce that the keys of
             ``state_dict`` in checkpoint match the keys returned by
-            ``self.module.state_dict``. Defaults to True.
+            ``self.module.state_dict``. Defaults to False.
+            Changed in v0.3.0.
         begin_iter (int): The number of iteration to enable ``EMAHook``.
             Defaults to 0.
-        begin_epoch (int): The number of epoch to enable ``EMAHook``. Defaults
-            to 0.
+        begin_epoch (int): The number of epoch to enable ``EMAHook``.
+            Defaults to 0.
         **kwargs: Keyword arguments passed to subclasses of
             :obj:`BaseAveragedModel`
     """
@@ -40,7 +41,7 @@ class EMAHook(Hook):
 
     def __init__(self,
                  ema_type: str = 'ExponentialMovingAverage',
-                 strict_load: bool = True,
+                 strict_load: bool = False,
                  begin_iter: int = 0,
                  begin_epoch: int = 0,
                  **kwargs):


Test patch: