diff options
author | A. Unique TensorFlower <gardener@tensorflow.org> | 2018-09-17 13:24:29 -0700 |
---|---|---|
committer | TensorFlower Gardener <gardener@tensorflow.org> | 2018-09-17 13:34:57 -0700 |
commit | a768624f1d0ae3629caf5b9784b4b6911b881c18 (patch) | |
tree | f7581648c47b4ad95d10099f4485e5f41463f767 /tensorflow/contrib/metrics | |
parent | d7b4bf68dc80f1abf90bd6b857f079157028a861 (diff) |
Move from deprecated self.test_session() to self.cached_session().
self.test_session() has been deprecated in 9962eb5e84b15e309410071b06c2ed2d6148ed44 as its name confuses readers of the test. Moving to cached_session() instead which is more explicit about:
* the fact that the session may be reused.
* the session is not closed even when doing a "with self.test_session()" statement.
PiperOrigin-RevId: 213326581
Diffstat (limited to 'tensorflow/contrib/metrics')
-rw-r--r-- | tensorflow/contrib/metrics/python/kernel_tests/histogram_ops_test.py | 10 | ||||
-rw-r--r-- | tensorflow/contrib/metrics/python/metrics/classification_test.py | 28 |
2 files changed, 19 insertions, 19 deletions
diff --git a/tensorflow/contrib/metrics/python/kernel_tests/histogram_ops_test.py b/tensorflow/contrib/metrics/python/kernel_tests/histogram_ops_test.py index 1d18d6beff..bed1ecb71c 100644 --- a/tensorflow/contrib/metrics/python/kernel_tests/histogram_ops_test.py +++ b/tensorflow/contrib/metrics/python/kernel_tests/histogram_ops_test.py @@ -31,21 +31,21 @@ class Strict1dCumsumTest(test.TestCase): """Test this private function.""" def test_empty_tensor_returns_empty(self): - with self.test_session(): + with self.cached_session(): tensor = constant_op.constant([]) result = histogram_ops._strict_1d_cumsum(tensor, 0) expected = constant_op.constant([]) np.testing.assert_array_equal(expected.eval(), result.eval()) def test_length_1_tensor_works(self): - with self.test_session(): + with self.cached_session(): tensor = constant_op.constant([3], dtype=dtypes.float32) result = histogram_ops._strict_1d_cumsum(tensor, 1) expected = constant_op.constant([3], dtype=dtypes.float32) np.testing.assert_array_equal(expected.eval(), result.eval()) def test_length_3_tensor_works(self): - with self.test_session(): + with self.cached_session(): tensor = constant_op.constant([1, 2, 3], dtype=dtypes.float32) result = histogram_ops._strict_1d_cumsum(tensor, 3) expected = constant_op.constant([1, 3, 6], dtype=dtypes.float32) @@ -58,7 +58,7 @@ class AUCUsingHistogramTest(test.TestCase): self.rng = np.random.RandomState(0) def test_empty_labels_and_scores_gives_nan_auc(self): - with self.test_session(): + with self.cached_session(): labels = constant_op.constant([], shape=[0], dtype=dtypes.bool) scores = constant_op.constant([], shape=[0], dtype=dtypes.float32) score_range = [0, 1.] @@ -155,7 +155,7 @@ class AUCUsingHistogramTest(test.TestCase): from synthetic data. """ score_range = [0, 1.] or score_range - with self.test_session(): + with self.cached_session(): labels = array_ops.placeholder(dtypes.bool, shape=[num_records]) scores = array_ops.placeholder(dtypes.float32, shape=[num_records]) auc, update_op = histogram_ops.auc_using_histogram( diff --git a/tensorflow/contrib/metrics/python/metrics/classification_test.py b/tensorflow/contrib/metrics/python/metrics/classification_test.py index 3d0b81c1be..d6a670f97b 100644 --- a/tensorflow/contrib/metrics/python/metrics/classification_test.py +++ b/tensorflow/contrib/metrics/python/metrics/classification_test.py @@ -34,7 +34,7 @@ from tensorflow.python.platform import test class ClassificationTest(test.TestCase): def testAccuracy1D(self): - with self.test_session() as session: + with self.cached_session() as session: pred = array_ops.placeholder(dtypes.int32, shape=[None]) labels = array_ops.placeholder(dtypes.int32, shape=[None]) acc = classification.accuracy(pred, labels) @@ -44,7 +44,7 @@ class ClassificationTest(test.TestCase): self.assertEqual(result, 0.5) def testAccuracy1DBool(self): - with self.test_session() as session: + with self.cached_session() as session: pred = array_ops.placeholder(dtypes.bool, shape=[None]) labels = array_ops.placeholder(dtypes.bool, shape=[None]) acc = classification.accuracy(pred, labels) @@ -54,7 +54,7 @@ class ClassificationTest(test.TestCase): self.assertEqual(result, 0.5) def testAccuracy1DInt64(self): - with self.test_session() as session: + with self.cached_session() as session: pred = array_ops.placeholder(dtypes.int64, shape=[None]) labels = array_ops.placeholder(dtypes.int64, shape=[None]) acc = classification.accuracy(pred, labels) @@ -64,7 +64,7 @@ class ClassificationTest(test.TestCase): self.assertEqual(result, 0.5) def testAccuracy1DString(self): - with self.test_session() as session: + with self.cached_session() as session: pred = array_ops.placeholder(dtypes.string, shape=[None]) labels = array_ops.placeholder(dtypes.string, shape=[None]) acc = classification.accuracy(pred, labels) @@ -87,7 +87,7 @@ class ClassificationTest(test.TestCase): classification.accuracy(pred, labels) def testAccuracy1DWeighted(self): - with self.test_session() as session: + with self.cached_session() as session: pred = array_ops.placeholder(dtypes.int32, shape=[None]) labels = array_ops.placeholder(dtypes.int32, shape=[None]) weights = array_ops.placeholder(dtypes.float32, shape=[None]) @@ -101,7 +101,7 @@ class ClassificationTest(test.TestCase): self.assertEqual(result, 0.5) def testAccuracy1DWeightedBroadcast(self): - with self.test_session() as session: + with self.cached_session() as session: pred = array_ops.placeholder(dtypes.int32, shape=[None]) labels = array_ops.placeholder(dtypes.int32, shape=[None]) weights = array_ops.placeholder(dtypes.float32, shape=[]) @@ -161,7 +161,7 @@ class F1ScoreTest(test.TestCase): (10, 3), maxval=2, dtype=dtypes.int64, seed=2) f1, f1_op = classification.f1_score(predictions, labels, num_thresholds=3) - with self.test_session() as sess: + with self.cached_session() as sess: sess.run(variables.local_variables_initializer()) # Run several updates. @@ -176,7 +176,7 @@ class F1ScoreTest(test.TestCase): def testAllCorrect(self): inputs = np.random.randint(0, 2, size=(100, 1)) - with self.test_session() as sess: + with self.cached_session() as sess: predictions = constant_op.constant(inputs, dtype=dtypes.float32) labels = constant_op.constant(inputs) f1, f1_op = classification.f1_score(predictions, labels, num_thresholds=3) @@ -191,7 +191,7 @@ class F1ScoreTest(test.TestCase): [1, 0, 1, 0], shape=(1, 4), dtype=dtypes.float32) labels = constant_op.constant([0, 1, 1, 0], shape=(1, 4)) f1, f1_op = classification.f1_score(predictions, labels, num_thresholds=1) - with self.test_session() as sess: + with self.cached_session() as sess: sess.run(variables.local_variables_initializer()) sess.run([f1_op]) # Threshold 0 will have around 0.5 precision and 1 recall yielding an F1 @@ -201,7 +201,7 @@ class F1ScoreTest(test.TestCase): def testAllIncorrect(self): inputs = np.random.randint(0, 2, size=(10000, 1)) - with self.test_session() as sess: + with self.cached_session() as sess: predictions = constant_op.constant(inputs, dtype=dtypes.float32) labels = constant_op.constant(1 - inputs, dtype=dtypes.float32) f1, f1_op = classification.f1_score(predictions, labels, num_thresholds=3) @@ -214,7 +214,7 @@ class F1ScoreTest(test.TestCase): self.assertAlmostEqual(2 * 0.5 * 1 / (1 + 0.5), f1.eval(), places=2) def testWeights1d(self): - with self.test_session() as sess: + with self.cached_session() as sess: predictions = constant_op.constant( [[1, 0], [1, 0]], shape=(2, 2), dtype=dtypes.float32) labels = constant_op.constant([[0, 1], [1, 0]], shape=(2, 2)) @@ -228,7 +228,7 @@ class F1ScoreTest(test.TestCase): self.assertAlmostEqual(1.0, f1.eval(), places=5) def testWeights2d(self): - with self.test_session() as sess: + with self.cached_session() as sess: predictions = constant_op.constant( [[1, 0], [1, 0]], shape=(2, 2), dtype=dtypes.float32) labels = constant_op.constant([[0, 1], [1, 0]], shape=(2, 2)) @@ -242,7 +242,7 @@ class F1ScoreTest(test.TestCase): self.assertAlmostEqual(1.0, f1.eval(), places=5) def testZeroLabelsPredictions(self): - with self.test_session() as sess: + with self.cached_session() as sess: predictions = array_ops.zeros([4], dtype=dtypes.float32) labels = array_ops.zeros([4]) f1, f1_op = classification.f1_score(predictions, labels, num_thresholds=3) @@ -300,7 +300,7 @@ class F1ScoreTest(test.TestCase): f1, f1_op = classification.f1_score(tf_labels, tf_predictions, num_thresholds=3) - with self.test_session() as sess: + with self.cached_session() as sess: sess.run(variables.local_variables_initializer()) for _ in range(num_batches): sess.run([f1_op]) |