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
String For Simplicity: The All Convolutional Net (https://arxiv.org/pdf/1412.6806.pdf)
Grad-CAM: Why did you say that? Visual Explanations from Deep Networks via Gradient-based Localization (https://arxiv.org/pdf/1610.02391v1.pdf)
Warning
Please note that there is a discussion that Guided Backpropagation is not working well as model explanations.
Sanity Checks for Saliency Maps (https://arxiv.org/pdf/1810.03292.pdf)
Guided Grad-CAM is Broken! Sanity Checks for Saliency Maps (https://glassboxmedicine.com/2019/10/12/guided-grad-cam-is-broken-sanity-checks-for-saliency-maps/)
- 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()])