-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Added support for BEYOND [ICML-2024] #2489
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev_1.19.0 #2489 +/- ##
==============================================
- Coverage 53.27% 49.07% -4.21%
==============================================
Files 666 668 +2
Lines 61858 61982 +124
Branches 10516 10523 +7
==============================================
- Hits 32956 30416 -2540
- Misses 27205 29999 +2794
+ Partials 1697 1567 -130
|
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.
Hi @allenhzy Thank you very much for your pull request! Could you please take a look at my review comments and add the proposed updates?
@@ -0,0 +1,163 @@ | |||
# MIT License | |||
# | |||
# Copyright (C) The Adversarial Robustness Toolbox (ART) Authors 2023 |
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.
# Copyright (C) The Adversarial Robustness Toolbox (ART) Authors 2023 | |
# Copyright (C) The Adversarial Robustness Toolbox (ART) Authors 2024 |
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
# SOFTWARE. | ||
""" | ||
This module implements the abstract base class for all evasion detectors. |
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.
This module implements the abstract base class for all evasion detectors. | |
This module implements the BEYOND detector for adversarial examples detection. | |
| Paper link: https://openreview.net/pdf?id=S4LqI6CcJ3 |
""" | ||
BEYOND detector for adversarial samples detection. | ||
This detector uses a combination of SSL and target model predictions to detect adversarial samples. | ||
""" |
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.
""" | |
BEYOND detector for adversarial samples detection. | |
This detector uses a combination of SSL and target model predictions to detect adversarial samples. | |
""" | |
""" | |
BEYOND detector for adversarial samples detection. | |
This detector uses a combination of SSL and target model predictions to detect adversarial examples. | |
| Paper link: https://openreview.net/pdf?id=S4LqI6CcJ3 | |
""" |
from __future__ import absolute_import, division, print_function, unicode_literals, annotations | ||
|
||
import abc | ||
from typing import Any |
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.
from typing import Any |
from __future__ import absolute_import, division, print_function, unicode_literals, annotations | ||
|
||
import abc | ||
from typing import Any |
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.
from typing import Any |
(x_train, y_train), (x_test, y_test), min_, max_ = get_cifar10 | ||
|
||
# Load models | ||
# Download pretrained weights from https://drive.google.com/drive/folders/1ieEdd7hOj2CIl1FQfu4-3RGZmEj-mesi?usp=sharing |
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.
How large are the downloaded files? Can we store them in the ART repo?
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.
The pre-trained model has over 100 M
print(f"Clean Detection Accuracy: {clean_accuracy:.4f}") | ||
print(f"Adversarial Detection Accuracy: {adv_accuracy:.4f}") |
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.
Please replace print
with logger
.
assert nb_true_positives > 0 | ||
assert nb_true_negatives > 0 |
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.
Would it be possible to make these assertions more accurate?
return {'z1': z1, 'z2': z2, 'p1': p1, 'p2': p2} | ||
|
||
@pytest.fixture | ||
def get_cifar10(): |
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.
I think we can use load_cifar10()
directly and remove get_cifar10()(
.
""" | ||
Loads CIFAR10 dataset. | ||
""" | ||
(x_train, y_train), (x_test, y_test), min_, max_ = load_cifar10() |
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.
Add import for fixture load_cifar10()
.
_, test_adv_detection = detector.detect(x_test_adv) | ||
|
||
# Assert there is at least one true positive and negative | ||
nb_true_positives = np.sum(test_adv_detection) |
Check notice
Code scanning / CodeQL
Unused local variable Note test
|
||
# Assert there is at least one true positive and negative | ||
nb_true_positives = np.sum(test_adv_detection) | ||
nb_true_negatives = len(test_detection) - np.sum(test_detection) |
Check notice
Code scanning / CodeQL
Unused local variable Note test
nb_true_positives = np.sum(test_adv_detection) | ||
nb_true_negatives = len(test_detection) - np.sum(test_detection) | ||
|
||
clean_accuracy = 1 - np.mean(test_detection) |
Check notice
Code scanning / CodeQL
Unused local variable Note test
nb_true_negatives = len(test_detection) - np.sum(test_detection) | ||
|
||
clean_accuracy = 1 - np.mean(test_detection) | ||
adv_accuracy = np.mean(test_adv_detection) |
Check notice
Code scanning / CodeQL
Unused local variable Note test
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.
Hi @allenhzy Thank you very much for your updates! Could you please take a look above at my two last change requests and the alerts from CodeQL about unused variables?
""" | ||
This module implements the BEYOND detector for adversarial examples detection. | ||
| Paper link: https://openreview.net/pdf?id=S4LqI6CcJ3 | ||
""" |
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.
""" | |
This module implements the BEYOND detector for adversarial examples detection. | |
| Paper link: https://openreview.net/pdf?id=S4LqI6CcJ3 | |
""" | |
""" | |
This module implements the BEYOND detector for adversarial examples detection. | |
| Paper link: https://openreview.net/pdf?id=S4LqI6CcJ3 | |
""" |
from art.utils import CLASSIFIER_NEURALNETWORK_TYPE | ||
|
||
|
||
logger = logging.getLogger(__name__) |
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.
This line seems to cause the unittest errors because of the missing import of logging
. Because the attack here is not actively using logging I suggest to remove this line.
logger = logging.getLogger(__name__) |
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.
I have revised the related codes.
Dear Beat,
I have revised the codes.
Please check it.
Best,
Zhiyuan HE
发件人: Beat Buesser ***@***.***>
日期: 星期一, 2024年12月9日 下午7:29
收件人: Trusted-AI/adversarial-robustness-toolbox ***@***.***>
抄送: hzy ***@***.***>, Mention ***@***.***>
主题: Re: [Trusted-AI/adversarial-robustness-toolbox] Added support for BEYOND [ICML-2024] (PR #2489)
@beat-buesser commented on this pull request.
Hi @allenhzy<https://github.com/allenhzy> Thank you very much for your updates! Could you please take a look above at my two last change requests and the alerts from CodeQL about unused variables?
________________________________
In art/defences/detector/evasion/beyond_detector.py<#2489 (comment)>:
+"""
+This module implements the BEYOND detector for adversarial examples detection.
+| Paper link: https://openreview.net/pdf?id=S4LqI6CcJ3
+"""
⬇️ Suggested change
-"""
-This module implements the BEYOND detector for adversarial examples detection.
-| Paper link: https://openreview.net/pdf?id=S4LqI6CcJ3
-"""
+"""
+This module implements the BEYOND detector for adversarial examples detection.
+
+| Paper link: https://openreview.net/pdf?id=S4LqI6CcJ3
+"""
________________________________
In art/defences/detector/evasion/beyond_detector.py<#2489 (comment)>:
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+"""
+This module implements the BEYOND detector for adversarial examples detection.
+| Paper link: https://openreview.net/pdf?id=S4LqI6CcJ3
+"""
+import numpy as np
+from typing import TYPE_CHECKING
+if TYPE_CHECKING:
+ from art.utils import CLASSIFIER_NEURALNETWORK_TYPE
+
+
+logger = logging.getLogger(__name__)
This line seems to cause the unittest errors because of the missing import of logging. Because the attack here is not actively using logging I suggest to remove this line.
⬇️ Suggested change
…-logger = logging.getLogger(__name__)
—
Reply to this email directly, view it on GitHub<#2489 (review)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AF2RSJG555KPWYSJTCOORXT2EV5IFAVCNFSM6AAAAABNRUHJ7CVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDIOBYGM3TSMBVGU>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
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.
Hi @allenhzy Thank you very much! There seems to be one more item making the test fail, the code suggestion above should fix them. Could you please add them to the PR?
Description
This pull request adds the support of the BEYOND Detection method proposed in [1].
[1] Be Your Own Neighborhood: Detecting Adversarial Example by the Neighborhood Relations Built on Self-Supervised Learning. ICML. 2024[Paper]
Type of change
Please check all relevant options.
Testing
Please describe the tests that you ran to verify your changes. Consider listing any relevant details of your test configuration.
Test Configuration:
Checklist