Construct all necessary functions and call run_loop.

  Args:
    flags_obj: Object containing user specified flags.

def run_census(flags_obj, ctx):
  """Construct all necessary functions and call run_loop.

  Args:
    flags_obj: Object containing user specified flags.
  """
  train_file = os.path.join(flags_obj.data_dir, census_dataset.TRAINING_FILE)
  test_file = os.path.join(flags_obj.data_dir, census_dataset.EVAL_FILE)

  # Train and evaluate the model every `flags.epochs_between_evals` epochs.
  def train_input_fn():
    return census_dataset.input_fn(
        train_file, flags_obj.epochs_between_evals, True, flags_obj.batch_size)

  def eval_input_fn():
    return census_dataset.input_fn(test_file, 1, False, flags_obj.batch_size)

  tensors_to_log = {
      'average_loss': '{loss_prefix}head/truediv',
      'loss': '{loss_prefix}head/weighted_loss/Sum'
  }

  # Removing run_loop, since we can only invoke train_and_evaluate once
  model_helpers.apply_clean(flags.FLAGS)
  model = build_estimator(
      model_dir=flags_obj.model_dir, model_type=flags_obj.model_type,
      model_column_fn=census_dataset.build_model_columns,
      inter_op=flags_obj.inter_op_parallelism_threads,
      intra_op=flags_obj.intra_op_parallelism_threads,
      ctx=ctx)

  loss_prefix = LOSS_PREFIX.get(flags_obj.model_type, '')
  tensors_to_log = {k: v.format(loss_prefix=loss_prefix)
                    for k, v in tensors_to_log.items()}
  train_hooks = hooks_helper.get_train_hooks(
      flags_obj.hooks, model_dir=flags_obj.model_dir,
      batch_size=flags_obj.batch_size, tensors_to_log=tensors_to_log)

  # Note: this will only be invoked once, so `--epochs_between_evals` is now effectively `--train_epochs`
  # and evaluation will only execute once.
  train_spec = tf.estimator.TrainSpec(input_fn=train_input_fn, hooks=train_hooks)
  eval_spec = tf.estimator.EvalSpec(input_fn=eval_input_fn)
  tf.estimator.train_and_evaluate(model, train_spec, eval_spec)