Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix]: Fix initialization bug of override cfg #918

Merged
merged 1 commit into from
Apr 2, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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