I created a CNN using TensorFlow2 and trained it as a binary classifier. Is there a way to extract the influence of each pixel upon the prediction?
I am trying to obtain a mask similar to the following:
Data Science Stack Exchange is a question and answer site for Data science professionals, Machine Learning specialists, and those interested in learning more about the field. It only takes a minute to sign up.
Sign up to join this communityI created a CNN using TensorFlow2 and trained it as a binary classifier. Is there a way to extract the influence of each pixel upon the prediction?
I am trying to obtain a mask similar to the following:
[updated]
You are looking for GradCam.
Code:
Paper: https://arxiv.org/abs/1610.02391
This is a good resource I found https://christophm.github.io/interpretable-ml-book/
The tf-explain package supports many interpretability methods. In particular, Grad CAM
can "visualize how parts of the image affects neural network's output by looking into the activation maps":
from tf_explain.callbacks.grad_cam import GradCAMCallback
model = [...]
callbacks = [
GradCAMCallback(
validation_data=(x_val, y_val),
class_index=0,
output_dir=output_dir,
)
]
model.fit(x_train, y_train, batch_size=2, epochs=2, callbacks=callbacks)