コード例 #1
0
def run_movie(flags_obj):
    """Construct all necessary functions and call run_loop.

  Args:
    flags_obj: Object containing user specified flags.
  """

    if flags_obj.download_if_missing:
        movielens.download(dataset=flags_obj.dataset,
                           data_dir=flags_obj.data_dir)

    train_input_fn, eval_input_fn, model_column_fn = \
      movielens_dataset.construct_input_fns(
          dataset=flags_obj.dataset, data_dir=flags_obj.data_dir,
          batch_size=flags_obj.batch_size, repeat=flags_obj.epochs_between_evals)

    tensors_to_log = {'loss': '{loss_prefix}head/weighted_loss/value'}

    wide_deep_run_loop.run_loop(name="MovieLens",
                                train_input_fn=train_input_fn,
                                eval_input_fn=eval_input_fn,
                                model_column_fn=model_column_fn,
                                build_estimator_fn=build_estimator,
                                flags_obj=flags_obj,
                                tensors_to_log=tensors_to_log,
                                early_stop=False)
コード例 #2
0
def run_census(flags_obj):
    """Construct all necessary functions and call run_loop.

  Args:
    flags_obj: Object containing user specified flags.
  """
    if flags_obj.download_if_missing:
        census_dataset.download(flags_obj.data_dir)

    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'
    }

    wide_deep_run_loop.run_loop(
        name="Census Income",
        train_input_fn=train_input_fn,
        eval_input_fn=eval_input_fn,
        model_column_fn=census_dataset.build_model_columns,
        build_estimator_fn=build_estimator,
        flags_obj=flags_obj,
        tensors_to_log=tensors_to_log,
        early_stop=True)