def test_build_graph(self, dataset_name, regression):
   """Test whether build_graph works as expected."""
   data_x, data_y, _ = data_utils.load_dataset(dataset_name)
   data_gen = data_utils.split_training_dataset(
       data_x, data_y, n_splits=5, stratified=not regression)
   (x_train, y_train), (x_validation, y_validation) = next(data_gen)
   sess = tf.InteractiveSession()
   graph_tensors_and_ops, metric_scores = graph_builder.build_graph(
       x_train=x_train,
       y_train=y_train,
       x_test=x_validation,
       y_test=y_validation,
       activation='exu',
       learning_rate=1e-3,
       batch_size=256,
       shallow=True,
       regression=regression,
       output_regularization=0.1,
       dropout=0.1,
       decay_rate=0.999,
       name_scope='model',
       l2_regularization=0.1)
   # Run initializer ops
   sess.run(tf.global_variables_initializer())
   sess.run([
       graph_tensors_and_ops['iterator_initializer'],
       graph_tensors_and_ops['running_vars_initializer']
   ])
   for _ in range(2):
     sess.run(graph_tensors_and_ops['train_op'])
   self.assertIsInstance(metric_scores['train'](sess), float)
   sess.close()
Exemplo n.º 2
0
def _create_computation_graph(
    x_train, y_train, x_validation,
    y_validation, batch_size
):
  """Build the computation graph."""
  graph_tensors_and_ops = []
  metric_scores = []
  for n in range(FLAGS.n_models):
    graph_tensors_and_ops_n, metric_scores_n = graph_builder.build_graph(
        x_train=x_train,
        y_train=y_train,
        x_test=x_validation,
        y_test=y_validation,
        activation=FLAGS.activation,
        learning_rate=FLAGS.learning_rate,
        batch_size=batch_size,
        shallow=FLAGS.shallow,
        output_regularization=FLAGS.output_regularization,
        l2_regularization=FLAGS.l2_regularization,
        dropout=FLAGS.dropout,
        num_basis_functions=FLAGS.num_basis_functions,
        units_multiplier=FLAGS.units_multiplier,
        decay_rate=FLAGS.decay_rate,
        feature_dropout=FLAGS.feature_dropout,
        regression=FLAGS.regression,
        use_dnn=FLAGS.use_dnn,
        trainable=True,
        name_scope=f'model_{n}')
    graph_tensors_and_ops.append(graph_tensors_and_ops_n)
    metric_scores.append(metric_scores_n)
  return graph_tensors_and_ops, metric_scores