Skip to content

Commit

Permalink
fix initialization bug of override cfg
Browse files Browse the repository at this point in the history
  • Loading branch information
ZwwWayne committed Mar 31, 2021
1 parent 9d80f56 commit 024d5f4
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions mmcv/cnn/utils/weight_init.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright (c) Open-MMLab. All rights reserved.
import copy
import warnings

import numpy as np
Expand Down Expand Up @@ -445,12 +446,17 @@ def initialize(module, init_cfg):
init_cfg = [init_cfg]

for cfg in init_cfg:
override = cfg.pop('override', None)
_initialize(module, cfg)
# should deeply copy the original config because cfg may be used by
# other modules, e.g., one init_cfg shared by multiple bottleneck
# blocks, the expected cfg will be changed after pop and will change
# the initialization behavior of other modules
cp_cfg = copy.deepcopy(cfg)
override = cp_cfg.pop('override', None)
_initialize(module, cp_cfg)

if override is not None:
cfg.pop('layer', None)
_initialize_override(module, override, cfg)
cp_cfg.pop('layer', None)
_initialize_override(module, override, cp_cfg)
else:
# All attributes in module have same initialization.
pass

0 comments on commit 024d5f4

Please sign in to comment.