Exemplo n.º 1
0
def generate_experiment_fn(output_dir, hparams):
    get_train = model.read_dataset(hparams['train_data_paths'],
                                   tf.estimator.ModeKeys.TRAIN,
                                   hparams['train_batch_size'])
    get_valid = model.read_dataset(hparams['eval_data_paths'],
                                   tf.estimator.ModeKeys.EVAL,
                                   1000)

    estimator = create_custom_estimator(output_dir, hparams)

    train_spec = tf.estimator.TrainSpec(input_fn=get_train, max_steps=hparams['train_steps'])
    exporter = tf.estimator.LatestExporter('exporter', model.serving_input_fn)
    eval_spec = tf.estimator.EvalSpec(input_fn=get_valid,
                                      steps=1000,
                                      start_delay_secs=1,  # start evaluating after N seconds
                                      throttle_secs=10,  # evaluate every N seconds
                                      exporters=exporter)
    return tf.estimator.train_and_evaluate(estimator=estimator, train_spec=train_spec, eval_spec=eval_spec)
 def experiment_fn(output_dir):
    get_train = model.read_dataset(train_data_paths, mode=tf.contrib.learn.ModeKeys.TRAIN)
    get_valid = model.read_dataset(eval_data_paths, mode=tf.contrib.learn.ModeKeys.EVAL)
    # run experiment
    return tflearn.Experiment(
        tflearn.Estimator(model_fn=model.simple_rnn, model_dir=output_dir),
        train_input_fn=get_train,
        eval_input_fn=get_valid,
        eval_metrics={
            'rmse': tflearn.MetricSpec(
                metric_fn=tf.contrib.metrics.streaming_root_mean_squared_error
            )
        },
        export_strategies=[saved_model_export_utils.make_export_strategy(
            model.serving_input_fn,
            default_output_alternative_key=None,
            exports_to_keep=1
        )],
        **experiment_args
    )
Exemplo n.º 3
0
    def experiment_fn(output_dir):
        get_train = model.read_dataset(hparams['train_data_paths'],
                                       tf.estimator.ModeKeys.TRAIN,
                                       hparams['train_batch_size'])
        get_valid = model.read_dataset(hparams['eval_data_paths'],
                                       tf.estimator.ModeKeys.EVAL, 1000)
        eval_freq = max(1, min(2000, hparams['train_steps'] / 5))

        return tf.contrib.learn.Experiment(
            estimator=create_custom_estimator(output_dir, hparams),
            train_input_fn=get_train,
            eval_input_fn=get_valid,
            train_steps=hparams['train_steps'],
            eval_steps=1,
            min_eval_frequency=eval_freq,
            export_strategies=[
                saved_model_export_utils.make_export_strategy(
                    model.serving_input_fn,
                    default_output_alternative_key=None,
                    exports_to_keep=1)
            ])
Exemplo n.º 4
0
 def experiment_fn(output_dir):
     get_train = model.read_dataset(train_data_paths,
                                    mode=tf.contrib.learn.ModeKeys.TRAIN)
     get_valid = model.read_dataset(eval_data_paths,
                                    mode=tf.contrib.learn.ModeKeys.EVAL)
     # run experiment
     return tflearn.Experiment(
         tflearn.Estimator(model_fn=model.simple_rnn, model_dir=output_dir),
         train_input_fn=get_train,
         eval_input_fn=get_valid,
         eval_metrics={
             'rmse':
             tflearn.MetricSpec(metric_fn=tf.contrib.metrics.
                                streaming_root_mean_squared_error)
         },
         export_strategies=[
             saved_model_export_utils.make_export_strategy(
                 model.serving_input_fn,
                 default_output_alternative_key=None,
                 exports_to_keep=1)
         ],
         **experiment_args)
Exemplo n.º 5
0
 def experiment_fn(output_dir):
    get_train = model.read_dataset(hparams['train_data_paths'],
                                   tf.estimator.ModeKeys.TRAIN,
                                   hparams['train_batch_size'])
    get_valid = model.read_dataset(hparams['eval_data_paths'],
                                   tf.estimator.ModeKeys.EVAL,
                                   1000)
    eval_freq = max(1, min(2000, hparams['train_steps']/5))

    return tf.contrib.learn.Experiment(
        estimator=create_custom_estimator(output_dir, hparams),
        train_input_fn=get_train,
        eval_input_fn=get_valid,
        train_steps=hparams['train_steps'],
        eval_steps=1,
        min_eval_frequency=eval_freq,
        export_strategies=[saved_model_export_utils.make_export_strategy(
            model.serving_input_fn,
            default_output_alternative_key=None,
            exports_to_keep=1
        )]
    )
Exemplo n.º 6
0
            FIELD_DEFAULTS.append(["NA"])
        else:
            FIELD_DEFAULTS.append([0.0])

    # run
    tf.logging.set_verbosity(tf.logging.INFO)
    # create estimator
    feature_columns, estimator = model.build_model(
        COLUMNS, LABEL_FIELD, FIELD_TYPES, FIELD_CATEGORIES, output_dir,
        LEARNING_RATE, L1_NORM, L2_NORM, FEATURE_COLUMN_NUM_BUCKETS, MINS,
        MAXS)

    train_spec = tf.estimator.TrainSpec(input_fn=model.read_dataset(
        MODEL_DIR,
        FIELD_DEFAULTS,
        COLUMNS,
        LABEL_FIELD,
        BATCH_SIZE=arguments['BATCH_SIZE'],
        TRAIN_STEPS=arguments['TRAIN_STEPS'],
        mode=tf.estimator.ModeKeys.TRAIN),
                                        max_steps=arguments['TRAIN_STEPS'])

    eval_spec = tf.estimator.EvalSpec(
        input_fn=model.read_dataset(
            MODEL_DIR,
            FIELD_DEFAULTS,
            COLUMNS,
            LABEL_FIELD,
            BATCH_SIZE=
            300,  #arguments['BATCH_SIZE'], # 300 should guarantee the full eval set coverage
            TRAIN_STEPS=arguments['TRAIN_STEPS'],
            mode=tf.estimator.ModeKeys.EVAL),
Exemplo n.º 7
0
        elif (FIELD_TYPES[c] == "string"):
            FIELD_DEFAULTS.append(["NA"])
        else:
            FIELD_DEFAULTS.append([0.0])

    # run
    tf.logging.set_verbosity(tf.logging.INFO)
    # create estimator
    feature_columns, estimator = model.build_model(
        COLUMNS, LABEL_FIELD, FIELD_TYPES, FIELD_CATEGORIES, output_dir,
        LEARNING_RATE, L1_NORM, L2_NORM, EMBEDDING_COLUMNS_SIZE, HIDDEN_UNITS)

    train_spec = tf.estimator.TrainSpec(input_fn=model.read_dataset(
        MODEL_DIR,
        FIELD_DEFAULTS,
        COLUMNS,
        LABEL_FIELD,
        BATCH_SIZE=arguments['BATCH_SIZE'],
        TRAIN_STEPS=arguments['TRAIN_STEPS'],
        mode=tf.estimator.ModeKeys.TRAIN),
                                        max_steps=arguments['TRAIN_STEPS'])

    eval_spec = tf.estimator.EvalSpec(
        input_fn=model.read_dataset(MODEL_DIR,
                                    FIELD_DEFAULTS,
                                    COLUMNS,
                                    LABEL_FIELD,
                                    BATCH_SIZE=arguments['BATCH_SIZE'],
                                    TRAIN_STEPS=arguments['TRAIN_STEPS'],
                                    mode=tf.estimator.ModeKeys.EVAL),
        start_delay_secs=2 * 60,  #20 * 60, # start evaluating after N seconds
        throttle_secs=1 * 60)  #10 * 60)    # evaluate every N seconds
Exemplo n.º 8
0
                                                          {}).get('trial', ''))

    # run
    tf.logging.set_verbosity(tf.logging.INFO)
    # create estimator
    estimator = model.wide_and_deep_model(output_dir, arguments['origin_file'],
                                          arguments['dest_file'],
                                          arguments['nbuckets'],
                                          arguments['hidden_units'],
                                          arguments['learning_rate'])

    estimator = tf.contrib.estimator.add_metrics(estimator, model.my_rmse)

    train_spec = tf.estimator.TrainSpec(input_fn=model.read_dataset(
        arguments['traindata'],
        mode=tf.estimator.ModeKeys.TRAIN,
        batch_size=arguments['batch_size'],
        num_training_epochs=arguments['num_training_epochs']))

    eval_spec = tf.estimator.EvalSpec(
        input_fn=model.read_dataset(arguments['evaldata']),
        steps=None,
        start_delay_secs=20 * 60,  # start evaluating after N seconds
        throttle_secs=10 * 60)  # evaluate every N seconds

    tf.estimator.train_and_evaluate(estimator, train_spec, eval_spec)

    estimator.export_savedmodel(
        os.path.join(output_dir, 'Servo'),
        serving_input_receiver_fn=model.serving_input_fn())