From 903688ccc0672e2ff4bef2ee29e59d146ea9a495 Mon Sep 17 00:00:00 2001 From: Boris Pfahringer Date: Mon, 29 Jan 2018 15:41:49 +0000 Subject: [PATCH 1/5] Accept directory path in check_eventfile_for_keyword() helper.' So that we can look in the evaluation directory if we want to test evaluation summary writing. --- tensorflow/python/estimator/estimator_test.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tensorflow/python/estimator/estimator_test.py b/tensorflow/python/estimator/estimator_test.py index 39a5b998ebd..b3057afa294 100644 --- a/tensorflow/python/estimator/estimator_test.py +++ b/tensorflow/python/estimator/estimator_test.py @@ -80,13 +80,13 @@ def dummy_model_fn(features, labels, params): _, _, _ = features, labels, params -def check_eventfile_for_keyword(keyword, est): +def check_eventfile_for_keyword(keyword, dir_): """Checks event files for the keyword.""" writer_cache.FileWriterCache.clear() # Get last Event written. - event_paths = glob.glob(os.path.join(est.model_dir, 'events*')) + event_paths = glob.glob(os.path.join(dir_, 'events*')) last_event = None for last_event in summary_iterator.summary_iterator(event_paths[-1]): if last_event.summary is not None: @@ -610,7 +610,7 @@ class EstimatorTrainTest(test.TestCase): # Make sure nothing is stuck in limbo. writer_cache.FileWriterCache.clear() - if check_eventfile_for_keyword('loss', est): + if check_eventfile_for_keyword('loss', est.model_dir): return self.fail('{} should be part of reported summaries.'.format('loss')) @@ -1291,7 +1291,7 @@ class EstimatorEvaluateTest(test.TestCase): writer_cache.FileWriterCache.clear() # Get last Event written. - if check_eventfile_for_keyword('image', est): + if check_eventfile_for_keyword('image', est.model_dir): return self.fail('{} should be part of reported summaries.'.format('image')) From 1230811c773756fdb2dff830da432c1dff4675e1 Mon Sep 17 00:00:00 2001 From: Boris Pfahringer Date: Wed, 31 Jan 2018 19:44:52 +0100 Subject: [PATCH 2/5] Look at all summary values when looking for a tag. --- tensorflow/python/estimator/estimator_test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tensorflow/python/estimator/estimator_test.py b/tensorflow/python/estimator/estimator_test.py index b3057afa294..65c9bd1d11e 100644 --- a/tensorflow/python/estimator/estimator_test.py +++ b/tensorflow/python/estimator/estimator_test.py @@ -90,8 +90,8 @@ def check_eventfile_for_keyword(keyword, dir_): last_event = None for last_event in summary_iterator.summary_iterator(event_paths[-1]): if last_event.summary is not None: - if last_event.summary.value: - if keyword in last_event.summary.value[0].tag: + for value in last_event.summary.value: + if keyword in value.tag: return True return False From 92d622d27fbb2fe1f2e29a17a606c166fcc12f35 Mon Sep 17 00:00:00 2001 From: Boris Pfahringer Date: Mon, 29 Jan 2018 15:45:44 +0000 Subject: [PATCH 3/5] Check the evaluation events in the evaluation tests. --- tensorflow/python/estimator/estimator_test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tensorflow/python/estimator/estimator_test.py b/tensorflow/python/estimator/estimator_test.py index 65c9bd1d11e..1af331697e6 100644 --- a/tensorflow/python/estimator/estimator_test.py +++ b/tensorflow/python/estimator/estimator_test.py @@ -1290,8 +1290,8 @@ class EstimatorEvaluateTest(test.TestCase): # Make sure nothing is stuck in limbo. writer_cache.FileWriterCache.clear() - # Get last Event written. - if check_eventfile_for_keyword('image', est.model_dir): + # Get last evaluation Event written. + if check_eventfile_for_keyword('image', os.path.join(est.model_dir, 'eval')): return self.fail('{} should be part of reported summaries.'.format('image')) From 0b012956d2c86583c189121a3b292de3c5e0cc6c Mon Sep 17 00:00:00 2001 From: Boris Pfahringer Date: Mon, 29 Jan 2018 15:51:15 +0000 Subject: [PATCH 4/5] Fix writing binary summaries in python3. In python 3, tf.string tensors are bytes() objects when fetched, not str(). six.binary_type maps exactly to tf.string in python 2 and 3, so use it to determine if we should try to interpret a metric as a tf.Summary proto. --- tensorflow/python/estimator/estimator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tensorflow/python/estimator/estimator.py b/tensorflow/python/estimator/estimator.py index 78d74b63d3e..f938ee0110e 100644 --- a/tensorflow/python/estimator/estimator.py +++ b/tensorflow/python/estimator/estimator.py @@ -1103,7 +1103,7 @@ def _write_dict_to_summary(output_dir, isinstance(dictionary[key], np.int32) or isinstance(dictionary[key], int)): summary_proto.value.add(tag=key, simple_value=int(dictionary[key])) - elif isinstance(dictionary[key], six.string_types): + elif isinstance(dictionary[key], six.binary_type): try: summ = summary_pb2.Summary.FromString(dictionary[key]) for i, _ in enumerate(summ.value): From 45a86d1acac8d5a3a6f159c9f5e186499e3d179a Mon Sep 17 00:00:00 2001 From: Martin Wicke <577277+martinwicke@users.noreply.github.com> Date: Thu, 15 Feb 2018 16:33:10 -0800 Subject: [PATCH 5/5] Lint fix --- tensorflow/python/estimator/estimator_test.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tensorflow/python/estimator/estimator_test.py b/tensorflow/python/estimator/estimator_test.py index 1af331697e6..641888d2295 100644 --- a/tensorflow/python/estimator/estimator_test.py +++ b/tensorflow/python/estimator/estimator_test.py @@ -1291,7 +1291,8 @@ class EstimatorEvaluateTest(test.TestCase): writer_cache.FileWriterCache.clear() # Get last evaluation Event written. - if check_eventfile_for_keyword('image', os.path.join(est.model_dir, 'eval')): + if check_eventfile_for_keyword('image', + os.path.join(est.model_dir, 'eval')): return self.fail('{} should be part of reported summaries.'.format('image'))