Example #1
0
 def _experiment_fn(run_config, hparams):
     # num_epochs can control duration if train_steps isn't
     # passed to Experiment
     train_input = lambda: model.generate_input_fn(
         hparams.train_files,
         num_epochs=hparams.num_epochs,
         batch_size=hparams.train_batch_size,
     )
     # Don't shuffle evaluation data
     eval_input = lambda: model.generate_input_fn(hparams.eval_files,
                                                  batch_size=hparams.
                                                  eval_batch_size,
                                                  shuffle=False)
     return tf.contrib.learn.Experiment(
         model.build_estimator(
             embedding_size=hparams.embedding_size,
             # Construct layers sizes with exponetial decay
             hidden_units=[
                 max(
                     2,
                     int(hparams.first_layer_size *
                         hparams.scale_factor**i))
                 for i in range(hparams.num_layers)
             ],
             config=run_config),
         train_input_fn=train_input,
         eval_input_fn=eval_input,
         **experiment_args)
Example #2
0
 def _experiment_fn(output_dir):
     # num_epochs can control duration if train_steps isn't
     # passed to Experiment
     train_input = model.generate_input_fn(
         train_files,
         num_epochs=num_epochs,
         batch_size=train_batch_size,
     )
     # Don't shuffle evaluation data
     eval_input = model.generate_input_fn(eval_files,
                                          batch_size=eval_batch_size,
                                          shuffle=False)
     return tf.contrib.learn.Experiment(
         model.build_estimator(
             output_dir,
             # Construct layers sizes with exponetial decay
             hidden_units=[
                 max(2, int(first_layer_size * scale_factor**i))
                 for i in range(num_layers)
             ]),
         train_input_fn=train_input,
         eval_input_fn=eval_input,
         # export strategies control the prediction graph structure
         # of exported binaries.
         export_strategies=[
             saved_model_export_utils.make_export_strategy(
                 model.serving_input_fn,
                 default_output_alternative_key=None,
                 exports_to_keep=1)
         ],
         **experiment_args)
Example #3
0
def run_experiment(hparams):
    # Create training and eval input functions
    train_input = lambda: model.generate_input_fn(
        args.train_files,
        num_epochs=hparams.num_epochs,
        batch_size=hparams.train_batch_size,
    )
    # Don't shuffle evaluation data
    eval_input = lambda: model.generate_input_fn(
        args.eval_files, batch_size=hparams.eval_batch_size, shuffle=False)

    # Define TrainSpec and EvalSpec instances

    # Define exporters for Eval Spec
    exporters = []
    exporters.append(
        tf.estimator.FinalExporter('mnist', model.example_serving_input_fn))

    eval_spec = tf.estimator.EvalSpec(eval_input,
                                      steps=hparams.eval_steps,
                                      exporters=exporters,
                                      throttle_secs=60)

    train_spec = tf.estimator.TrainSpec(train_input,
                                        max_steps=hparams.max_steps)

    # Create estimator
    estimator = tf.estimator.Estimator(model.generate_model_fn(hparams),
                                       config=tf.estimator.RunConfig(
                                           model_dir=hparams.job_dir, ))

    tf.estimator.train_and_evaluate(estimator, train_spec, eval_spec)
Example #4
0
 def _experiment_fn(run_config, hparams):
   # num_epochs can control duration if train_steps isn't
   # passed to Experiment
   train_input = lambda: model.generate_input_fn(
       hparams.train_files,
       num_epochs=hparams.num_epochs,
       batch_size=hparams.train_batch_size,
   )
   # Don't shuffle evaluation data
   eval_input = lambda: model.generate_input_fn(
       hparams.eval_files,
       batch_size=hparams.eval_batch_size,
       shuffle=False
   )
   return tf.contrib.learn.Experiment(
       tf.estimator.Estimator(
           model.generate_model_fn(
               embedding_size=hparams.embedding_size,
               # Construct layers sizes with exponetial decay
               hidden_units=[
                   max(2, int(hparams.first_layer_size *
                              hparams.scale_factor**i))
                   for i in range(hparams.num_layers)
               ],
               learning_rate=hparams.learning_rate
           ),
           config=run_config
       ),
       train_input_fn=train_input,
       eval_input_fn=eval_input,
       **experiment_args
   )
Example #5
0
 def _experiment_fn(run_config, hparams):
     # num_epochs can control duration if train_steps isn't
     # passed to Experiment
     train_input = lambda: model.generate_input_fn()
     # Don't shuffle evaluation data
     eval_input = lambda: model.generate_input_fn(shuffle=False)
     return tf.contrib.learn.Experiment(
         model.build_estimator(config=run_config),
         train_input_fn=train_input,
         eval_input_fn=eval_input,
         **experiment_args)
Example #6
0
 def _experiment_fn(output_dir):
     train_input = model.generate_input_fn(train_file,
                                           num_epochs=num_epochs,
                                           batch_size=train_batch_size)
     eval_input = model.generate_input_fn(eval_file,
                                          batch_size=eval_batch_size)
     return Experiment(model.build_estimator(job_dir,
                                             embedding_size=embedding_size,
                                             hidden_units=hidden_units),
                       train_input_fn=train_input,
                       eval_input_fn=eval_input,
                       export_strategies=[
                           saved_model_export_utils.make_export_strategy(
                               model.serving_input_fn,
                               default_output_alternative_key=None,
                               exports_to_keep=1)
                       ],
                       **experiment_args)
Example #7
0
 def _experiment_fn(run_config, hparams):
     """Definicion de experimento"""
     # Funcion de entrada de entrenamiento
     train_input = lambda: model.generate_input_fn(
         hparams.train_files,
         num_epochs=hparams.num_epochs,
         batch_size=hparams.train_batch_size,
     )
     # Funcion de entrada de evaluacion
     eval_input = lambda: model.generate_input_fn(
         hparams.eval_files,
         batch_size=hparams.eval_batch_size
     )
     # Experimento
     return tf.contrib.learn.Experiment(
         model.build_estimator(hparams.job_dir),
         train_input_fn=train_input,
         eval_input_fn=eval_input,
         **experiment_args
     )
Example #8
0
 def _experiment_fn(run_config, hparams):
     # num_epochs can control duration if train_steps isn't
     # passed to Experiment
     train_input = lambda: model.generate_input_fn(
         [
             os.path.join(os.environ['PIPELINE_INPUT_PATH'], train_file)
             for train_file in hparams.train_files
         ],
         num_epochs=hparams.num_epochs,
         batch_size=hparams.train_batch_size,
     )
     # Don't shuffle evaluation data
     eval_input = lambda: model.generate_input_fn([
         os.path.join(os.environ['PIPELINE_INPUT_PATH'], eval_file)
         for eval_file in hparams.eval_files
     ],
                                                  batch_size=hparams.
                                                  eval_batch_size,
                                                  shuffle=False)
     return tf.contrib.learn.Experiment(
         tf.estimator.Estimator(
             model.generate_model_fn(
                 embedding_size=hparams.embedding_size,
                 # Construct layers sizes with exponential decay
                 hidden_units=[
                     max(
                         2,
                         int(hparams.first_layer_size *
                             hparams.scale_factor**i))
                     for i in range(hparams.num_layers)
                 ],
                 learning_rate=hparams.learning_rate),
             config=run_config),
         train_input_fn=train_input,
         eval_input_fn=eval_input,
         #       export_fn
         #        checkpoint_and_export=True,
         **experiment_args)
Example #9
0
 def _experiment_fn(output_dir):
     train_input = model.generate_input_fn(train_file,
                                           num_epochs=num_epochs,
                                           batch_size=train_batch_size)
     eval_input = model.generate_input_fn(eval_file,
                                          batch_size=eval_batch_size)
     return learn.Experiment(
         model.build_estimator(job_dir,
                               embedding_size=embedding_size,
                               hidden_units=hidden_units),
         train_input_fn=train_input,
         eval_input_fn=eval_input,
         eval_metrics={
             'training/hptuning/metric':
             learn.MetricSpec(metric_fn=metrics.streaming_accuracy,
                              prediction_key='logits')
         },
         export_strategies=[
             saved_model_export_utils.make_export_strategy(
                 model.serving_input_fn,
                 default_output_alternative_key=None,
                 exports_to_keep=1)
         ],
         **experiment_args)