mindarmour.utils

Util methods of MindArmour.

class mindarmour.utils.LogUtil[source]

Logging module.

Raises

SyntaxError – If create this class.

add_handler(handler)[source]

Add other handler supported by logging module.

Parameters

handler (logging.Handler) – Other handler supported by logging module.

Raises

ValueError – If handler is not an instance of logging.Handler.

debug(tag, msg, *args)[source]

Log ‘[tag] msg % args’ with severity ‘DEBUG’.

Parameters
  • tag (str) – Logger tag.

  • msg (str) – Logger message.

  • args (Any) – Auxiliary value.

error(tag, msg, *args)[source]

Log ‘[tag] msg % args’ with severity ‘ERROR’.

Parameters
  • tag (str) – Logger tag.

  • msg (str) – Logger message.

  • args (Any) – Auxiliary value.

static get_instance()[source]

Get instance of class LogUtil.

Returns

Object, instance of class LogUtil.

info(tag, msg, *args)[source]

Log ‘[tag] msg % args’ with severity ‘INFO’.

Parameters
  • tag (str) – Logger tag.

  • msg (str) – Logger message.

  • args (Any) – Auxiliary value.

set_level(level)[source]

Set the logging level of this logger, level must be an integer or a string.

Parameters

level (Union[int, str]) – Level of logger.

warn(tag, msg, *args)[source]

Log ‘[tag] msg % args’ with severity ‘WARNING’.

Parameters
  • tag (str) – Logger tag.

  • msg (str) – Logger message.

  • args (Any) – Auxiliary value.

class mindarmour.utils.GradWrapWithLoss(network)[source]

Construct a network to compute the gradient of loss function in input space and weighted by weight.

construct(inputs, labels, weight)[source]

Compute gradient of inputs with labels and weight.

Parameters
  • inputs (Tensor) – Inputs of network.

  • labels (Tensor) – Labels of inputs.

  • weight (Tensor) – Weight of each gradient, weight has the same shape with labels.

Returns

Tensor, gradient matrix.

class mindarmour.utils.GradWrap(network)[source]

Construct a network to compute the gradient of network outputs in input space and weighted by weight, expressed as a jacobian matrix.

construct(inputs, weight)[source]

Compute jacobian matrix.

Parameters
  • inputs (Tensor) – Inputs of network.

  • weight (Tensor) – Weight of each gradient, weight has the same shape with labels.

Returns

Tensor, Jacobian matrix.