From 63916b202c5c717fe738cbf489cdc1533297df46 Mon Sep 17 00:00:00 2001 From: GiulioZizzo Date: Wed, 20 Dec 2023 15:23:11 +0000 Subject: [PATCH] mypy fixes Signed-off-by: GiulioZizzo --- .../certification/randomized_smoothing/pytorch.py | 7 +++++-- .../randomized_smoothing/smooth_adv/tensorflow.py | 1 - .../certification/randomized_smoothing/tensorflow.py | 8 +++++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/art/estimators/certification/randomized_smoothing/pytorch.py b/art/estimators/certification/randomized_smoothing/pytorch.py index 1006764080..e00f66692e 100644 --- a/art/estimators/certification/randomized_smoothing/pytorch.py +++ b/art/estimators/certification/randomized_smoothing/pytorch.py @@ -222,17 +222,20 @@ def fit( # pylint: disable=W0221 if scheduler is not None: scheduler.step() - def predict(self, x: np.ndarray, batch_size: int = 128, **kwargs) -> np.ndarray: # type: ignore + def predict(self, x: np.ndarray, batch_size: int = 128, verbose: bool = False, **kwargs) -> np.ndarray: # type: ignore """ Perform prediction of the given classifier for a batch of inputs, taking an expectation over transformations. :param x: Input samples. :param batch_size: Batch size. + :param verbose: Display training progress bar. :param is_abstain: True if function will abstain from prediction and return 0s. Default: True :type is_abstain: `boolean` :return: Array of predictions of shape `(nb_inputs, nb_classes)`. """ - return RandomizedSmoothingMixin.predict(self, x, batch_size=batch_size, training_mode=False, **kwargs) + return RandomizedSmoothingMixin.predict( + self, x, batch_size=batch_size, verbose=verbose, training_mode=False, **kwargs + ) def loss_gradient( # type: ignore self, x: np.ndarray, y: np.ndarray, training_mode: bool = False, **kwargs diff --git a/art/estimators/certification/randomized_smoothing/smooth_adv/tensorflow.py b/art/estimators/certification/randomized_smoothing/smooth_adv/tensorflow.py index f83341ab6f..0887e7ce6c 100644 --- a/art/estimators/certification/randomized_smoothing/smooth_adv/tensorflow.py +++ b/art/estimators/certification/randomized_smoothing/smooth_adv/tensorflow.py @@ -125,7 +125,6 @@ def __init__( sample_size=sample_size, scale=scale, alpha=alpha, - verbose=verbose, ) self.epsilon = epsilon self.num_noise_vec = num_noise_vec diff --git a/art/estimators/certification/randomized_smoothing/tensorflow.py b/art/estimators/certification/randomized_smoothing/tensorflow.py index db148b389f..908feb381d 100644 --- a/art/estimators/certification/randomized_smoothing/tensorflow.py +++ b/art/estimators/certification/randomized_smoothing/tensorflow.py @@ -70,7 +70,6 @@ def __init__( sample_size: int = 32, scale: float = 0.1, alpha: float = 0.001, - verbose: bool = False, ): """ Create a randomized smoothing classifier. @@ -192,17 +191,20 @@ def train_step(model, images, labels): if scheduler is not None: scheduler(epoch) - def predict(self, x: np.ndarray, batch_size: int = 128, **kwargs) -> np.ndarray: # type: ignore + def predict(self, x: np.ndarray, batch_size: int = 128, verbose: bool = False, **kwargs) -> np.ndarray: # type: ignore """ Perform prediction of the given classifier for a batch of inputs, taking an expectation over transformations. :param x: Input samples. :param batch_size: Batch size. + :param verbose: Display training progress bar. :param is_abstain: True if function will abstain from prediction and return 0s. Default: True :type is_abstain: `boolean` :return: Array of predictions of shape `(nb_inputs, nb_classes)`. """ - return RandomizedSmoothingMixin.predict(self, x, batch_size=batch_size, training_mode=False, **kwargs) + return RandomizedSmoothingMixin.predict( + self, x, batch_size=batch_size, verbose=verbose, training_mode=False, **kwargs + ) def loss_gradient(self, x: np.ndarray, y: np.ndarray, training_mode: bool = False, **kwargs) -> np.ndarray: """