Skip to content

Commit 230b522

Browse files
committed
fix small bug on jpeg_compression
1 parent 2bf3f0a commit 230b522

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

art/defences/jpeg_compression.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def __init__(self, quality=50, channel_index=3):
3131
self._is_fitted = True
3232
self.set_params(quality=quality, channel_index=channel_index)
3333

34-
def __call__(self, x, y=None, quality=None):
34+
def __call__(self, x, y=None, quality=None, clip_values=(0, 1)):
3535
"""
3636
Apply jpeg compression to sample `x`.
3737
@@ -92,6 +92,8 @@ def __call__(self, x, y=None, quality=None):
9292
if self.channel_index < 3:
9393
x_ = np.swapaxes(x_, self.channel_index, 3)
9494

95+
x_ = np.clip(x_, clip_values[0], clip_values[1])
96+
9597
return x_
9698

9799
def fit(self, x, y=None, **kwargs):

0 commit comments

Comments
 (0)