diff --git a/alibi_detect/utils/perturbation.py b/alibi_detect/utils/perturbation.py index 5a29e8663..348e9c2b8 100644 --- a/alibi_detect/utils/perturbation.py +++ b/alibi_detect/utils/perturbation.py @@ -865,8 +865,8 @@ def pixelate(x: np.ndarray, strength: float, xrange: tuple = None) -> np.ndarray x = (x - xrange[0]) / (xrange[1] - xrange[0]) * 255 im = Image.fromarray(x.astype('uint8'), mode='RGB') - im = im.resize((int(rows * strength), int(cols * strength)), Image.BOX) - im = im.resize((rows, cols), Image.BOX) + im = im.resize((int(rows * strength), int(cols * strength)), Image.Resampling.BOX) + im = im.resize((rows, cols), Image.Resampling.BOX) x_pi = np.array(im, dtype=np.float32) / 255 x_pi = x_pi * (xrange[1] - xrange[0]) + xrange[0] return x_pi @@ -898,8 +898,8 @@ def jpeg_compression(x: np.ndarray, strength: float, xrange: tuple = None) -> np x = Image.fromarray(x.astype('uint8'), mode='RGB') output = BytesIO() x.save(output, 'JPEG', quality=strength) # type: ignore[attr-defined] # TODO: allow redefinition - x = Image.open(output) - x_jpeg = np.array(x, dtype=np.float32) / 255 + x_image = Image.open(output) + x_jpeg = np.array(x_image, dtype=np.float32) / 255 x_jpeg = x_jpeg * (xrange[1] - xrange[0]) + xrange[0] return x_jpeg