class_docstr: Implementation of (De)Randomized Smoothing applied to classifier predictions as introduced
  in Levine et al. (2020).
  
  | Paper link: https://arxiv.org/abs/2002.10733
class_docstr_tok: ["Implementation","of","(","De",")","Randomized","Smoothing","applied","to","classifier","predictions","as","introduced","in","Levine","et","al",".","(","2020",")",".","|","Paper","link",":","https",":","\/\/arxiv.org\/abs\/2002.10733"]
docstr: Performs cumulative predictions over every ablation location
  
  :param x: Unablated image
  :param batch_size: the batch size for the prediction
  :param training_mode: if to run the classifier in training mode
  :return: cumulative predictions after sweeping over all the ablation configurations.
docstr_tok: ["Performs","cumulative","predictions","over","every","ablation","location",":","param","x",":","Unablated","image",":","param","batch_size",":","the","batch","size","for","the","prediction",":","param","training_mode",":","if","to","run","the","classifier","in","training","mode",":","return",":","cumulative","predictions","after","sweeping","over","all","the","ablation","configurations","."]
code: def predict(
      self,
      x: np.ndarray,
      batch_size: int = 128,
      training_mode: bool = False,
      **kwargs,
  ) -> np.ndarray:
      """
      Performs cumulative predictions over every ablation location
  
      :param x: Unablated image
      :param batch_size: the batch size for the prediction
      :param training_mode: if to run the classifier in training mode
      :return: cumulative predictions after sweeping over all the ablation configurations.
      """
      if self._channels_first:
          columns_in_data = x.shape[-1]
          rows_in_data = x.shape[-2]
      else:
          columns_in_data = x.shape[-2]
          rows_in_data = x.shape[-3]
  
      if self.ablation_type in {"column", "row"}:
          if self.ablation_type == "column":
              ablate_over_range = columns_in_data
          else:
              # image will be transposed, so loop over the number of rows
              ablate_over_range = rows_in_data
  
          for ablation_start in range(ablate_over_range):
              ablated_x = self.ablator.forward(
                  np.copy(x), column_pos=ablation_start
              )
              if ablation_start == 0:
                  preds = self._predict_classifier(
                      ablated_x,
                      batch_size=batch_size,
                      training_mode=training_mode,
                      **kwargs,
                  )
              else:
                  preds += self._predict_classifier(
                      ablated_x,
                      batch_size=batch_size,
                      training_mode=training_mode,
                      **kwargs,
                  )
      elif self.ablation_type == "block":
          for xcorner in range(rows_in_data):
              for ycorner in range(columns_in_data):
                  ablated_x = self.ablator.forward(
                      np.copy(x), row_pos=xcorner, column_pos=ycorner
                  )
                  if ycorner == 0 and xcorner == 0:
                      preds = self._predict_classifier(
                          ablated_x,
                          batch_size=batch_size,
                          training_mode=training_mode,
                          **kwargs,
                      )
                  else:
                      preds += self._predict_classifier(
                          ablated_x,
                          batch_size=batch_size,
                          training_mode=training_mode,
                          **kwargs,
                      )
      return preds
  
file_path: adversarial-robustness-toolbox/art/estimators/certification/derandomized_smoothing/tensorflow.py
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import logging
  from typing import Callable, List, Optional, Tuple, Union, TYPE_CHECKING
  import numpy
  from tqdm import tqdm
  from art.estimators.certification.derandomized_smoothing.derandomized import DeRandomizedSmoothingMixin
  from art.estimators.classification.tensorflow import TensorFlowV2Classifier
  from art.utils import check_and_transform_label_format
label_desc: Use image node_id 4 for calling the TensorFlowV2DeRandomizedSmoothing obj's underlying member method code with example usage: obj.predict(x, batch_size, training_mode) and returns: preds