module¶
- class trojanzoo.utils.module.BasicObject(indent=0, **kwargs)[source]¶
A basic class with a pretty
summary()
method.- Variables:
- class trojanzoo.utils.module.Process(output=0, **kwargs)[source]¶
It inherits
BasicObject
and further specify output levels.- Parameters:
output (int, Iterable[str]) – The level of output or the set of output items.
- Variables:
output (set[str]) – The set of output items generated by
get_output()
.
See also
trojanzoo.optim.Optimizer
andModelProcess
inherit this class.- get_output(org_output=None)[source]¶
Get output items based on output level.
- Parameters:
org_output (int, Iterable[str]) – Output level integer or output items. If
int
, callget_output_int()
. Defaults toself.output
.- Returns:
set[str] – The set of output items.
- classmethod get_output_int(org_output=0)[source]¶
Get output items based on output level integer.
0 - 4 : {'verbose'}
5 - 9 : {'verbose', 'end'}
10 - 19: {'verbose', 'end', 'start'}
20 - 29: {'verbose', 'end', 'start', 'middle'}
30 - * : {'verbose', 'end', 'start', 'middle', 'memory'}
- Parameters:
org_output (int) – Output level integer. Defaults to
0
.- Returns:
set[str] – The set of output items.
- class trojanzoo.utils.module.ModelProcess(dataset=None, model=None, folder_path=None, **kwargs)[source]¶
It inherits
Process
and further specify model related items.- Variables:
dataset (trojanzoo.datasets.Dataset | None) – The dataset instance.
model (trojanzoo.models.Model | None) – The model instance.
folder_path (str | None) – The folder path to store results. Defaults to
None
.clean_acc (float) – The clean accuracy of
model
.
See also
trojanzoo.attacks.Attack
andtrojanzoo.defenses.Defense
inherit this class.
- class trojanzoo.utils.module.Module(*args, **kwargs)[source]¶
A dict-like class which supports attribute-like view as well.
- Parameters:
*args – Positional dict-like arguments. All keys will be merged together.
**kwargs – Keyword arguments that compose a dict. All keys will be merged together.
- Variables:
_marker (str) – The marker of the class, which is shown in
str(self)
. Defaults to'M'
.
- remove_none()[source]¶
Remove the parameters whose values are
None
.- Returns:
Module – return
self
for stream usage.
- class trojanzoo.utils.module.Param(*args, **kwargs)[source]¶
A dict-like class to store parameters config that inherits
Module
and further extends default values. You can view and set keys by attributes as well.- Parameters:
*args – Positional dict-like arguments. All keys will be merged together. If there is only 1 argument and no keyword argument, regard it as the default value.
**kwargs – Keyword arguments that compose a dict. All keys will be merged together.
- Variables:
_marker (str) – The marker of the class, which is shown in
str(self)
. Defaults to'P'
.default (Any) – The default value of unknown keys.