Exemplo n.º 1
0
 def testIrisDNN(self):
   iris = base.load_iris()
   feature_columns = [feature_column.real_valued_column("", dimension=4)]
   classifier = dnn.DNNClassifier(
       feature_columns=feature_columns,
       hidden_units=[10, 20, 10],
       n_classes=3,
       config=run_config.RunConfig(tf_random_seed=1))
   classifier.fit(iris.data, iris.target, max_steps=200)
   variable_names = classifier.get_variable_names()
   self.assertEqual(
       classifier.get_variable_value("dnn/hiddenlayer_0/weights").shape,
       (4, 10))
   self.assertEqual(
       classifier.get_variable_value("dnn/hiddenlayer_1/weights").shape,
       (10, 20))
   self.assertEqual(
       classifier.get_variable_value("dnn/hiddenlayer_2/weights").shape,
       (20, 10))
   self.assertEqual(
       classifier.get_variable_value("dnn/logits/weights").shape, (10, 3))
   self.assertIn("dnn/hiddenlayer_0/biases", variable_names)
   self.assertIn("dnn/hiddenlayer_1/biases", variable_names)
   self.assertIn("dnn/hiddenlayer_2/biases", variable_names)
   self.assertIn("dnn/logits/biases", variable_names)
Exemplo n.º 2
0
  def test_checkpoint_and_export(self):
    model_dir = tempfile.mkdtemp()
    config = run_config_lib.RunConfig(save_checkpoints_steps=3)
    est = dnn.DNNClassifier(
        n_classes=3,
        feature_columns=[
            feature_column.real_valued_column('feature', dimension=4)
        ],
        hidden_units=[3, 3],
        model_dir=model_dir,
        config=config)

    exp_strategy = saved_model_export_utils.make_export_strategy(
        est, 'export_input', exports_to_keep=None)

    ex = experiment.Experiment(
        est,
        train_input_fn=test_data.iris_input_multiclass_fn,
        eval_input_fn=test_data.iris_input_multiclass_fn,
        export_strategies=(exp_strategy,),
        train_steps=8,
        checkpoint_and_export=True,
        eval_delay_secs=0)

    with test.mock.patch.object(ex, '_maybe_export'):
      with test.mock.patch.object(ex, '_call_evaluate'):
        ex.train_and_evaluate()
        # Eval and export are called after steps 1, 4, 7, and 8 (after training
        # is completed).
        self.assertEqual(ex._maybe_export.call_count, 4)
        self.assertEqual(ex._call_evaluate.call_count, 4)
Exemplo n.º 3
0
 def testDNNDropout0(self):
   # Dropout prob == 0.
   iris = base.load_iris()
   feature_columns = [feature_column.real_valued_column("", dimension=4)]
   classifier = dnn.DNNClassifier(
       feature_columns=feature_columns,
       hidden_units=[10, 20, 10],
       n_classes=3,
       dropout=0.0,
       config=run_config.RunConfig(tf_random_seed=1))
   classifier.fit(iris.data, iris.target, max_steps=200)