zennit.composites

Composites, registered in a global composite dict.

Functions

register_composite

Register a composite in the global COMPOSITES dict under name.

Classes

DeconvNet

An explicit composite modifying the gradients of all ReLUs according to DeconvNet 1.

EpsilonAlpha2Beta1

An explicit composite using the alpha2-beta1 rule for all convolutional layers and the epsilon rule for all fully connected layers.

EpsilonAlpha2Beta1Flat

An explicit composite using the flat rule for any linear first layer, the alpha2-beta1 rule for all other convolutional layers and the epsilon rule for all other fully connected layers.

EpsilonGammaBox

An explicit composite using the ZBox rule for the first convolutional layer, gamma rule for all following convolutional layers, and the epsilon rule for all fully connected layers.

EpsilonPlus

An explicit composite using the zplus rule for all convolutional layers and the epsilon rule for all fully connected layers.

EpsilonPlusFlat

An explicit composite using the flat rule for any linear first layer, the zplus rule for all other convolutional layers and the epsilon rule for all other fully connected layers.

ExcitationBackprop

An explicit composite implementing the ExcitationBackprop 3.

GuidedBackprop

An explicit composite modifying the gradients of all ReLUs according to GuidedBackprop 2.

LayerMapComposite

A Composite for which hooks are specified by a mapping from module types to hooks.

NameMapComposite

A Composite for which hooks are specified by a mapping from module types to hooks.

SpecialFirstLayerMapComposite

A Composite for which hooks are specified by a mapping from module types to hooks.

class zennit.composites.DeconvNet(canonizers=None)[source]

Bases: LayerMapComposite

An explicit composite modifying the gradients of all ReLUs according to DeconvNet 1.

References

1(1,2)

M. D. Zeiler and R. Fergus, “Visualizing and understanding convolutional networks,” in European conference on computer vision. Springer, 2014, pp. 818–833.

class zennit.composites.EpsilonAlpha2Beta1(canonizers=None)[source]

Bases: LayerMapComposite

An explicit composite using the alpha2-beta1 rule for all convolutional layers and the epsilon rule for all fully connected layers.

class zennit.composites.EpsilonAlpha2Beta1Flat(canonizers=None)[source]

Bases: SpecialFirstLayerMapComposite

An explicit composite using the flat rule for any linear first layer, the alpha2-beta1 rule for all other convolutional layers and the epsilon rule for all other fully connected layers.

class zennit.composites.EpsilonGammaBox(low, high, canonizers=None)[source]

Bases: SpecialFirstLayerMapComposite

An explicit composite using the ZBox rule for the first convolutional layer, gamma rule for all following convolutional layers, and the epsilon rule for all fully connected layers.

Parameters
  • low (obj:torch.Tensor) – A tensor with the same size as the input, describing the lowest possible pixel values.

  • high (obj:torch.Tensor) – A tensor with the same size as the input, describing the highest possible pixel values.

class zennit.composites.EpsilonPlus(canonizers=None)[source]

Bases: LayerMapComposite

An explicit composite using the zplus rule for all convolutional layers and the epsilon rule for all fully connected layers.

class zennit.composites.EpsilonPlusFlat(canonizers=None)[source]

Bases: SpecialFirstLayerMapComposite

An explicit composite using the flat rule for any linear first layer, the zplus rule for all other convolutional layers and the epsilon rule for all other fully connected layers.

class zennit.composites.ExcitationBackprop(canonizers=None)[source]

Bases: LayerMapComposite

An explicit composite implementing the ExcitationBackprop 3.

References

3(1,2)

J. Zhang, S. A. Bargal, Z. Lin, J. Brandt, X. Shen, and S. Sclaroff, “Top-down neural attention by excitation backprop,” International Journal of Computer Vision, vol. 126, no. 10, pp. 1084–1102, 2018.

class zennit.composites.GuidedBackprop(canonizers=None)[source]

Bases: LayerMapComposite

An explicit composite modifying the gradients of all ReLUs according to GuidedBackprop 2.

References

2(1,2)

J. T. Springenberg, A. Dosovitskiy, T. Brox, and M. A. Riedmiller, “Striving for simplicity: The all convolutional net,” in Proceedings of the International Conference of Learning Representations (ICLR), 2015.

class zennit.composites.LayerMapComposite(layer_map, canonizers=None)[source]

Bases: Composite

A Composite for which hooks are specified by a mapping from module types to hooks.

Parameters

layer_map (list[tuple[tuple[torch.nn.Module, …], Hook]]) – A mapping as a list of tuples, with a tuple of applicable module types and a Hook.

mapping(ctx, name, module)[source]

Get the appropriate hook given a mapping from module types to hooks.

Parameters
  • ctx (dict) – A context dictionary to keep track of previously registered hooks.

  • name (str) – Name of the module.

  • module (obj:torch.nn.Module) – Instance of the module to find a hook for.

Returns

obj – The hook found with the module type in the given layer map, or None if no applicable hook was found.

Return type

Hook or None

class zennit.composites.NameMapComposite(name_map, canonizers=None)[source]

Bases: Composite

A Composite for which hooks are specified by a mapping from module types to hooks.

Parameters

name_map (list[tuple[tuple[str, …], Hook]]) – A mapping as a list of tuples, with a tuple of applicable module names and a Hook.

mapping(ctx, name, module)[source]

Get the appropriate hook given a mapping from module names to hooks.

Parameters
  • ctx (dict) – A context dictionary to keep track of previously registered hooks.

  • name (str) – Name of the module.

  • module (obj:torch.nn.Module) – Instance of the module to find a hook for.

Returns

obj – The hook found with the module type in the given name map, or None if no applicable hook was found.

Return type

Hook or None

class zennit.composites.SpecialFirstLayerMapComposite(layer_map, first_map, canonizers=None)[source]

Bases: LayerMapComposite

A Composite for which hooks are specified by a mapping from module types to hooks.

Parameters
  • layer_map (list[tuple[tuple[torch.nn.Module, …], Hook]]) – A mapping as a list of tuples, with a tuple of applicable module types and a Hook.

  • first_map (list[tuple[tuple[torch.nn.Module, …], Hook]]) – Applicable mapping for the first layer, same format as layer_map.

mapping(ctx, name, module)[source]

Get the appropriate hook given a mapping from module types to hooks and a special mapping for the first occurrence in another mapping.

Parameters
  • ctx (dict) – A context dictionary to keep track of previously registered hooks.

  • name (str) – Name of the module.

  • module (obj:torch.nn.Module) – Instance of the module to find a hook for.

Returns

obj – The hook found with the module type in the given layer map, in the first layer map if this was the first layer, or None if no applicable hook was found.

Return type

Hook or None

zennit.composites.register_composite(name)[source]

Register a composite in the global COMPOSITES dict under name.