-
-
Notifications
You must be signed in to change notification settings - Fork 428
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
Expectation Over Transformation Wrapper #719
Conversation
Great, thanks for preparing this! Would you mind adding unit tests for the new module, too? |
By looking at the other test files, I have added some tests to assert that wrapping the model with EoT does not change clean / robust accuracy (when no random transforms are applied). Don't know if this is correct. Also, I am not really sure how to add more complex tests (with random transformations applied to the input). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Except a few smaller things, this looks good to me! But please make sure that all tests listed at the end of the page pass; otherwise, we sadly cannot merge the PR.
tests/test_eot_attack.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's rename this file to something like test_eot_wrapper.py
.
tests/test_eot_attack.py
Outdated
from conftest import ModeAndDataAndDescription | ||
|
||
|
||
def test_eot_attack( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment above.
tests/test_eot_attack.py
Outdated
epsilons = (5000.0, L2(50.), Linf(1.)) | ||
|
||
for attack, eps in zip(attacks, epsilons): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove unnecessary whitespace.
I have uploaded a refactored version, which should now be compatible with |
Codecov ReportAll modified and coverable lines are covered by tests ✅
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #719 +/- ##
=======================================
Coverage 98.46% 98.47%
=======================================
Files 56 56
Lines 3529 3546 +17
=======================================
+ Hits 3475 3492 +17
Misses 54 54 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only one minor comment left, then we can merge this!
@@ -21,3 +21,29 @@ def __call__(self, inputs: T) -> T: | |||
y = ep.where(x < self._threshold, min_, max_).astype(x.dtype) | |||
z = self._model(y) | |||
return restore_type(z) | |||
|
|||
|
|||
class ExpectationOverTransformationWrapper(Model): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for not mentioning this earlier, but can you please add docstrings to the class & module like its done for the other classes in the project?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added it to the models.rst
file, taking the other wrapper module as an example.
However, I am not sure how to fix the version error for sphinx
. In my local machine, I tried to build html
docs with sphinx
version 5 and it works, but the requirements.txt
file in the docs folder wants:
sphinx==4.5.0
sphinx-autobuild==2021.3.14
sphinx_rtd_theme==1.0.0
sphinx-typlog-theme==0.8.0
Closes #563 and #191
My approach for implementing EoT.
I tried to follow the suggestions of @zimmerrol.
Basically, I created a new ExpectationOverTransformation Wrapper class that computes the forward pass
n_steps
times (default to 16) and returns the average prediction.I also created a new example for pytorch
resnet-18
model, which seems to work.Potential Issue: since the forward pass is executed
n_steps
times, the attack takes a long time for execution.