keisen / tf-keras-vis

Neural network visualization toolkit for tf.keras
https://keisen.github.io/tf-keras-vis-docs/
MIT License
313 stars 45 forks source link

scorecam seems to be weighting all feature maps equally #103

Open amirro1 opened 8 months ago

amirro1 commented 8 months ago

Hi,

Thanks so much for this awesome repo.

I have been using the gradCAM and gradCAM++ functionality, and it has been working great. However, when I try to use the scorecam functionality, I am seeing some odd behavior. Specifically, the output appears to be an equal weighting of all of my activation maps from the last convolutional layer (rather than a weighting based on the score of the perturbed input images)

Because it seemed as though all of weights were equal, I dug into the source code where the weights were computed (inside the call method of scorecam.py). Here, I noticed that even though the scores of my perturbed images varied, the following line seemed to push every weight to 1:

weights = ([score(K.softmax(tf.constant(p))) for p in prediction]
                  for score, prediction in zip(scores, preds))

Could this be an issue with my score function ( I included the score function below)? Is there a way to formulate my model and input such that this line will not push every weight to 1?

Thanks, Amy

Simple score function:

def score_function_pos(output):
    score =output[:, 0]
    return score