raghakot / keras-vis

Neural network visualization toolkit for keras
https://raghakot.github.io/keras-vis
MIT License
2.98k stars 660 forks source link

add an option to get unnormalized gradient maps #178

Open eyaler opened 5 years ago

eyaler commented 5 years ago

in saliency functions we have

utils.normalize(grads)[0]

i want an option to get the raw gradients for thresholding or comparing between filters

keisen commented 5 years ago

Hi, @eyaler . Thank you for your request.

To create the option you said is so easy, but I'm wondering if I should do it. Something doesn't feel right with that the saliency function return the raw gradients, because it is the Gradient, not the Saliency. I believe we should use vis.optimizer.Optimizer when we want to get raw gradients.

opt = Optimizer(input_tensor, losses, wrt_tensor=wrt_tensor, norm_grads=False)
grads = opt.minimize(seed_input=seed_input, max_iter=1, grad_modifier=grad_modifier, verbose=False)[1]

I'd like to get your thoughts on this.

keisen commented 5 years ago

But, if we think the gradient is just used as the saliency, it should do it. I'm little bit confusing :confused:

eyaler commented 5 years ago

also there is a potential problem with this line: normalized = (array - arr_min) / (arr_max - arr_min + K.epsilon()) since array values can be in the magnitude of epsilon... maybe we should use max(arr_max - arr_min, K.epsilon())

eyaler commented 4 years ago

and the thing is that normalizing the gradients will always highlight something. but for finding negative evidence the magnitude is important

eyaler commented 4 years ago

also: grads = grads / (np.max(grads) + K.epsilon()) in grad cam