Model Modifiers

class tf_keras_vis.utils.model_modifiers.ExtractIntermediateLayer(index_or_name)[source]

Bases: ModelModifier

A model modifier that constructs new model instance whose output layer is an intermediate layer of model.

This modifier will be used to visualize the features of the model layer.

class tf_keras_vis.utils.model_modifiers.GuidedBackpropagation(target_activations=[tf.keras.activations.relu])[source]

Bases: ModelModifier

A model modifier that replaces the gradient calculation of activation functions to Guided calculation.

For details on Guided back propagation, see the papers:

References

Warning

Please note that there is a discussion that Guided Backpropagation is not working well as model explanations.

class tf_keras_vis.utils.model_modifiers.ModelModifier[source]

Bases: ABC

Abstract class for defining a model modifier.

abstract __call__(model)[source]

Implement modification to the model before processing gradient descent.

Parameters:

model – A model instance.

Raises:

NotImplementedError – This method must be overwritten.

Returns: Modified model or None.

class tf_keras_vis.utils.model_modifiers.ReplaceToLinear[source]

Bases: ModelModifier

A model modifier that replaces the activation functions of all output layers to tf.keras.activations.linear.

Please note that this modifier must be set the end of modifiers list that is passed to ModelVisualization#__init__(). For example:

# When visualizing `intermediate-1` layer.
ActivationMaximization(YOUR_MODEL,
                        model_modifier=[ExtractIntermediateLayer("intermediate-1"),
                                        ReplaceToLinear()])