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
Describe the bug
The insert_image function in art.attacks.poisoning.perturbations has two bugs involving the placement of the trigger image.
Due to Pillow swapping the height and width, a non-square trigger is the wrong dimensions when placed onto the image. This was partially addressed by PR Fix Incorrect Height and Width for Image Perturbations #2046 which fixed the incorrect dimensions for the input image, but did not make the same change for the trigger. The fix is is to apply the same where the height and width are swapped.
When the trigger height or width is the same size as the image height or width, the insert_image function will error due to the np.random.randint function not accepting 0 as the upper bound. This numpy function will sample from the lower bound inclusively and upper bound exclusively. This is an off-by-one error and can be easily fixed by adding one to the difference between the image height/width and trigger height/width.
To Reproduce
The following code snippet will reproduce the first bug:
Describe the bug
The
insert_image
function inart.attacks.poisoning.perturbations
has two bugs involving the placement of the trigger image.Due to Pillow swapping the height and width, a non-square trigger is the wrong dimensions when placed onto the image. This was partially addressed by PR Fix Incorrect Height and Width for Image Perturbations #2046 which fixed the incorrect dimensions for the input image, but did not make the same change for the trigger. The fix is is to apply the same where the height and width are swapped.
When the trigger height or width is the same size as the image height or width, the
insert_image
function will error due to thenp.random.randint
function not accepting 0 as the upper bound. This numpy function will sample from the lower bound inclusively and upper bound exclusively. This is an off-by-one error and can be easily fixed by adding one to the difference between the image height/width and trigger height/width.To Reproduce
The following code snippet will reproduce the first bug:
From this, the trigger will be inserted as a
10 x 5
rather than the specified5 x 10
due to Pillow swapping the height and width order.The following code snippet will reproduce the second bug:
This will raise an exception due to the
np.random.randint
function not accepting a value of 0 as the trigger and image size are the same.Expected behavior
The
insert_image
function should produce the correct behavior and not error when valid inputs are provided.Screenshots
N/A
System information (please complete the following information):
The text was updated successfully, but these errors were encountered: