code: def prepare_student_data(dataset, nb_teachers, save=False):
      """
      Takes a dataset name and the size of the teacher ensemble and prepares
      training data for the student model, according to parameters indicated
      in flags above.
      :param dataset: string corresponding to mnist, cifar10, or svhn
      :param nb_teachers: number of teachers (in the ensemble) to learn from
      :param save: if set to True, will dump student training labels predicted by
                   the ensemble of teachers (with Laplacian noise) as npy files.
                   It also dumps the clean votes for each class (without noise) and
                   the labels assigned by teachers
      :return: pairs of (data, labels) to be used for student training and testing
      """
      assert input.create_dir_if_needed(FLAGS.train_dir)
  
      # Load the dataset
      if dataset == "svhn":
          test_data, test_labels = input.ld_svhn(test_only=True)
      elif dataset == "cifar10":
          test_data, test_labels = input.ld_cifar10(test_only=True)
      elif dataset == "mnist":
          test_data, test_labels = input.ld_mnist(test_only=True)
      else:
          print("Check value of dataset flag")
          return False
  
      # Make sure there is data leftover to be used as a test set
      assert FLAGS.stdnt_share < len(test_data)
  
      # Prepare [unlabeled] student training data (subset of test set)
      stdnt_data = test_data[: FLAGS.stdnt_share]
  
      # Compute teacher predictions for student training data
      teachers_preds = ensemble_preds(dataset, nb_teachers, stdnt_data)
  
      # Aggregate teacher predictions to get student training labels
      if not save:
          stdnt_labels = aggregation.noisy_max(
              teachers_preds, FLAGS.lap_scale
          )
      else:
          # Request clean votes and clean labels as well
          (
              stdnt_labels,
              clean_votes,
              labels_for_dump,
          ) = aggregation.noisy_max(
              teachers_preds, FLAGS.lap_scale, return_clean_votes=True
          )  # NOLINT(long-line)
  
          # Prepare filepath for numpy dump of clean votes
          filepath = (
              FLAGS.data_dir
              + "/"
              + str(dataset)
              + "_"
              + str(nb_teachers)
              + "_student_clean_votes_lap_"
              + str(FLAGS.lap_scale)
              + ".npy"
          )  # NOLINT(long-line)
  
          # Prepare filepath for numpy dump of clean labels
          filepath_labels = (
              FLAGS.data_dir
              + "/"
              + str(dataset)
              + "_"
              + str(nb_teachers)
              + "_teachers_labels_lap_"
              + str(FLAGS.lap_scale)
              + ".npy"
          )  # NOLINT(long-line)
  
          # Dump clean_votes array
          with tf.gfile.Open(filepath, mode="w") as file_obj:
              np.save(file_obj, clean_votes)
  
          # Dump labels_for_dump array
          with tf.gfile.Open(filepath_labels, mode="w") as file_obj:
              np.save(file_obj, labels_for_dump)
  
      # Print accuracy of aggregated labels
      ac_ag_labels = metrics.accuracy(
          stdnt_labels, test_labels[: FLAGS.stdnt_share]
      )
      print("Accuracy of the aggregated labels: " + str(ac_ag_labels))
  
      # Store unused part of test set for use as a test set after student training
      stdnt_test_data = test_data[FLAGS.stdnt_share :]
      stdnt_test_labels = test_labels[FLAGS.stdnt_share :]
  
      if save:
          # Prepare filepath for numpy dump of labels produced by noisy aggregation
          filepath = (
              FLAGS.data_dir
              + "/"
              + str(dataset)
              + "_"
              + str(nb_teachers)
              + "_student_labels_lap_"
              + str(FLAGS.lap_scale)
              + ".npy"
          )  # NOLINT(long-line)
  
          # Dump student noisy labels array
          with tf.gfile.Open(filepath, mode="w") as file_obj:
              np.save(file_obj, stdnt_labels)
  
      return (
          stdnt_data,
          stdnt_labels,
          stdnt_test_data,
          stdnt_test_labels,
      )
  
file_path: privacy/research/pate_2017/train_student.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import aggregation
  import deep_cnn
  import input
  import metrics
  import numpy
  from six.moves import xrange
  import tensorflow.compat.v1
label_desc: Use image node_id 2 for calling a global function with example usage: prepare_student_data(dataset, nb_teachers, save) and returns: stdnt_data,  stdnt_labels,  stdnt_test_data,  stdnt_test_labels, False