未验证 提交 e32bb3f5 编写于 作者: Y Yang Zhang 提交者: GitHub

Prevent module instance from modifying global config (#2790)

some of the global config values are reference type, e.g., objects, lists or
dicts, if the created module instances modify those values (see FPN and
spatial_scale), global config will reflect these changes, and instances of the
same class created later will inherit the changed values
上级 4752ddea
......@@ -21,6 +21,7 @@ import os
import sys
import yaml
import copy
from .config.schema import SchemaDict, extract_schema
from .config.yaml_helpers import serializable
......@@ -163,4 +164,7 @@ def create(cls_or_name, **kwargs):
kwargs[k] = target
else:
raise ValueError("Unsupported injection type:", target_key)
# prevent modification of global config values of reference types
# (e.g., list, dict) from within the created module instances
kwargs = copy.deepcopy(kwargs)
return cls(**kwargs)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册