code: def get_or_guess_labels(model_fn, x, y=None, targeted=False):
      """
      Helper function to get the label to use in generating an
      adversarial example for x.
      If 'y' is not None, then use these labels.
      If 'targeted' is True, then assume it's a targeted attack
      and y must be set.
      Otherwise, use the model's prediction as the label and perform an
      untargeted attack
      :param model_fn: a callable that takes an input tensor and returns the model logits.
      :param x: input tensor.
      """
      if targeted is True and y is None:
          raise ValueError("Must provide y for a targeted attack!")
  
      preds = model_fn(x)
      nb_classes = preds.shape[-1]
  
      # labels set by the user
      if y is not None:
          # inefficient when y is a tensor, but this function only get called once
          y = np.asarray(y)
  
          if len(y.shape) == 1:
              # the user provided categorical encoding
              y = tf.one_hot(y, nb_classes)
  
          y = tf.cast(y, x.dtype)
          return y, nb_classes
  
      # must be an untargeted attack
      labels = tf.cast(
          tf.equal(tf.reduce_max(preds, axis=1, keepdims=True), preds),
          x.dtype,
      )
  
      return labels, nb_classes
  
file_path: cleverhans/cleverhans/tf2/utils.py
imports: import numpy
  import tensorflow
label_desc: Use image node_id 5 for calling a global function with example usage: get_or_guess_labels(model_fn, x, y, targeted) and returns: labels,  nb_classes, y,  nb_classes