code: def evaluate_robustness(model_to_attack, dataset, models, hparams):
      """Evaluates the robustness of `models` with adversarially-perturbed input.
  
      Args:
        model_to_attack: `tf.keras.Model`. Perturbations will be generated based
          on this model's weights.
        dataset: Dataset to be perturbed.
        models: Dictionary of model names and `tf.keras.Model` to be evaluated.
        hparams: Hyper-parameters for generating adversarial examples.
  
      Returns:
        A dictionary of model names and accuracy of the model on adversarially
        perturbed input, i.e. robustness.
      """
      if not isinstance(
          model_to_attack, nsl.keras.AdversarialRegularization
      ):
          # Enables AdversarialRegularization-specific API for the model_to_attack.
          # This won't change the model's weights.
          model_to_attack = apply_adversarial_regularization(
              model_to_attack, hparams
          )
          model_to_attack.compile(
              optimizer="adam",
              loss="sparse_categorical_crossentropy",
              metrics=["accuracy"],
          )
  
      metrics = {
          name: tf.keras.metrics.SparseCategoricalAccuracy()
          for name in models.keys()
      }
  
      if hparams.eval_steps:
          dataset = dataset.take(hparams.eval_steps)
      # When running on accelerators, looping over the dataset inside a tf.function
      # may be much faster.
      for batch in dataset:
          adv_batch = model_to_attack.perturb_on_batch(batch)
          # Clips the perturbed values to 0~1, the same as normalized values after
          # preprocessing.
          adv_batch[FEATURE_INPUT_NAME] = tf.clip_by_value(
              adv_batch[FEATURE_INPUT_NAME], 0.0, 1.0
          )
          y_true = adv_batch.pop(LABEL_INPUT_NAME)
          for name, model in models.items():
              y_pred = model(adv_batch)
              metrics[name](y_true, y_pred)
  
      return {
          name: metric.result().numpy()
          for name, metric in metrics.items()
      }
  
file_path: neural-structured-learning/neural_structured_learning/examples/adv_keras_cnn_mnist.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from absl import app
  from absl import flags
  import attr
  import neural_structured_learning
  import tensorflow
label_desc: Use image node_id 8 for calling a global function with example usage: evaluate_robustness(model_to_attack, dataset, models, hparams) and returns: unknown