utkuozbulak / pytorch-cnn-visualizations

Pytorch implementation of convolutional neural network visualization techniques
MIT License
7.81k stars 1.49k forks source link

SmoothGrad incorrect sigma calculation? #99

Closed czhao39 closed 3 years ago

czhao39 commented 3 years ago

https://github.com/utkuozbulak/pytorch-cnn-visualizations/blob/16eddfa055a9c618ba548e9fb4529e2ccbc79c35/src/smooth_grad.py#L33

Shouldn't sigma be proportional to the range of the input, not inversely proportional to it? Following the original paper, I think it would make more sense to define sigma as:

sigma = param_sigma_prop * (torch.max(prep_img) - torch.min(prep_img)).item()

where param_sigma_prop is the "noise level" in the paper.

TejasKarkera10 commented 3 years ago

Hey @utkuozbulak Should I fix this issue ?

utkuozbulak commented 3 years ago

It's not a major issue. Just a matter of a scalar multiplier. I appreciate the heads up but anyone who uses it can simply select 1/mul instead of mul without much trouble.