code: def train(
      sess,
      loss,
      x,
      y,
      X_train,
      Y_train,
      save=False,
      init_all=False,
      evaluate=None,
      feed=None,
      args=None,
      rng=None,
      var_list=None,
      fprop_args=None,
      optimizer=None,
  ):
      """
      Train a TF graph.
      This function is deprecated. Prefer cleverhans.train.train when possible.
      cleverhans.train.train supports multiple GPUs but this function is still
      needed to support legacy models that do not support calling fprop more
      than once.
  
      :param sess: TF session to use when training the graph
      :param loss: tensor, the model training loss.
      :param x: input placeholder
      :param y: output placeholder (for labels)
      :param X_train: numpy array with training inputs
      :param Y_train: numpy array with training outputs
      :param save: boolean controlling the save operation
      :param init_all: (boolean) If set to true, all TF variables in the session
                       are (re)initialized, otherwise only previously
                       uninitialized variables are initialized before training.
      :param evaluate: function that is run after each training iteration
                       (typically to display the test/validation accuracy).
      :param feed: An optional dictionary that is appended to the feeding
                   dictionary before the session runs. Can be used to feed
                   the learning phase of a Keras model for instance.
      :param args: dict or argparse `Namespace` object.
                   Should contain `nb_epochs`, `learning_rate`,
                   `batch_size`
                   If save is True, should also contain 'train_dir'
                   and 'filename'
      :param rng: Instance of numpy.random.RandomState
      :param var_list: Optional list of parameters to train.
      :param fprop_args: dict, extra arguments to pass to fprop (loss and model).
      :param optimizer: Optimizer to be used for training
      :return: True if model trained
      """
      warnings.warn(
          "This function is deprecated and will be removed on or after"
          " 2019-04-05. Switch to cleverhans.train.train."
      )
  
      args = _ArgsWrapper(args or {})
      fprop_args = fprop_args or {}
  
      # Check that necessary arguments were given (see doc above)
      assert (
          args.nb_epochs
      ), "Number of epochs was not given in args dict"
      if optimizer is None:
          assert args.learning_rate is not None, (
              "Learning rate was not given " "in args dict"
          )
      assert args.batch_size, "Batch size was not given in args dict"
  
      if save:
          assert (
              args.train_dir
          ), "Directory for save was not given in args dict"
          assert (
              args.filename
          ), "Filename for save was not given in args dict"
  
      if rng is None:
          rng = np.random.RandomState()
  
      # Define optimizer
      loss_value = loss.fprop(x, y, **fprop_args)
      if optimizer is None:
          optimizer = tf.train.AdamOptimizer(
              learning_rate=args.learning_rate
          )
      else:
          if not isinstance(optimizer, tf.train.Optimizer):
              raise ValueError(
                  "optimizer object must be from a child class of "
                  "tf.train.Optimizer"
              )
      # Trigger update operations within the default graph (such as batch_norm).
      with tf.control_dependencies(
          tf.get_collection(tf.GraphKeys.UPDATE_OPS)
      ):
          train_step = optimizer.minimize(loss_value, var_list=var_list)
  
      with sess.as_default():
          if hasattr(tf, "global_variables_initializer"):
              if init_all:
                  tf.global_variables_initializer().run()
              else:
                  initialize_uninitialized_global_variables(sess)
          else:
              warnings.warn(
                  "Update your copy of tensorflow; future versions of "
                  "CleverHans may drop support for this version."
              )
              sess.run(tf.initialize_all_variables())
  
          for epoch in xrange(args.nb_epochs):
              # Compute number of batches
              nb_batches = int(
                  math.ceil(float(len(X_train)) / args.batch_size)
              )
              assert nb_batches * args.batch_size >= len(X_train)
  
              # Indices to shuffle training set
              index_shuf = list(range(len(X_train)))
              rng.shuffle(index_shuf)
  
              prev = time.time()
              for batch in range(nb_batches):
                  # Compute batch start and end indices
                  start, end = batch_indices(
                      batch, len(X_train), args.batch_size
                  )
  
                  # Perform one training step
                  feed_dict = {
                      x: X_train[index_shuf[start:end]],
                      y: Y_train[index_shuf[start:end]],
                  }
                  if feed is not None:
                      feed_dict.update(feed)
                  train_step.run(feed_dict=feed_dict)
              assert end >= len(
                  X_train
              )  # Check that all examples were used
              cur = time.time()
              _logger.info(
                  "Epoch "
                  + str(epoch)
                  + " took "
                  + str(cur - prev)
                  + " seconds"
              )
              if evaluate is not None:
                  evaluate()
  
          if save:
              save_path = os.path.join(args.train_dir, args.filename)
              saver = tf.train.Saver()
              saver.save(sess, save_path)
              _logger.info(
                  "Completed model training and saved at: "
                  + str(save_path)
              )
          else:
              _logger.info("Completed model training.")
  
      return True
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from __future__ import unicode_literals
  import logging
  import math
  import os
  import time
  import warnings
  import numpy
  import six
  from six.moves import xrange
  import tensorflow
  from cleverhans.compat import device_lib
  from cleverhans.compat import reduce_sum, reduce_mean
  from cleverhans.compat import reduce_max
  from cleverhans.compat import softmax_cross_entropy_with_logits
  from cleverhans.utils import batch_indices, _ArgsWrapper, create_logger
label_desc: Use image node_id 3 for calling a global function with example usage: train(sess, loss, x, y, X_train, Y_train, save, init_all, evaluate, feed, args, rng, var_list, fprop_args, optimizer) and returns: True