diff options
author | Nathan Silberman <nsilberman@google.com> | 2016-11-11 07:27:09 -0800 |
---|---|---|
committer | TensorFlower Gardener <gardener@tensorflow.org> | 2016-11-11 07:44:00 -0800 |
commit | 7846a90355753910b60b5e927ebbfffce2622ef6 (patch) | |
tree | 7599179e15e2a97996abd5882586f4192788ce6f | |
parent | a045d500b01c617eaee988e3f8b77e3b0d1b4ce3 (diff) |
Ensuring that each test that accesses a local directory uses a separate directory.
Change: 138874226
-rw-r--r-- | tensorflow/contrib/framework/python/ops/variables.py | 2 | ||||
-rw-r--r-- | tensorflow/contrib/framework/python/ops/variables_test.py | 51 |
2 files changed, 43 insertions, 10 deletions
diff --git a/tensorflow/contrib/framework/python/ops/variables.py b/tensorflow/contrib/framework/python/ops/variables.py index 49aca82fbf..aedadb970b 100644 --- a/tensorflow/contrib/framework/python/ops/variables.py +++ b/tensorflow/contrib/framework/python/ops/variables.py @@ -292,7 +292,7 @@ def get_model_variables(scope=None, suffix=None): def get_local_variables(scope=None, suffix=None): - """Gets the list of model variables, filtered by scope and/or suffix. + """Gets the list of local variables, filtered by scope and/or suffix. Args: scope: an optional scope for filtering the variables to return. diff --git a/tensorflow/contrib/framework/python/ops/variables_test.py b/tensorflow/contrib/framework/python/ops/variables_test.py index a25d4cf2c1..cf937dce70 100644 --- a/tensorflow/contrib/framework/python/ops/variables_test.py +++ b/tensorflow/contrib/framework/python/ops/variables_test.py @@ -19,6 +19,7 @@ from __future__ import division from __future__ import print_function import os +import tempfile import numpy as np import tensorflow as tf @@ -792,11 +793,13 @@ class AssignFromCheckpointTest(tf.test.TestCase): return saver.save(sess, checkpoint_dir, global_step=global_step) def testLoadExistingVariables(self): + model_dir = tempfile.mkdtemp(prefix=os.path.join( + self.get_temp_dir(), 'load_existing_variables')) + init_value0 = 10.0 init_value1 = 20.0 var_names_to_values = {'v0': init_value0, 'v1': init_value1} - model_dir = os.path.join(self.get_temp_dir(), 'model') with self.test_session() as sess: model_path = self.create_checkpoint_from_values(var_names_to_values, model_dir) @@ -818,11 +821,13 @@ class AssignFromCheckpointTest(tf.test.TestCase): self.assertEqual(init_value1, var1.eval()) def testRaisesValueErrorIfAVariableIsntFound(self): + model_dir = tempfile.mkdtemp(prefix=os.path.join( + self.get_temp_dir(), 'raises_value_error_if_var_isnt_found')) + init_value0 = 10.0 init_value1 = 20.0 var_names_to_values = {'v0': init_value0, 'v1': init_value1} - model_dir = os.path.join(self.get_temp_dir(), 'model') with self.test_session(): model_path = self.create_checkpoint_from_values(var_names_to_values, model_dir) @@ -836,13 +841,16 @@ class AssignFromCheckpointTest(tf.test.TestCase): vars_to_restore) def testInitFromCheckpointWithScopes(self): + model_dir = tempfile.mkdtemp(prefix=os.path.join( + self.get_temp_dir(), 'init_from_checkpoint_with_scopes')) + init_value0 = np.asarray([1.0, 3.0, 9.0], dtype=np.float32).reshape((1, 3, 1)) init_value1 = np.asarray([2.0, 4.0, 6.0, 8.0], dtype=np.float32).reshape((2, 1, 2)) var_names_to_values = {'layer0/v0': init_value0, 'layer1/v1': init_value1} - model_dir = os.path.join(self.get_temp_dir(), 'model') + with self.test_session() as sess: model_path = self.create_checkpoint_from_values(var_names_to_values, model_dir) @@ -896,11 +904,15 @@ class AssignFromCheckpointFnTest(tf.test.TestCase): return saver.save(sess, checkpoint_dir, global_step=global_step) def testLoadExistingVariables(self): + model_dir = tempfile.mkdtemp(prefix=os.path.join( + self.get_temp_dir(), 'load_existing_variables')) + if tf.gfile.Exists(model_dir): + tf.gfile.DeleteRecursively(model_dir) + init_value0 = 10.0 init_value1 = 20.0 var_names_to_values = {'v0': init_value0, 'v1': init_value1} - model_dir = os.path.join(self.get_temp_dir(), 'model') with self.test_session() as sess: model_path = self.create_checkpoint_from_values(var_names_to_values, model_dir) @@ -922,11 +934,15 @@ class AssignFromCheckpointFnTest(tf.test.TestCase): self.assertEqual(init_value1, var1.eval()) def testLoadExistingVariablesDifferentShapeDefaultDoesNotAllowReshape(self): + model_dir = tempfile.mkdtemp(prefix=os.path.join( + self.get_temp_dir(), 'load_existing_vars_no_reshape')) + if tf.gfile.Exists(model_dir): + tf.gfile.DeleteRecursively(model_dir) + init_value0 = [[10.0, 11.0]] init_value1 = 20.0 var_names_to_values = {'v0': init_value0, 'v1': init_value1} - model_dir = os.path.join(self.get_temp_dir(), 'model') with self.test_session() as sess: model_path = self.create_checkpoint_from_values(var_names_to_values, model_dir) @@ -945,11 +961,16 @@ class AssignFromCheckpointFnTest(tf.test.TestCase): init_fn(sess) def testLoadExistingVariablesDifferentShapeAllowReshape(self): + model_dir = tempfile.mkdtemp(prefix=os.path.join( + self.get_temp_dir(), + 'load_existing_variables_different_shape_allow_reshape')) + if tf.gfile.Exists(model_dir): + tf.gfile.DeleteRecursively(model_dir) + init_value0 = [[10.0, 11.0]] init_value1 = 20.0 var_names_to_values = {'v0': init_value0, 'v1': init_value1} - model_dir = os.path.join(self.get_temp_dir(), 'model') with self.test_session() as sess: model_path = self.create_checkpoint_from_values(var_names_to_values, model_dir) @@ -971,11 +992,15 @@ class AssignFromCheckpointFnTest(tf.test.TestCase): self.assertEqual(init_value1, var1.eval()) def testNotFoundError(self): + model_dir = tempfile.mkdtemp(prefix=os.path.join( + self.get_temp_dir(), 'not_found_error')) + if tf.gfile.Exists(model_dir): + tf.gfile.DeleteRecursively(model_dir) + init_value0 = 10.0 init_value1 = 20.0 var_names_to_values = {'v0': init_value0, 'v1': init_value1} - model_dir = os.path.join(self.get_temp_dir(), 'model') with self.test_session() as sess: model_path = self.create_checkpoint_from_values(var_names_to_values, model_dir) @@ -996,11 +1021,15 @@ class AssignFromCheckpointFnTest(tf.test.TestCase): init_fn(sess) def testMissingVariablesList(self): + model_dir = tempfile.mkdtemp(prefix=os.path.join( + self.get_temp_dir(), 'missing_variables_list')) + if tf.gfile.Exists(model_dir): + tf.gfile.DeleteRecursively(model_dir) + init_value0 = 10.0 init_value1 = 20.0 var_names_to_values = {'v0': init_value0, 'v1': init_value1} - model_dir = os.path.join(self.get_temp_dir(), 'model') with self.test_session() as sess: model_path = self.create_checkpoint_from_values(var_names_to_values, model_dir) @@ -1025,11 +1054,15 @@ class AssignFromCheckpointFnTest(tf.test.TestCase): self.assertEqual(init_value1, var1.eval()) def testMissingVariablesDict(self): + model_dir = tempfile.mkdtemp(prefix=os.path.join( + self.get_temp_dir(), 'missing_variables_dict')) + if tf.gfile.Exists(model_dir): + tf.gfile.DeleteRecursively(model_dir) + init_value0 = 10.0 init_value1 = 20.0 var_names_to_values = {'v0': init_value0, 'v1': init_value1} - model_dir = os.path.join(self.get_temp_dir(), 'model') with self.test_session() as sess: model_path = self.create_checkpoint_from_values(var_names_to_values, model_dir) |