Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix default noise level for NoiseAugmentation #179

Merged
merged 7 commits into from
Dec 2, 2024
Merged

Conversation

adrhill
Copy link
Member

@adrhill adrhill commented Dec 2, 2024

The previous std was 0.1 instead of the documented 1.0.
A value of one is more in line with the recommendation from the SmoothGrad paper, which has been added to the docstring:

For optimal results, $REF_SMILKOV_SMOOTHGRAD recommends setting `std` between 10% and 20% of the input range of every sample,
e.g. `std = 0.1 * (maximum(input) - minimum(input))`.

@adrhill adrhill added the bug Something isn't working label Dec 2, 2024
renamed arg was optional, not a kwargs
@adrhill
Copy link
Member Author

adrhill commented Dec 2, 2024

The fixed default of std=1 should be in line with the recommendation from the SmoothGrad paper according to a simple numerical experiment, assuming normalized inputs:

julia> d = Normal(0, 1)
Normal{Float64}(μ=0.0, σ=1.0)

julia> function sample_range(n) # of normalized n-dim. input
         e = extrema(rand(d, n))
         return e[2] - e[1]
       end
sample_range (generic function with 2 methods)

julia> mean(sample_range(224*224*3) for _ in 1:1000)
8.939849898946928

julia> mean(sample_range(224*224*3) for _ in 1:1000)
8.959057153975865

julia> mean(sample_range(224*224*3) for _ in 1:1000)
8.943506279873574

scaled by 10-20%, std=1 appears to be adequate. CC @nealmckee.

@adrhill adrhill added the BREAKING Breaking change label Dec 2, 2024
@adrhill adrhill merged commit bd0e400 into master Dec 2, 2024
5 checks passed
@adrhill adrhill deleted the ah/fix-noise-scaling branch December 2, 2024 16:34
@nealmckee
Copy link

While the actual noise might be similar to the recommended level over the entire dataset, the original intention of Smoothgrad as I read it was to have a constant signal to noise ratio for each image, where they determine the noise ratio by looking at the maximum amplitude across the entire image and all channels.

Whether this is the best way to get a measure of the signal amplitude and whether it makes sense to adjust the noise level per image rather than per dataset is up for discussion, but if the intention is to have a standardized implementation, this would be it if one were to base it on the text of the paper.

It definitely makes sense to adjust the noise with respect to the data in some way, and if it’s per image it would make sense to bake it into the analyzer. Per dataset it’s reasonable to let the user enter it manually, though it has the downside of having less universal defaults.

@adrhill
Copy link
Member Author

adrhill commented Dec 3, 2024

the original intention of Smoothgrad as I read it was to have a constant signal to noise ratio for each image

Yes, I hope the new docstring makes that clear.

Since NoiseAugmentation is a general purpose wrapper around any analyzer and any sort of Sampleable the user defines (not just Gaussian distributions), simply specifying a "noise level" isn't possible.

I will decouple SmoothGrad from NoiseAugmentation in a follow-up PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BREAKING Breaking change bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants