From 584126e5031447043bc8cc029dab8989d90b9cda Mon Sep 17 00:00:00 2001 From: Yang Zhang Date: Fri, 12 Jul 2019 13:12:24 +0800 Subject: [PATCH] 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 --- ppdet/core/workspace.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ppdet/core/workspace.py b/ppdet/core/workspace.py index 8e42ff362..375da3e33 100644 --- a/ppdet/core/workspace.py +++ b/ppdet/core/workspace.py @@ -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) -- GitLab