Skip to content

Commit

Permalink
Merge 1a39da2 into 03a2e3a
Browse files Browse the repository at this point in the history
  • Loading branch information
MeowZheng authored Apr 8, 2021
2 parents 03a2e3a + 1a39da2 commit 9f58cc4
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions mmcv/cnn/utils/weight_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,13 +376,25 @@ def _initialize_override(module, override, cfg):
override = [override] if isinstance(override, dict) else override

for override_ in override:
if 'type' not in override_.keys():
override_.update(cfg)
name = override_.pop('name', None)

cp_cfg = copy.deepcopy(override_)
name = cp_cfg.pop('name', None)
if name is None:
raise ValueError('`override` must contain the key "name",'
f'but got {cp_cfg}')
# if override only has name kay, it means use origial init_cfg
if not cp_cfg:
cp_cfg.update(cfg)
# if override has name kay and other args except type key, it will
# raise error
elif 'type' not in cp_cfg.keys():
raise ValueError(f'`override` need "type" key, but got {cp_cfg}')

if hasattr(module, name):
_initialize(getattr(module, name), override_, wholemodule=True)
_initialize(getattr(module, name), cp_cfg, wholemodule=True)
else:
raise RuntimeError(f'module did not have attribute {name}')
raise RuntimeError(f'module did not have attribute {name}, '
f'but init_cfg is {cp_cfg}.')


def initialize(module, init_cfg):
Expand Down

0 comments on commit 9f58cc4

Please sign in to comment.