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]
wheredataset_name
is optional(
config[config_file][key]
istrojanzoo.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 toNone
.
- Variables:
cmd_config_path (str) – Path to
cmd_config
. Defaults toNone
.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 inself.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 toself.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
inself.config_dict
.