提交 584126e5 编写于 作者: 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
上级 0fc149e6
...@@ -21,6 +21,7 @@ import os ...@@ -21,6 +21,7 @@ import os
import sys import sys
import yaml import yaml
import copy
from .config.schema import SchemaDict, extract_schema from .config.schema import SchemaDict, extract_schema
from .config.yaml_helpers import serializable from .config.yaml_helpers import serializable
...@@ -163,4 +164,7 @@ def create(cls_or_name, **kwargs): ...@@ -163,4 +164,7 @@ def create(cls_or_name, **kwargs):
kwargs[k] = target kwargs[k] = target
else: else:
raise ValueError("Unsupported injection type:", target_key) 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) return cls(**kwargs)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册