Unverified Commit 2661eb97 authored by Taylor Robie's avatar Taylor Robie Committed by GitHub
Browse files

change reference_data.py to use tf.gfile (#3921)

* change reference_data.py to use tf.gfile

* simplify json treatment

* Update reference files to account for a superficial change in batch_norm
parent c93409cf
...@@ -170,7 +170,7 @@ class BaseTest(tf.test.TestCase): ...@@ -170,7 +170,7 @@ class BaseTest(tf.test.TestCase):
# Serialize graph for comparison. # Serialize graph for comparison.
graph_bytes = graph.as_graph_def().SerializeToString() graph_bytes = graph.as_graph_def().SerializeToString()
expected_file = os.path.join(data_dir, "expected_graph") expected_file = os.path.join(data_dir, "expected_graph")
with open(expected_file, "wb") as f: with tf.gfile.Open(expected_file, "wb") as f:
f.write(graph_bytes) f.write(graph_bytes)
with graph.as_default(): with graph.as_default():
...@@ -191,10 +191,10 @@ class BaseTest(tf.test.TestCase): ...@@ -191,10 +191,10 @@ class BaseTest(tf.test.TestCase):
if correctness_function is not None: if correctness_function is not None:
results = correctness_function(*eval_results) results = correctness_function(*eval_results)
with open(os.path.join(data_dir, "results.json"), "wt") as f: with tf.gfile.Open(os.path.join(data_dir, "results.json"), "w") as f:
json.dump(results, f) json.dump(results, f)
with open(os.path.join(data_dir, "tf_version.json"), "wt") as f: with tf.gfile.Open(os.path.join(data_dir, "tf_version.json"), "w") as f:
json.dump([tf.VERSION, tf.GIT_VERSION], f) json.dump([tf.VERSION, tf.GIT_VERSION], f)
def _evaluate_test_case(self, name, graph, ops_to_eval, correctness_function): def _evaluate_test_case(self, name, graph, ops_to_eval, correctness_function):
...@@ -216,7 +216,7 @@ class BaseTest(tf.test.TestCase): ...@@ -216,7 +216,7 @@ class BaseTest(tf.test.TestCase):
# Serialize graph for comparison. # Serialize graph for comparison.
graph_bytes = graph.as_graph_def().SerializeToString() graph_bytes = graph.as_graph_def().SerializeToString()
expected_file = os.path.join(data_dir, "expected_graph") expected_file = os.path.join(data_dir, "expected_graph")
with open(expected_file, "rb") as f: with tf.gfile.Open(expected_file, "rb") as f:
expected_graph_bytes = f.read() expected_graph_bytes = f.read()
# The serialization is non-deterministic byte-for-byte. Instead there is # The serialization is non-deterministic byte-for-byte. Instead there is
# a utility which evaluates the semantics of the two graphs to test for # a utility which evaluates the semantics of the two graphs to test for
...@@ -231,7 +231,7 @@ class BaseTest(tf.test.TestCase): ...@@ -231,7 +231,7 @@ class BaseTest(tf.test.TestCase):
init = tf.global_variables_initializer() init = tf.global_variables_initializer()
saver = tf.train.Saver() saver = tf.train.Saver()
with open(os.path.join(data_dir, "tf_version.json"), "rt") as f: with tf.gfile.Open(os.path.join(data_dir, "tf_version.json"), "r") as f:
tf_version_reference, tf_git_version_reference = json.load(f) # pylint: disable=unpacking-non-sequence tf_version_reference, tf_git_version_reference = json.load(f) # pylint: disable=unpacking-non-sequence
tf_version_comparison = "" tf_version_comparison = ""
...@@ -262,7 +262,7 @@ class BaseTest(tf.test.TestCase): ...@@ -262,7 +262,7 @@ class BaseTest(tf.test.TestCase):
eval_results = [op.eval() for op in ops_to_eval] eval_results = [op.eval() for op in ops_to_eval]
if correctness_function is not None: if correctness_function is not None:
results = correctness_function(*eval_results) results = correctness_function(*eval_results)
with open(os.path.join(data_dir, "results.json"), "rt") as f: with tf.gfile.Open(os.path.join(data_dir, "results.json"), "r") as f:
expected_results = json.load(f) expected_results = json.load(f)
self.assertAllClose(results, expected_results) self.assertAllClose(results, expected_results)
......
[32, 8, 8, 4, 0.08920872211456299, 0.8918969631195068, 4064.7060546875, 32, 4, 4, 8, 0.0, 0.8524793982505798, 2294.368896484375] [32, 8, 8, 4, 0.08920872211456299, 0.8918969631195068, 4064.7060546875, 32, 4, 4, 8, 0.0, 0.10715862363576889, 2344.4775390625]
\ No newline at end of file \ No newline at end of file
["1.8.0-dev20180325", "v1.7.0-rc1-750-g6c1737e6c8"] ["1.8.0-dev20180408", "v1.7.0-1345-gb874783ccd"]
\ No newline at end of file \ No newline at end of file
[32, 8, 8, 4, 0.918815016746521, 0.1826801300048828, 4064.4677734375, 32, 4, 4, 8, -1.6396304368972778, 0.00014326802920550108, 98.39237213134766] [32, 8, 8, 4, 0.918815016746521, 0.1826801300048828, 4064.4677734375, 32, 4, 4, 8, -1.3153012990951538, 0.011247094720602036, 261.84716796875]
\ No newline at end of file \ No newline at end of file
["1.8.0-dev20180325", "v1.7.0-rc1-750-g6c1737e6c8"] ["1.8.0-dev20180408", "v1.7.0-1345-gb874783ccd"]
\ No newline at end of file \ No newline at end of file
[32, 8, 8, 4, 0.1677999496459961, 0.7767924070358276, 4089.44189453125, 32, 8, 8, 4, 1.8148397207260132, 1.3842545747756958, 5515.17529296875] [32, 8, 8, 4, 0.1677999496459961, 0.7767924070358276, 4089.44189453125, 32, 8, 8, 4, 0.8615571856498718, 1.1359407901763916, 5806.876953125]
\ No newline at end of file \ No newline at end of file
["1.8.0-dev20180325", "v1.7.0-rc1-750-g6c1737e6c8"] ["1.8.0-dev20180408", "v1.7.0-1345-gb874783ccd"]
\ No newline at end of file \ No newline at end of file
[32, 8, 8, 4, 0.8239736557006836, 0.3485994338989258, 4108.87548828125, 32, 8, 8, 4, 0.8239736557006836, 0.3485994338989258, 1519.11328125] [32, 8, 8, 4, 0.8239736557006836, 0.3485994338989258, 4108.87548828125, 32, 8, 8, 4, 0.16798323392868042, -0.2975311279296875, 2860.068359375]
\ No newline at end of file \ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment