code: def train(args):
      np.random.seed(42)
      tf.set_random_seed(42)
  
      print("Setting up...")
  
      # Parse csv files for file names
      all_filenames = pd.read_csv(
          args.data_csv,
          dtype=object,
          keep_default_na=False,
          na_values=[],
      ).as_matrix()
  
      train_filenames = all_filenames[:100]
      val_filenames = all_filenames[100:]
  
      # Set up a data reader to handle the file i/o.
      reader_params = {
          "n_examples": 10,
          "example_size": [1, 224, 224],
          "extract_examples": True,
      }
      reader_example_shapes = {
          "features": {
              "x": reader_params["example_size"]
              + [
                  NUM_CHANNELS,
              ]
          }
      }
      reader = Reader(read_fn, {"features": {"x": tf.float32}})
  
      # Get input functions and queue initialisation hooks for training and
      # validation data
      train_input_fn, train_qinit_hook = reader.get_inputs(
          file_references=train_filenames,
          mode=tf.estimator.ModeKeys.TRAIN,
          example_shapes=reader_example_shapes,
          batch_size=BATCH_SIZE,
          shuffle_cache_size=SHUFFLE_CACHE_SIZE,
          params=reader_params,
      )
  
      val_input_fn, val_qinit_hook = reader.get_inputs(
          file_references=val_filenames,
          mode=tf.estimator.ModeKeys.EVAL,
          example_shapes=reader_example_shapes,
          batch_size=BATCH_SIZE,
          shuffle_cache_size=SHUFFLE_CACHE_SIZE,
          params=reader_params,
      )
  
      # Instantiate the neural network estimator
      nn = tf.estimator.Estimator(
          model_fn=model_fn,
          model_dir=args.model_path,
          params={"learning_rate": 0.01},
          config=tf.estimator.RunConfig(),
      )
  
      # Hooks for validation summaries
      val_summary_hook = tf.contrib.training.SummaryAtEndHook(
          os.path.join(args.model_path, "eval")
      )
      step_cnt_hook = tf.train.StepCounterHook(
          every_n_steps=EVAL_EVERY_N_STEPS, output_dir=args.model_path
      )
  
      print("Starting training...")
      try:
          for _ in range(MAX_STEPS // EVAL_EVERY_N_STEPS):
              nn.train(
                  input_fn=train_input_fn,
                  hooks=[train_qinit_hook, step_cnt_hook],
                  steps=EVAL_EVERY_N_STEPS,
              )
  
              if args.run_validation:
                  results_val = nn.evaluate(
                      input_fn=val_input_fn,
                      hooks=[val_qinit_hook, val_summary_hook],
                      steps=EVAL_STEPS,
                  )
  
                  print(
                      "Step = {}; val loss = {:.5f};".format(
                          results_val["global_step"],
                          results_val["loss"],
                      )
                  )
  
      except KeyboardInterrupt:
          pass
  
      print("Stopping now.")
      export_dir = nn.export_savedmodel(
          export_dir_base=args.model_path,
          serving_input_receiver_fn=reader.serving_input_receiver_fn(
              reader_example_shapes
          ),
      )
      print("Model saved to {}.".format(export_dir))
  
file_path: DLTK/examples/applications/IXI_HH_representation_learning_cae/train.py
imports: from __future__ import unicode_literals
  from __future__ import print_function
  from __future__ import division
  from __future__ import absolute_import
  import argparse
  import os
  import pandas
  import tensorflow
  import numpy
  from dltk.networks.autoencoder.convolutional_autoencoder import convolutional_autoencoder_3d
  from dltk.io.abstract_reader import Reader
  from reader import read_fn
label_desc: Use image node_id 2 for calling a global function with example usage: train(args) without return types