code: def main(unused_argv):
      # Load training and test data.
      x_train, y_train, x_test, y_test = load_cifar10()
  
      # Get model, optimizer and specify loss.
      model = small_cnn()
      optimizer = tf.keras.optimizers.SGD(
          lr=FLAGS.learning_rate, momentum=0.9
      )
      loss = tf.keras.losses.SparseCategoricalCrossentropy(
          from_logits=True
      )
      model.compile(
          optimizer=optimizer, loss=loss, metrics=["accuracy"]
      )
  
      # Get callback for membership inference attack.
      mia_callback = MembershipInferenceCallback(
          (x_train, y_train),
          (x_test, y_test),
          slicing_spec=SlicingSpec(entire_dataset=True, by_class=True),
          attack_types=[
              AttackType.THRESHOLD_ATTACK,
              AttackType.K_NEAREST_NEIGHBORS,
          ],
          tensorboard_dir=FLAGS.model_dir,
          tensorboard_merge_classifiers=FLAGS.tensorboard_merge_classifiers,
          is_logit=True,
          batch_size=2048,
      )
  
      # Train model with Keras
      model.fit(
          x_train,
          y_train,
          epochs=FLAGS.epochs,
          validation_data=(x_test, y_test),
          batch_size=FLAGS.batch_size,
          callbacks=[mia_callback],
          verbose=2,
      )
  
      print("End of training attack:")
      attack_results = run_attack_on_keras_model(
          model,
          (x_train, y_train),
          (x_test, y_test),
          slicing_spec=SlicingSpec(entire_dataset=True, by_class=True),
          attack_types=[
              AttackType.THRESHOLD_ATTACK,
              AttackType.K_NEAREST_NEIGHBORS,
          ],
          is_logit=True,
          batch_size=2048,
      )
      (
          att_types,
          att_slices,
          att_metrics,
          att_values,
      ) = get_flattened_attack_metrics(attack_results)
      print(
          "\n".join(
              [
                  "  %s: %.4f" % (", ".join([s, t, m]), v)
                  for t, s, m, v in zip(
                      att_types, att_slices, att_metrics, att_values
                  )
              ]
          )
      )
  
file_path: privacy/tensorflow_privacy/privacy/privacy_tests/membership_inference_attack/keras_evaluation_example.py
imports: from absl import app
  from absl import flags
  import numpy
  import tensorflow
  from tensorflow_privacy.privacy.privacy_tests.membership_inference_attack.data_structures import AttackType
  from tensorflow_privacy.privacy.privacy_tests.membership_inference_attack.data_structures import get_flattened_attack_metrics
  from tensorflow_privacy.privacy.privacy_tests.membership_inference_attack.data_structures import SlicingSpec
  from tensorflow_privacy.privacy.privacy_tests.membership_inference_attack.keras_evaluation import MembershipInferenceCallback
  from tensorflow_privacy.privacy.privacy_tests.membership_inference_attack.keras_evaluation import run_attack_on_keras_model
label_desc: Use image node_id 3 for calling a global function with example usage: main(unused_argv) without return types