class_docstr: Implements the functionality for albating the image, and retaining only a block
class_docstr_tok: ["Implements","the","functionality","for","albating","the","image",",","and","retaining","only","a","block"]
docstr: Checks if based on the predictions supplied the classifications over the ablated datapoints result in a
  certified prediction against a patch attack of size size_to_certify.
  
  :param pred_counts: The cumulative predictions of the classifier over the ablation locations.
  :param size_to_certify: The size of the patch to check against.
  :param label: Ground truth labels
  :return: A tuple consisting of: the certified predictions,
           the predictions which were certified and also correct,
           and the most predicted class across the different ablations on the input.
docstr_tok: ["Checks","if","based","on","the","predictions","supplied","the","classifications","over","the","ablated","datapoints","result","in","a","certified","prediction","against","a","patch","attack","of","size","size_to_certify",".",":","param","pred_counts",":","The","cumulative","predictions","of","the","classifier","over","the","ablation","locations",".",":","param","size_to_certify",":","The","size","of","the","patch","to","check","against",".",":","param","label",":","Ground","truth","labels",":","return",":","A","tuple","consisting","of",":","the","certified","predictions",",","the","predictions","which","were","certified","and","also","correct",",","and","the","most","predicted","class","across","the","different","ablations","on","the","input","."]
code: def certify(
      self,
      pred_counts: Union["tf.Tensor", np.ndarray],
      size_to_certify: int,
      label: Union[np.ndarray, "tf.Tensor"],
  ) -> Tuple["tf.Tensor", "tf.Tensor", "tf.Tensor"]:
      """
      Checks if based on the predictions supplied the classifications over the ablated datapoints result in a
      certified prediction against a patch attack of size size_to_certify.
  
      :param pred_counts: The cumulative predictions of the classifier over the ablation locations.
      :param size_to_certify: The size of the patch to check against.
      :param label: Ground truth labels
      :return: A tuple consisting of: the certified predictions,
               the predictions which were certified and also correct,
               and the most predicted class across the different ablations on the input.
      """
      import tensorflow as tf
  
      result = tf.math.top_k(pred_counts, k=2)
  
      top_predicted_class, second_predicted_class = (
          result.indices[:, 0],
          result.indices[:, 1],
      )
      top_class_counts, second_class_counts = (
          result.values[:, 0],
          result.values[:, 1],
      )
  
      certs = (top_class_counts - second_class_counts) > 2 * (
          size_to_certify + self.ablation_size - 1
      ) ** 2
      tie_break_certs = (
          (top_class_counts - second_class_counts)
          == 2 * (size_to_certify + self.ablation_size - 1) ** 2
      ) & (top_predicted_class < second_predicted_class)
      cert = tf.math.logical_or(certs, tie_break_certs)
  
      # NB, newer versions of pylint do not require the disable.
      if label.ndim > 1:
          cert_and_correct = cert & (
              tf.math.argmax(label, axis=1)
              == tf.cast(  # pylint: disable=E1120, E1123
                  top_predicted_class,
                  dtype=tf.math.argmax(label, axis=1).dtype,
              )
          )
      else:
          cert_and_correct = cert & (
              label
              == tf.cast(
                  top_predicted_class, dtype=label.dtype
              )  # pylint: disable=E1120, E1123
          )
  
      return cert, cert_and_correct, top_predicted_class
  
file_path: adversarial-robustness-toolbox/art/estimators/certification/derandomized_smoothing/ablators/tensorflow.py
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  from typing import Optional, Union, Tuple, TYPE_CHECKING
  import random
  import numpy
  from art.estimators.certification.derandomized_smoothing.ablators.ablate import BaseAblator
label_desc: Use image node_id 3 for calling the BlockAblator obj's underlying member method code with example usage: obj.certify(pred_counts, size_to_certify, label) and returns: cert,  cert_and_correct,  top_predicted_class