-
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
base: dev_1.19.0
Are you sure you want to change the base?
Conversation
""" | ||
from __future__ import absolute_import, division, print_function, unicode_literals, annotations | ||
|
||
import abc |
Check notice
Code scanning / CodeQL
Unused import Note
from __future__ import absolute_import, division, print_function, unicode_literals, annotations | ||
|
||
import abc | ||
from typing import Any |
Check notice
Code scanning / CodeQL
Unused import Note
:param batch_size: Batch size for processing | ||
:param nb_epochs: Number of training epochs (not used in this method) | ||
""" | ||
clean_similarities = self._get_metrics(x, batch_size) |
Check notice
Code scanning / CodeQL
Unused local variable Note
import pytest | ||
import numpy as np | ||
|
||
import sys |
Check notice
Code scanning / CodeQL
Unused import Note test
import numpy as np | ||
|
||
import sys | ||
import os |
Check notice
Code scanning / CodeQL
Unused import Note test
import os | ||
|
||
from art.attacks.evasion.fast_gradient import FastGradientMethod | ||
from art.estimators.classification import PyTorchClassifier |
Check notice
Code scanning / CodeQL
Unused import Note test
from art.attacks.evasion.fast_gradient import FastGradientMethod | ||
from art.estimators.classification import PyTorchClassifier | ||
from art.defences.detector.evasion import BeyondDetector | ||
from art.utils import load_dataset, get_file |
Check notice
Code scanning / CodeQL
Unused import Note test
Import of 'get_file' is not used.
def test_beyond_detector(art_warning, get_cifar10, get_ssl_model): | ||
try: | ||
# Load CIFAR10 data | ||
(x_train, y_train), (x_test, y_test), min_, max_ = get_cifar10 |
Check notice
Code scanning / CodeQL
Unused local variable Note test
def test_beyond_detector(art_warning, get_cifar10, get_ssl_model): | ||
try: | ||
# Load CIFAR10 data | ||
(x_train, y_train), (x_test, y_test), min_, max_ = get_cifar10 |
Check notice
Code scanning / CodeQL
Unused local variable Note test
detector = BeyondDetector( | ||
target_model=target_model, | ||
ssl_model=ssl_model, | ||
img_augmentation=img_augmentations, | ||
aug_num=50, | ||
alpha=0.8, | ||
K=20, | ||
percentile=5 | ||
) |
Check failure
Code scanning / CodeQL
Wrong name for an argument in a class instantiation Error test
BeyondDetector.__init__
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev_1.19.0 #2489 +/- ##
==============================================
- Coverage 85.23% 77.12% -8.11%
==============================================
Files 329 330 +1
Lines 30143 30208 +65
Branches 5173 5177 +4
==============================================
- Hits 25693 23299 -2394
- Misses 3021 5606 +2585
+ Partials 1429 1303 -126
|
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?
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()
.
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