Skip to content

Commit 65520d6

Browse files
committed
fix poison backdoor image trigger bug
Signed-off-by: Farhan Ahmed <[email protected]>
1 parent b13f802 commit 65520d6

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

art/attacks/poisoning/perturbations/image_perturbations.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,17 +143,17 @@ def insert_image(
143143
orig_img.paste(backdoored_input)
144144

145145
trigger = Image.open(backdoor_path).convert("RGBA")
146-
if size:
147-
trigger = trigger.resize(size)
146+
if size is not None:
147+
trigger = trigger.resize(size[1], size[0]) # height and width are swapped for PIL
148148

149149
backdoor_width, backdoor_height = trigger.size # height and width are swapped for PIL
150150

151151
if backdoor_width > width or backdoor_height > height:
152152
raise ValueError("Backdoor does not fit inside original image")
153153

154154
if random:
155-
x_shift = np.random.randint(width - backdoor_width)
156-
y_shift = np.random.randint(height - backdoor_height)
155+
x_shift = np.random.randint(width - backdoor_width + 1)
156+
y_shift = np.random.randint(height - backdoor_height + 1)
157157

158158
backdoored_img.paste(trigger, (x_shift, y_shift), mask=trigger)
159159
composite = Image.alpha_composite(orig_img, backdoored_img)

0 commit comments

Comments
 (0)