code: #!/usr/bin/env python
  
  
  """"
  Script to evaluate a trained DRAW network.
  
  Example Usage:
      python test.py --data_dir=/tmp/draw --model_dir=./out --read_attn=soft_attn --write_attn=soft_attn
  """
  
  import tensorflow as tf
  from tensorflow.examples.tutorials import mnist
  import numpy as np
  import os
  from attention.no_attn import ReadNoAttn, WriteNoAttn
  from attention.soft_attn import ReadSoftAttn, WriteSoftAttn
  from attention.spatial_transformer_attn import ReadSpatialTransformerAttn, WriteSpatialTransformerAttn
  import data_loader
  import draw
  
  tf.flags.DEFINE_string("data_dir", "", "")
  tf.flags.DEFINE_string("model_dir", "", "")
  tf.flags.DEFINE_string("write_attn", "no_attn", "Specify type of write attention " +
      "to use. Options include: 'no_attn', 'soft_attn', 'spatial_transformer_attn'.")
  tf.flags.DEFINE_string("dataset", "mnist", "Dataset to train the model with." +
      " Options include: 'mnist', 'svhn'")
  
  FLAGS = tf.flags.FLAGS
  
  ## GENERATIVE PARAMETERS ##
  batch_size = 100
  
  # Select dataset:
  if FLAGS.dataset == 'mnist':
      dimensions = (batch_size,) + data_loader.MNISTLoader.dimensions
  elif FLAGS.dataset == 'svhn':
      dimensions = (batch_size,) + data_loader.SVHNLoader.dimensions
  else:
      print("dataset parameter was not recognized. Defaulting to 'mnist'.")
      dimensions = (batch_size,) + data_loader.MNISTLoader.dimensions
  
  ## CREATE MODEL ##
  model = draw.DRAWGenerativeModel(FLAGS.write_attn, dimensions)
  
  ## Generate Images ##
  with tf.Session() as sess:
      # Restore trained model from checkpoint
      ckpt_file = os.path.join(FLAGS.model_dir, "draw_model.ckpt")
      model.restore_from_ckpt(sess, ckpt_file)
  
      canvases, w_params = model.generate_images(sess)
  
      canvases = np.array(canvases) # T x B x H x W x C
      w_params = np.array(w_params) # T x B x num_w_params
  
      out_file = os.path.join(FLAGS.model_dir, "draw_generated_images.npz")
      np.savez(out_file, img=canvases, w_params=w_params)
      print("Images saved in file: %s" % out_file)
  
apis: tensorflow.flags.DEFINE_string numpy.array tensorflow.Session numpy.savez
api_extract: [(21, 'tensorflow.flags.DEFINE_string', 'tf.flags.DEFINE_string', (['"""data_dir"""', '""""""', '""""""'], {}), True, 'import tensorflow as tf\n'), (22, 'tensorflow.flags.DEFINE_string', 'tf.flags.DEFINE_string', (['"""model_dir"""', '""""""', '""""""'], {}), True, 'import tensorflow as tf\n'), (23, 'tensorflow.flags.DEFINE_string', 'tf.flags.DEFINE_string', (['"""write_attn"""', '"""no_attn"""', '(\'Specify type of write attention \' +\n    "to use. Options include: \'no_attn\', \'soft_attn\', \'spatial_transformer_attn\'."\n    )'], {}), True, 'import tensorflow as tf\n'), (25, 'tensorflow.flags.DEFINE_string', 'tf.flags.DEFINE_string', (['"""dataset"""', '"""mnist"""', '(\'Dataset to train the model with.\' + " Options include: \'mnist\', \'svhn\'")'], {}), True, 'import tensorflow as tf\n'), (43, 'draw.DRAWGenerativeModel', 'draw.DRAWGenerativeModel', (['FLAGS.write_attn', 'dimensions'], {}), False, 'import draw\n'), (46, 'tensorflow.Session', 'tf.Session', ([], {}), True, 'import tensorflow as tf\n'), (48, 'os.path.join', 'os.path.join', (['FLAGS.model_dir', '"""draw_model.ckpt"""'], {}), False, 'import os\n'), (53, 'numpy.array', 'np.array', (['canvases'], {}), True, 'import numpy as np\n'), (54, 'numpy.array', 'np.array', (['w_params'], {}), True, 'import numpy as np\n'), (56, 'os.path.join', 'os.path.join', (['FLAGS.model_dir', '"""draw_generated_images.npz"""'], {}), False, 'import os\n'), (57, 'numpy.savez', 'np.savez', (['out_file'], {'img': 'canvases', 'w_params': 'w_params'}), True, 'import numpy as np\n')]