aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/contrib/estimator
diff options
context:
space:
mode:
authorGravatar Goutham Bhat <goutham@google.com>2018-07-23 14:30:36 -0700
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2018-07-23 14:35:53 -0700
commit69f229a56652f076454ce9f3cb99bba285604ebe (patch)
treef7bfa660c8406cade4329c1c6915c320b98db06b /tensorflow/contrib/estimator
parent5e7807be1c709f55f5643e7993bba04d2ba72ea6 (diff)
Work around gfile.Glob's divergent behavior in different environments.
PiperOrigin-RevId: 205725301
Diffstat (limited to 'tensorflow/contrib/estimator')
-rw-r--r--tensorflow/contrib/estimator/python/estimator/early_stopping.py9
-rw-r--r--tensorflow/contrib/estimator/python/estimator/early_stopping_test.py13
2 files changed, 18 insertions, 4 deletions
diff --git a/tensorflow/contrib/estimator/python/estimator/early_stopping.py b/tensorflow/contrib/estimator/python/estimator/early_stopping.py
index af4855e91e..3eab21d5ac 100644
--- a/tensorflow/contrib/estimator/python/estimator/early_stopping.py
+++ b/tensorflow/contrib/estimator/python/estimator/early_stopping.py
@@ -394,10 +394,11 @@ def _summaries(eval_dir):
Yields:
`tensorflow.Event` object read from the event files.
"""
- for event_file in gfile.Glob(
- os.path.join(eval_dir, _EVENT_FILE_GLOB_PATTERN)):
- for event in summary_iterator.summary_iterator(event_file):
- yield event
+ if gfile.Exists(eval_dir):
+ for event_file in gfile.Glob(
+ os.path.join(eval_dir, _EVENT_FILE_GLOB_PATTERN)):
+ for event in summary_iterator.summary_iterator(event_file):
+ yield event
def _get_or_create_stop_var():
diff --git a/tensorflow/contrib/estimator/python/estimator/early_stopping_test.py b/tensorflow/contrib/estimator/python/estimator/early_stopping_test.py
index b5eee818fa..e4bfd4b446 100644
--- a/tensorflow/contrib/estimator/python/estimator/early_stopping_test.py
+++ b/tensorflow/contrib/estimator/python/estimator/early_stopping_test.py
@@ -92,6 +92,19 @@ class ReadEvalMetricsTest(test.TestCase):
},
}, early_stopping.read_eval_metrics(eval_dir))
+ def test_read_eval_metrics_when_no_events(self):
+ eval_dir = tempfile.mkdtemp()
+ self.assertTrue(os.path.exists(eval_dir))
+
+ # No error should be raised when eval directory exists with no event files.
+ self.assertEqual({}, early_stopping.read_eval_metrics(eval_dir))
+
+ os.rmdir(eval_dir)
+ self.assertFalse(os.path.exists(eval_dir))
+
+ # No error should be raised when eval directory does not exist.
+ self.assertEqual({}, early_stopping.read_eval_metrics(eval_dir))
+
class EarlyStoppingHooksTest(test.TestCase, parameterized.TestCase):