text: #!/usr/bin/python
  # import tensorflow as tf
  import tensorflow.compat.v1 as tf
  from config import Config
  from model import QuestionAnswerer
  from dataset import prepare_train_data, prepare_eval_data, prepare_test_data
  
  FLAGS = tf.app.flags.FLAGS
  
  tf.flags.DEFINE_string('phase', 'train',
                         'The phase can be train, eval or test')
  
  tf.flags.DEFINE_boolean('load', False,
                          'Turn on to load a pretrained model from either \
                          the latest checkpoint or a specified file')
  
  tf.flags.DEFINE_string('model_file', None,
                         'If sepcified, load a pretrained model from this file')
  
  tf.flags.DEFINE_boolean('load_cnn', False,
                          'Turn on to load a pretrained CNN model')
  
  tf.flags.DEFINE_string('cnn_model_file', './vgg16_no_fc.npy',
                         'File containing a pretrained CNN model')
  
  tf.flags.DEFINE_boolean('train_cnn', False,
                          'Turn on to train both CNN and RNN. \
                           Otherwise, only RNN is trained')
  
  def main(argv):
      config = Config()
      config.phase = FLAGS.phase
      config.train_cnn = FLAGS.train_cnn
  
      with tf.Session() as sess:
          if FLAGS.phase == 'train':
              # training phase
              data, config = prepare_train_data(config)
              model = QuestionAnswerer(config)
              sess.run(tf.global_variables_initializer())
              if FLAGS.load:
                  model.load(sess, FLAGS.model_file)
              if FLAGS.load_cnn:
                  model.load_cnn(sess, FLAGS.cnn_model_file)
              tf.get_default_graph().finalize()
              model.train(sess, data)
  
          elif FLAGS.phase == 'eval':
              # evaluation phase
              vqa, data, vocabulary, config = prepare_eval_data(config)
              model = QuestionAnswerer(config)
              model.load(sess, FLAGS.model_file)
              tf.get_default_graph().finalize()
              model.eval(sess, vqa, data, vocabulary)
  
          else:
              # testing phase
              data, vocabulary, config = prepare_test_data(config)
              model = QuestionAnswerer(config)
              model.load(sess, FLAGS.model_file)
              tf.get_default_graph().finalize()
              model.test(sess, data, vocabulary)
  
  if __name__ == '__main__':
      tf.app.run()
  