Fix inconsistencies in fgsm_tutorial #2418
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #1032
Description
mean=0.1307
andstd=0.3081
. However, no normalization was being applied in this example. Thus, the same normalization is applied to thetest_loader
in this example.state_dict
of the MNIST was being loaded on the CPU even thoughuse_cuda=True
anddevice
is being dynamically defined. Therefore,map_location=device
instead ofcpu
test
function is modified. After computing the gradient of the normalized data, the data is unnormalized. FGSM is then applied on unnormalized data. Finally, the perturbed data is again normalized before applying the model on it.I also checked the code without step 5, i.e., not performing normalization and denormalization inside the
test
function. The observation was that the accuracy stayed the same between 98-99%, although it was supposed to fall. Applying step 5 rectified this issue.Checklist