IBA.pytorch_readout

class IBAReadout(attach_layer, readout_layers, model, estimator_type=None, **kwargs)[source]

Bases: IBA.pytorch.IBA

The Readout Bottleneck is an extension to yield the alphas for the IBA bottleneck from a readout network. The readout network is trained on intermediate feature maps which are obtained by performing a nested forward pass on the model and recording activations.

Major differences to the Per-Sample IBA: * an additional context manager for the nested pass * additional hooks to collect the input and the feature maps in the nested pass * a readout network of three 1x1 conv. layers to yield alpha

detach()[source]

Remove the bottleneck to restore the original model

analyze(input_t, model, mode='saliency', **kwargs)[source]

Use the trained Readout IBA to find relevant regions in the input. The input is passed through the network and the Readout Bottleneck restricts the information flow. The capacity at each pixel is then returned as saliency map, similar to the Per-Sample IBA.

Parameters
  • input_t – input image of shape (1, C, H W)

  • model – the model containing the trained bottleneck

  • mode – how to post-process the resulting map: ‘saliency’ (default) or ‘capacity’

Returns

The heatmap of the same shape as the input_t.

Additional arguments are ignored.

reset_estimate()[source]

Equivalent to IBA.reset_estimate, but additionaly resets estimators of bottleneck layers.

forward(x)[source]

You don’t need to call this method manually.

The IBA acts as a model layer, passing the information in x along to the next layer either as-is or by restricting the flow of infomration. We use it also to estimate the distribution of x passing through the layer.