Skip to content

Commit 9be8e72

Browse files
committed
Final test fixes
Signed-off-by: Álvaro Bacca Peña <[email protected]>
1 parent 5934878 commit 9be8e72

File tree

7 files changed

+2458
-769
lines changed

7 files changed

+2458
-769
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ RUN pip3 install tensorflow==2.9.1 keras==2.9.0 numpy==1.22.4 scipy==1.8.1 matpl
99
resampy==0.3.1 ffmpeg-python==0.2.0 cma==3.2.2 pandas==1.4.3 h5py==3.7.0 tensorflow-addons==0.17.1 \
1010
torch==1.12.0 torchaudio==0.12.0 torchvision==0.13.0 catboost==1.0.6 GPy==1.10.0 \
1111
lightgbm==3.3.2 xgboost==1.6.1 kornia==0.6.6 lief==0.12.1 pytest==7.1.2 pytest-pep8==1.0.6 \
12-
pytest-mock==3.8.2 requests==2.28.1
12+
pytest-mock==3.8.2 requests==2.28.1 umap-learn==0.5.7
1313

1414
RUN apt-get -y install ffmpeg libavcodec-extra vim git
1515

art/attacks/poisoning/perturbations/__init__.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,3 @@
77
add_single_bd,
88
insert_image,
99
)
10-
11-
from .network_perturbations import (
12-
create_flip_perturbation
13-
)

art/defences/detector/poison/clustering_centroid_analysis.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,6 @@ def get_clusters(self) -> np.array:
244244

245245
return result
246246

247-
# TODO: MAP THE ENCODINGS
248-
# NP ARGMAX IN THE LAST LAYER
249247
def __init__(
250248
self,
251249
classifier: "CLASSIFIER_TYPE",
@@ -254,7 +252,7 @@ def __init__(
254252
benign_indices: np.array,
255253
final_feature_layer_name: str,
256254
misclassification_threshold: float,
257-
reducer = UMAP(n_neighbors=5, min_dist=0, random_state=42),
255+
reducer = UMAP(n_neighbors=5, min_dist=0),
258256
clusterer = DBSCAN(eps=0.8, min_samples=20)
259257
):
260258
"""
@@ -472,8 +470,7 @@ def detect_poison(self, **kwargs) -> (dict, list[int]):
472470

473471
logging.info("Evaluating cluster misclassification...")
474472
for cluster_label, mr in misclassification_rates.items():
475-
# FIXME: changed the misclassification threshold
476-
if mr >= self.misclassification_threshold:
473+
if mr >= 1 - self.misclassification_threshold:
477474
cluster_indices = np.where(self.class_cluster_labels == cluster_label)[0]
478475
self.is_clean[cluster_indices] = 0
479476
logging.info(f"Cluster k={cluster_label} i={self.cluster_class_mapping[cluster_label]} considered poison ({misclassification_rates[cluster_label]} >= {1 - self.misclassification_threshold})")

notebooks/poisoning_defense_clustering_centroid_analysis.ipynb

Lines changed: 2448 additions & 757 deletions
Large diffs are not rendered by default.

requirements_test.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ opencv-python
2121
sortedcontainers==2.4.0
2222
h5py==3.13.0
2323
multiprocess>=0.70.12
24+
umap-learn==0.5.7
2425

2526
# frameworks
2627

run_tests.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ then
2525
pytest --cov-report=xml --cov=art --cov-append -q -vv tests/defences/detector/poison/test_spectral_signature_defense.py --framework=$framework --durations=20 --durations-min=0
2626
if [[ $? -ne 0 ]]; then exit_code=1; echo "Failed defences/detector/poison/test_spectral_signature_defense.py tests"; fi
2727

28+
pytest --cov-report=xml --cov=art --cov-append -q -vv tests/defences/detector/poison/test_clustering_centroid_analysis.py --framework=$framework --durations=20 --durations-min=0
29+
if [[ $? -ne 0 ]]; then exit_code=1; echo "Failed defences/detector/poison/test_clustering_centroid_analysis.py tests"; fi
30+
2831
pytest --cov-report=xml --cov=art --cov-append -q -vv tests/defences/preprocessor --framework=$framework --durations=20 --durations-min=0
2932
if [[ $? -ne 0 ]]; then exit_code=1; echo "Failed defences/preprocessor tests"; fi
3033

@@ -161,6 +164,7 @@ else
161164

162165
declare -a art=("tests/test_data_generators.py" \
163166
"tests/test_optimizers.py" \
167+
"tests/test_performance_monitor.py" \
164168
"tests/test_utils.py" \
165169
"tests/test_visualization.py" )
166170

tests/defences/detector/poison/test_clustering_centroid_analysis.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,7 @@ def test_detect_poison_all_benign(self):
953953
y_train=self.y_train,
954954
benign_indices=self.benign_indices,
955955
final_feature_layer_name='hidden_layer',
956-
misclassification_threshold=0.1
956+
misclassification_threshold=0.1 # 1.0 - 0.1 = 0.9
957957
)
958958

959959
# Mock the _calculate_misclassification_rate method to return low rates (all benign)
@@ -981,7 +981,7 @@ def test_detect_poison_with_poisoned_samples_as_outliers(self):
981981
y_train=self.y_train,
982982
benign_indices=self.benign_indices,
983983
final_feature_layer_name='hidden_layer',
984-
misclassification_threshold=0.1
984+
misclassification_threshold=0.1 # 1.0 - 0.1 = 0.9
985985
)
986986

987987
# Mock the _calculate_misclassification_rate method to return low rates (all benign)

0 commit comments

Comments
 (0)