ConfigItem
- class lib.config.objects.ConfigItem(datatype: type[~lib.config.objects.T], default: ~lib.config.objects.T, group: str, info: str, choices: list[str] | ~typing.Literal['colorchooser'] = <factory>, gui_radio: bool = False, min_max: tuple[~lib.config.objects.T, ~lib.config.objects.T] | None = None, rounding: int = -1, fixed: bool = True)
Bases:
Generic[T]A dataclass for storing config items loaded from config.ini files and dynamically assigning and validating that the correct datatype is used.
The value loaded from the .ini config file can be accessed with either:
>>> conf.value >>> conf() >>> conf.get()
- Parameters:
datatype (type[lib.config.objects.T]) – A python type class. This limits the type of data that can be provided in the .ini file and ensures that the value is returned to faceswap is correct. Valid datatypes are: int, float, str, bool or list. Note that list items must all be strings.
default (lib.config.objects.T) – The default value for this option. It must be of the same type as
datatype.group (str) – The group that this config item exists within in the config section
info (str) – A description of what this option does.
choices (list[str] | Literal['colorchooser']) – If this option’s datatype is a str then valid selections can be defined here, empty list for any value. If the option’s datatype is a list, then this option must be populated with the valid selections. This validates the option and also enables a combobox / radio option in the GUI. If the default value is a hex color value, then this should be the literal “colorchooser” to present a color choosing interface in the GUI. Ignored for all other datatypes Default: [] (empty list: no options)
gui_radio (bool) – If
choicesare defined, this indicates that the GUI should use radio buttons rather than a combobox to display this option. Default:Falsemin_max (tuple[lib.config.objects.T, lib.config.objects.T] | None) – For int and float
datatypethis is required otherwise it is ignored. Should be a tuple of min and max accepted values of the same datatype as the option value. This is used for controlling the GUI slider range. Values are not enforced. Default:Nonerounding (int) – For int and float :attr:datatypes this is required to be > 0 otherwise it is ignored. Used for the GUI slider. For `float, this is the number of decimal places to display. For int this is the step size. Default: -1 (ignored)
fixed (bool) – [train only]. Training configurations are fixed when the model is created, and then reloaded from the state file. Marking an item as fixed=``False`` indicates that this value can be changed for existing models, and will override the value saved in the state file with the updated value in config. Default:
True
Attributes Summary
Only used for train.model configurations.
indicates that the GUI should use radio buttons rather than a combobox to display this option if
choicesis populatedDescription of the config option with additional formatting and helptext added from the item parameters
The current value of the ConfigItem as a string for writing to a .ini file
For int and float
datatypethis will be populated otherwise it will beNone.The name associated with this option
For int and float
datatypesthis will be > 0 otherwise it will be -1.The config value for this item loaded from the config .ini file.
Methods Summary
__call__()Obtain the currently stored configuration value
get()Obtain the currently stored configuration value
set(value)Set the item's option value
set_name(name)Set the logging name for this object for display purposes
Attributes Documentation
- fixed: bool = True
Only used for train.model configurations. Options marked as fixed=``False`` indicates that this value can be changed for existing models, otherwise the option set when the model commenced training is fixed and cannot be changed. Default:
True
- gui_radio: bool = False
indicates that the GUI should use radio buttons rather than a combobox to display this option if
choicesis populated
- helptext
Description of the config option with additional formatting and helptext added from the item parameters
- ini_value
The current value of the ConfigItem as a string for writing to a .ini file
- min_max: tuple[T, T] | None = None
For int and float
datatypethis will be populated otherwise it will beNone. Used for controlling the GUI slider range. Values are not enforced.
- name
The name associated with this option
- rounding: int = -1
For int and float
datatypesthis will be > 0 otherwise it will be -1. Used for the GUI slider. For float, this is the number of decimal places to display. For int this is the step size.
- value
The config value for this item loaded from the config .ini file. String values will always be lowercase, regardless of what is loaded from Config
Methods Documentation
- __call__() T
Obtain the currently stored configuration value
- Returns:
The config value for this item loaded from the config .ini file. String values will always
be lowercase, regardless of what is loaded from Config
- Return type:
- get() T
Obtain the currently stored configuration value
- Returns:
The config value for this item loaded from the config .ini file. String values will always
be lowercase, regardless of what is loaded from Config
- Return type:
- set_name(name: str) None
Set the logging name for this object for display purposes
- Parameters:
name (str) – The name to assign to this option
- Return type:
None
- __call__() T
Obtain the currently stored configuration value
- Returns:
The config value for this item loaded from the config .ini file. String values will always
be lowercase, regardless of what is loaded from Config
- Return type:
- choices: list[str] | Literal['colorchooser'] = <dataclasses._MISSING_TYPE object>
If this option’s datatype is a str then valid selections may be defined here, Empty list if any value is valid. If the datatype is a list then valid choices will be populated here. If the default value is a hex color code, then the literal “colorchooser” will display a color choosing interface in the GUI.
- datatype: type[T] = <dataclasses._MISSING_TYPE object>
A python type class. The datatype of the config value. One of int, float, str, bool or list. list will only contain str items
- default: T = <dataclasses._MISSING_TYPE object>
The default value for this option. It is of the same type as
datatype
- fixed: bool = True
Only used for train.model configurations. Options marked as fixed=``False`` indicates that this value can be changed for existing models, otherwise the option set when the model commenced training is fixed and cannot be changed. Default:
True
- get() T
Obtain the currently stored configuration value
- Returns:
The config value for this item loaded from the config .ini file. String values will always
be lowercase, regardless of what is loaded from Config
- Return type:
- group: str = <dataclasses._MISSING_TYPE object>
The group that this config option belongs to
- gui_radio: bool = False
indicates that the GUI should use radio buttons rather than a combobox to display this option if
choicesis populated
- property helptext: str
Description of the config option with additional formatting and helptext added from the item parameters
- info: str = <dataclasses._MISSING_TYPE object>
A description of what this option does
- property ini_value: str
The current value of the ConfigItem as a string for writing to a .ini file
- min_max: tuple[T, T] | None = None
For int and float
datatypethis will be populated otherwise it will beNone. Used for controlling the GUI slider range. Values are not enforced.
- property name: str
The name associated with this option
- rounding: int = -1
For int and float
datatypesthis will be > 0 otherwise it will be -1. Used for the GUI slider. For float, this is the number of decimal places to display. For int this is the step size.
- set_name(name: str) None
Set the logging name for this object for display purposes
- Parameters:
name (str) – The name to assign to this option
- Return type:
None