sicara / tf-explain

Interpretability Methods for tf.keras models with Tensorflow 2.x
https://tf-explain.readthedocs.io
MIT License
1.02k stars 112 forks source link

Different shapes from running methods of tf.xplain.core #187

Open annahedstroem opened 1 year ago

annahedstroem commented 1 year ago

Problem

The output shape of explanations differ for GradCAM (and OcclusionSensitivity) and e.g., VanillaGradient, where GradCAM also includes the channels.

Implementation

While the syntax is the same:

explainer = tf_explain.core.grad_cam.GradCAM()
        explanation = (
            np.array(
                list(
                    map(
                        lambda x, y: explainer.explain(
                            ([x], None), model, y, **method_kwargs
                        ),
                        inputs,
                        targets,
                    )
                ),
                dtype=float,
            )
            / 255
        )

=== {"shape": (nr_samples, img_size, img_size, nr_channels)},

vs

explainer = tf_explain.core.vanilla_gradients.VanillaGradients()
        explanation = (
            np.array(
                list(
                    map(
                        lambda x, y: explainer.explain(
                            ([x], None), model, y, **method_kwargs
                        ),
                        inputs,
                        targets,
                    )
                ),
                dtype=float,
            )
            / 255
        )

=== {"shape": (nr_samples, img_size, img_size)},

Thank you!

annahedstroem commented 1 year ago

(code from https://github.com/understandable-machine-intelligence-lab/Quantus package!)