Shortcuts

configs

TrojanZoo config path:

config_path: dict[str, str] = {
    'package': os.path.dirname(__file__),   # trojanzoo/configs/*/*.yml
    'user': os.path.normpath(os.path.expanduser(
        '~/.trojanzoo/configs/trojanzoo')),
    'project': os.path.normpath('./configs/trojanzoo'),
    }
class trojanzoo.configs.Config(cmd_config_path=None, _base=None, **kwargs)[source]

Configuration class.

Warning

There is already a preset config instance trojanzoo.configs.config.

NEVER call the class init method to create a new instance (unless you know what you’re doing).

Note

ConfigType is Module[str, Module[str, Any]]

value = config[config_file][key][dataset_name] where dataset_name is optional

(config[config_file][key] is trojanzoo.utils.module.Param and has default values).

Parameters:
  • _base (Config) – The base config instance. config_dict of current config instance will inherit _base.config_dict and update based on self.config_path. It’s usually the config in father library (e.g., trojanvision config inherits trojanzoo config). Defaults to None.

  • **kwargs (dict[str, str]) – Map of config paths.

Variables:
  • cmd_config_path (str) – Path to cmd_config. Defaults to None.

  • cmd_config (ConfigType) – Config loaded from path cmd_config_path.

  • config_path (dict[str, str]) – Map from config name (e.g., 'package', 'user', 'project') to path string.

  • config_dict (dict[str, ConfigType]) – Map from config name (e.g., 'package', 'user', 'project') to its config.

  • full_config (ConfigType) – Full config with parameters for all datasets by calling merge() to merge different configs in self.config_dict. value = full_config[config_file][key][dataset_name].

get_config(dataset_name, config=None, **kwargs)[source]

Get config for specific dataset.

Parameters:
  • dataset_name (str) – Dataset name.

  • config – (ConfigType): The config for all datasets. value = full_config[config_file][key][dataset_name]. Defaults to self.full_config.

Returns:

Param[str, Module[str, Any]] – Config for dataset_name. value = full_config[config_file][key].

static load_config(path)[source]

Load yaml or json configs from path.

Parameters:

path (str) – Path to config file.

Returns:

ConfigType – Config loaded from path.

merge(keys=['package', 'user', 'project'])[source]

Merge different configs of keys in self.config_dict.

Parameters:

keys (list[str]) – Keys of self.config_dict to merge.

Returns:

ConfigType – Merged config.

summary(keys=['final'], config=None, indent=0)[source]

Summary the config information.

Parameters:
  • keys (list[str] | str) –

    keys of configs to summary.

    • 'final': self.full_config

    • 'cmd': self.cmd_config

    • key in self.config_dict.keys()

    Defaults to ['final'].

  • indent (int) – The space indent of entire string. Defaults to 0.

Docs

Access comprehensive developer documentation for TrojanZoo

View Docs