From 6db3e5ce5c1b6ce0df81f74679e23cdcac73f5a0 Mon Sep 17 00:00:00 2001 From: Foxglove144 Date: Fri, 16 Jun 2023 21:24:51 +0200 Subject: [PATCH 1/2] Fix ragged nested sequence warning Signed-off-by: Foxglove144 --- art/defences/detector/poison/clustering_analyzer.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/art/defences/detector/poison/clustering_analyzer.py b/art/defences/detector/poison/clustering_analyzer.py index ef3742d984..e634af2b87 100644 --- a/art/defences/detector/poison/clustering_analyzer.py +++ b/art/defences/detector/poison/clustering_analyzer.py @@ -68,10 +68,9 @@ def analyze_by_size(self, separated_clusters: List[np.ndarray]) -> Tuple[np.ndar all_assigned_clean = [] nb_classes = len(separated_clusters) nb_clusters = len(np.unique(separated_clusters[0])) - summary_poison_clusters: np.ndarray = np.zeros((nb_classes, nb_clusters)) + summary_poison_clusters: np.ndarray = np.zeros((nb_classes, nb_clusters), dtype=object) for i, clusters in enumerate(separated_clusters): - # assume that smallest cluster is poisonous and all others are clean sizes = np.bincount(clusters) total_dp_in_class = np.sum(sizes) @@ -98,8 +97,9 @@ def analyze_by_size(self, separated_clusters: List[np.ndarray]) -> Tuple[np.ndar report["Class_" + str(i)] = report_class - report["suspicious_clusters"] = report["suspicious_clusters"] + np.sum(summary_poison_clusters).item() - return np.asarray(all_assigned_clean), summary_poison_clusters, report + report["suspicious_clusters"] = report["suspicious_clusters"] + np.sum(summary_poison_clusters) + # return np.asarray(all_assigned_clean), summary_poison_clusters, report + return np.asarray(all_assigned_clean, dtype=object), summary_poison_clusters, report def analyze_by_distance( self, @@ -187,7 +187,7 @@ def analyze_by_distance( assigned_clean = self.assign_class(clusters, clean_clusters, np.array(poison_clusters)) all_assigned_clean.append(assigned_clean) - all_assigned_clean_array = np.asarray(all_assigned_clean) + all_assigned_clean_array = np.asarray(all_assigned_clean, dtype=object) return all_assigned_clean_array, summary_poison_clusters, report def analyze_by_relative_size( From 5a41925f1140df82d6c5890c0297a352f9c65b0f Mon Sep 17 00:00:00 2001 From: Foxglove144 Date: Fri, 16 Jun 2023 21:31:49 +0200 Subject: [PATCH 2/2] Remove old code Signed-off-by: Foxglove144 --- art/defences/detector/poison/clustering_analyzer.py | 1 - 1 file changed, 1 deletion(-) diff --git a/art/defences/detector/poison/clustering_analyzer.py b/art/defences/detector/poison/clustering_analyzer.py index e634af2b87..6690197438 100644 --- a/art/defences/detector/poison/clustering_analyzer.py +++ b/art/defences/detector/poison/clustering_analyzer.py @@ -98,7 +98,6 @@ def analyze_by_size(self, separated_clusters: List[np.ndarray]) -> Tuple[np.ndar report["Class_" + str(i)] = report_class report["suspicious_clusters"] = report["suspicious_clusters"] + np.sum(summary_poison_clusters) - # return np.asarray(all_assigned_clean), summary_poison_clusters, report return np.asarray(all_assigned_clean, dtype=object), summary_poison_clusters, report def analyze_by_distance(