Shortcuts

module

class trojanzoo.utils.module.BasicObject(indent=0, **kwargs)[source]

A basic class with a pretty summary() method.

Variables:
  • name (str) – The name of the instance or class.

  • param_list (dict[str, list[str]]) – Map from category strings to variable name list.

  • indent (int) – The indent when calling summary(). Defaults to 0.

summary(indent=None)[source]

Summary the variables of the instance according to param_list.

Parameters:

indent (int) – The space indent for the entire string. Defaults to self.indent.

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 and ModelProcess 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, call get_output_int(). Defaults to self.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.

static output_iter(name, _iter, iteration=None)[source]

Output an iteration string: {name} Iter: [ {_iter + 1} / {iteration} ] or {name} Iter: [ {_iter + 1} ] if iteration is None.

Parameters:
  • name (str) – The header string.

  • _iter (int) – The current iteration.

  • iteration (int) – The total iteration. Defaults to None.

See also

The implementation is in trojanzoo.utils.output.output_iter().

class trojanzoo.utils.module.ModelProcess(dataset=None, model=None, folder_path=None, **kwargs)[source]

It inherits Process and further specify model related items.

Variables:

See also

trojanzoo.attacks.Attack and trojanzoo.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'.

clear()[source]

Remove all keys.

Returns:

Module – return self for stream usage.

copy()[source]

Deepcopy of self.

Returns:

Module – return the deepcopy of self.

items()[source]
keys()[source]
remove_none()[source]

Remove the parameters whose values are None.

Returns:

Module – return self for stream usage.

summary(indent=0)[source]

Output information of self.

Parameters:

indent (int) – The space indent for the entire string. Defaults to 0.

update(*args, **kwargs)[source]

update values.

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.

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.

clear()[source]
remove_none()[source]
update(*args, **kwargs)[source]

Docs

Access comprehensive developer documentation for TrojanZoo

View Docs