You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
triggers=self.generator(images.to(self.classifier.device)) #Generate dynamic, input-specific triggers using the trained TriggerGenerator
40
+
poisoned= (images.to(self.classifier.device) +self.epsilon*triggers).clamp(0, 1) # Clamp the pixel values to ensure they stay in the valid [0, 1] range.
41
+
returnpoisoned
42
+
# Poison the training data by injecting dynamic triggers and changing labels
43
+
defpoison(self, x, y):
44
+
# Convert raw image data (x) to torch tensors (float), and convert one-hot labels (y) to class indices-required by ART
45
+
x_tensor=torch.tensor(x).float()
46
+
y_tensor=torch.tensor(np.argmax(y, axis=1))
47
+
# Calculate total number of samples and how many should be poisoned(posion ratio=backdoor_rate)
48
+
batch_size=x_tensor.shape[0]
49
+
n_poison=int(self.backdoor_rate*batch_size)
50
+
# Apply the learned trigger to the first 'n_poison' samples
0 commit comments