diff options
author | 2018-08-21 19:53:48 -0700 | |
---|---|---|
committer | 2018-08-21 20:03:09 -0700 | |
commit | ba9501e0a6c457a0bb051760bf9312d31c6211bf (patch) | |
tree | 4384fad21a1645d9c35172a8820d2f1b19e04975 /tensorflow/contrib/image | |
parent | 47c0bda0e7f736a9328aaf76aba7c8006e24556f (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: 209703613
Diffstat (limited to 'tensorflow/contrib/image')
7 files changed, 40 insertions, 40 deletions
diff --git a/tensorflow/contrib/image/python/kernel_tests/dense_image_warp_test.py b/tensorflow/contrib/image/python/kernel_tests/dense_image_warp_test.py index a58b6a247e..24b790977d 100644 --- a/tensorflow/contrib/image/python/kernel_tests/dense_image_warp_test.py +++ b/tensorflow/contrib/image/python/kernel_tests/dense_image_warp_test.py @@ -50,7 +50,7 @@ class DenseImageWarpTest(test_util.TensorFlowTestCase): interp = dense_image_warp._interpolate_bilinear(grid, query_points) - with self.test_session() as sess: + with self.cached_session() as sess: predicted = sess.run(interp) self.assertAllClose(expected_results, predicted) @@ -64,7 +64,7 @@ class DenseImageWarpTest(test_util.TensorFlowTestCase): interp = dense_image_warp._interpolate_bilinear( grid, query_points, indexing='xy') - with self.test_session() as sess: + with self.cached_session() as sess: predicted = sess.run(interp) self.assertAllClose(expected_results, predicted) @@ -78,7 +78,7 @@ class DenseImageWarpTest(test_util.TensorFlowTestCase): interp = dense_image_warp._interpolate_bilinear(grid, query_points) - with self.test_session() as sess: + with self.cached_session() as sess: predicted = sess.run(interp) self.assertAllClose(expected_results, predicted) @@ -160,7 +160,7 @@ class DenseImageWarpTest(test_util.TensorFlowTestCase): flow_type) interp = dense_image_warp.dense_image_warp(image, flows) - with self.test_session() as sess: + with self.cached_session() as sess: rand_image, rand_flows = self.get_random_image_and_flows( shape, image_type, flow_type) rand_flows *= 0 @@ -191,7 +191,7 @@ class DenseImageWarpTest(test_util.TensorFlowTestCase): flow_type) interp = dense_image_warp.dense_image_warp(image, flows) low_precision = image_type == 'float16' or flow_type == 'float16' - with self.test_session() as sess: + with self.cached_session() as sess: rand_image, rand_flows = self.get_random_image_and_flows( shape, image_type, flow_type) @@ -249,7 +249,7 @@ class DenseImageWarpTest(test_util.TensorFlowTestCase): opt_func = optimizer.apply_gradients(zip(grad, [flows])) init_op = variables.global_variables_initializer() - with self.test_session() as sess: + with self.cached_session() as sess: sess.run(init_op) for _ in range(10): sess.run(opt_func) diff --git a/tensorflow/contrib/image/python/kernel_tests/distort_image_ops_test.py b/tensorflow/contrib/image/python/kernel_tests/distort_image_ops_test.py index a495b58b7f..ac8573445c 100644 --- a/tensorflow/contrib/image/python/kernel_tests/distort_image_ops_test.py +++ b/tensorflow/contrib/image/python/kernel_tests/distort_image_ops_test.py @@ -217,7 +217,7 @@ class AdjustSaturationInYiqTest(test_util.TensorFlowTestCase): 'gb_same', 'rgb_same', ] - with self.test_session(): + with self.cached_session(): for x_shape in x_shapes: for test_style in test_styles: x_np = np.random.rand(*x_shape) * 255. diff --git a/tensorflow/contrib/image/python/kernel_tests/image_ops_test.py b/tensorflow/contrib/image/python/kernel_tests/image_ops_test.py index f588eae923..70339d7612 100644 --- a/tensorflow/contrib/image/python/kernel_tests/image_ops_test.py +++ b/tensorflow/contrib/image/python/kernel_tests/image_ops_test.py @@ -39,7 +39,7 @@ class ImageOpsTest(test_util.TensorFlowTestCase): def test_zeros(self): for dtype in _DTYPES: - with self.test_session(): + with self.cached_session(): for shape in [(5, 5), (24, 24), (2, 24, 24, 3)]: for angle in [0, 1, np.pi / 2.0]: image = array_ops.zeros(shape, dtype) @@ -49,7 +49,7 @@ class ImageOpsTest(test_util.TensorFlowTestCase): def test_rotate_even(self): for dtype in _DTYPES: - with self.test_session(): + with self.cached_session(): image = array_ops.reshape( math_ops.cast(math_ops.range(36), dtype), (6, 6)) image_rep = array_ops.tile(image[None, :, :, None], [3, 1, 1, 1]) @@ -71,7 +71,7 @@ class ImageOpsTest(test_util.TensorFlowTestCase): def test_rotate_odd(self): for dtype in _DTYPES: - with self.test_session(): + with self.cached_session(): image = array_ops.reshape( math_ops.cast(math_ops.range(25), dtype), (5, 5)) image_rep = array_ops.tile(image[None, :, :, None], [3, 1, 1, 1]) @@ -91,7 +91,7 @@ class ImageOpsTest(test_util.TensorFlowTestCase): def test_translate(self): for dtype in _DTYPES: - with self.test_session(): + with self.cached_session(): image = constant_op.constant( [[1, 0, 1, 0], [0, 1, 0, 1], @@ -107,7 +107,7 @@ class ImageOpsTest(test_util.TensorFlowTestCase): def test_compose(self): for dtype in _DTYPES: - with self.test_session(): + with self.cached_session(): image = constant_op.constant( [[1, 1, 1, 0], [1, 0, 0, 0], @@ -131,7 +131,7 @@ class ImageOpsTest(test_util.TensorFlowTestCase): def test_extreme_projective_transform(self): for dtype in _DTYPES: - with self.test_session(): + with self.cached_session(): image = constant_op.constant( [[1, 0, 1, 0], [0, 1, 0, 1], @@ -147,7 +147,7 @@ class ImageOpsTest(test_util.TensorFlowTestCase): [0, 0, 0, 0]]) def test_bilinear(self): - with self.test_session(): + with self.cached_session(): image = constant_op.constant( [[0, 0, 0, 0, 0], [0, 1, 1, 1, 0], @@ -176,7 +176,7 @@ class ImageOpsTest(test_util.TensorFlowTestCase): [0, 0, 1, 0, 0]]) def test_bilinear_uint8(self): - with self.test_session(): + with self.cached_session(): image = constant_op.constant( np.asarray( [[0.0, 0.0, 0.0, 0.0, 0.0], @@ -209,7 +209,7 @@ class ImageOpsTest(test_util.TensorFlowTestCase): self.assertAllEqual([3, 5], result.get_shape()) def _test_grad(self, shape_to_test): - with self.test_session(): + with self.cached_session(): test_image_shape = shape_to_test test_image = np.random.randn(*test_image_shape) test_image_tensor = constant_op.constant( @@ -228,7 +228,7 @@ class ImageOpsTest(test_util.TensorFlowTestCase): self.assertLess(left_err, 1e-10) def _test_grad_different_shape(self, input_shape, output_shape): - with self.test_session(): + with self.cached_session(): test_image_shape = input_shape test_image = np.random.randn(*test_image_shape) test_image_tensor = constant_op.constant( @@ -276,7 +276,7 @@ class BipartiteMatchTest(test_util.TensorFlowTestCase): expected_col_to_row_match_np = np.array(expected_col_to_row_match, dtype=np.int32) - with self.test_session(): + with self.cached_session(): distance_mat_tf = constant_op.constant(distance_mat_np, shape=distance_mat_shape) location_to_prior, prior_to_location = image_ops.bipartite_match( diff --git a/tensorflow/contrib/image/python/kernel_tests/interpolate_spline_test.py b/tensorflow/contrib/image/python/kernel_tests/interpolate_spline_test.py index 3054128979..d58a654292 100644 --- a/tensorflow/contrib/image/python/kernel_tests/interpolate_spline_test.py +++ b/tensorflow/contrib/image/python/kernel_tests/interpolate_spline_test.py @@ -165,7 +165,7 @@ class InterpolateSplineTest(test_util.TensorFlowTestCase): with ops.name_scope('interpolator'): interpolator = interpolate_spline.interpolate_spline( train_points, train_values, query_points, interpolation_order) - with self.test_session() as sess: + with self.cached_session() as sess: fetches = [query_points, train_points, train_values, interpolator] query_points_, train_points_, train_values_, interp_ = sess.run(fetches) @@ -205,7 +205,7 @@ class InterpolateSplineTest(test_util.TensorFlowTestCase): target_interpolation = tp.HARDCODED_QUERY_VALUES[(order, reg_weight)] target_interpolation = np.array(target_interpolation) - with self.test_session() as sess: + with self.cached_session() as sess: interp_val = sess.run(interpolator) self.assertAllClose(interp_val[0, :, 0], target_interpolation) @@ -223,7 +223,7 @@ class InterpolateSplineTest(test_util.TensorFlowTestCase): target_interpolation = tp.HARDCODED_QUERY_VALUES[(order, reg_weight)] target_interpolation = np.array(target_interpolation) - with self.test_session() as sess: + with self.cached_session() as sess: interp_val = sess.run(interpolator) self.assertAllClose(interp_val[0, :, 0], target_interpolation) @@ -253,7 +253,7 @@ class InterpolateSplineTest(test_util.TensorFlowTestCase): target_interpolation = tp.HARDCODED_QUERY_VALUES[(order, reg_weight)] target_interpolation = np.array(target_interpolation) - with self.test_session() as sess: + with self.cached_session() as sess: (train_points_value, train_values_value, query_points_value) = sess.run( [train_points, train_values, query_points]) @@ -330,7 +330,7 @@ class InterpolateSplineTest(test_util.TensorFlowTestCase): opt_func = optimizer.apply_gradients(zip(grad, [train_points])) init_op = variables.global_variables_initializer() - with self.test_session() as sess: + with self.cached_session() as sess: sess.run(init_op) for _ in range(100): sess.run([loss, opt_func]) diff --git a/tensorflow/contrib/image/python/kernel_tests/segmentation_test.py b/tensorflow/contrib/image/python/kernel_tests/segmentation_test.py index 48066cbace..3d39165ede 100644 --- a/tensorflow/contrib/image/python/kernel_tests/segmentation_test.py +++ b/tensorflow/contrib/image/python/kernel_tests/segmentation_test.py @@ -59,19 +59,19 @@ class SegmentationTest(test_util.TensorFlowTestCase): [7, 0, 8, 0, 0, 0, 9, 0, 0], [0, 0, 0, 0, 10, 0, 0, 0, 0], [0, 0, 11, 0, 0, 0, 0, 0, 0]]) # pyformat: disable - with self.test_session(): + with self.cached_session(): self.assertAllEqual(image_ops.connected_components(arr).eval(), expected) def testSimple(self): arr = [[0, 1, 0], [1, 1, 1], [0, 1, 0]] - with self.test_session(): + with self.cached_session(): # Single component with id 1. self.assertAllEqual( image_ops.connected_components(math_ops.cast( arr, dtypes.bool)).eval(), arr) def testSnake(self): - with self.test_session(): + with self.cached_session(): # Single component with id 1. self.assertAllEqual( image_ops.connected_components(math_ops.cast( @@ -80,7 +80,7 @@ class SegmentationTest(test_util.TensorFlowTestCase): def testSnake_disconnected(self): for i in range(SNAKE.shape[0]): for j in range(SNAKE.shape[1]): - with self.test_session(): + with self.cached_session(): # If we disconnect any part of the snake except for the endpoints, # there will be 2 components. if SNAKE[i, j] and (i, j) not in [(1, 1), (6, 3)]: @@ -121,27 +121,27 @@ class SegmentationTest(test_util.TensorFlowTestCase): [0, 6, 6, 0], [8, 0, 6, 0], [0, 0, 6, 6]]] # pyformat: disable - with self.test_session(): + with self.cached_session(): self.assertAllEqual( image_ops.connected_components(math_ops.cast( images, dtypes.bool)).eval(), expected) def testZeros(self): - with self.test_session(): + with self.cached_session(): self.assertAllEqual( image_ops.connected_components( array_ops.zeros((100, 20, 50), dtypes.bool)).eval(), np.zeros((100, 20, 50))) def testOnes(self): - with self.test_session(): + with self.cached_session(): self.assertAllEqual( image_ops.connected_components( array_ops.ones((100, 20, 50), dtypes.bool)).eval(), np.tile(np.arange(100)[:, None, None] + 1, [1, 20, 50])) def testOnes_small(self): - with self.test_session(): + with self.cached_session(): self.assertAllEqual( image_ops.connected_components(array_ops.ones((3, 5), dtypes.bool)).eval(), @@ -153,7 +153,7 @@ class SegmentationTest(test_util.TensorFlowTestCase): expected = connected_components_reference_implementation(images) if expected is None: return - with self.test_session(): + with self.cached_session(): self.assertAllEqual( image_ops.connected_components(images).eval(), expected) diff --git a/tensorflow/contrib/image/python/kernel_tests/single_image_random_dot_stereograms_ops_test.py b/tensorflow/contrib/image/python/kernel_tests/single_image_random_dot_stereograms_ops_test.py index 3f4029e558..e5980c53b2 100644 --- a/tensorflow/contrib/image/python/kernel_tests/single_image_random_dot_stereograms_ops_test.py +++ b/tensorflow/contrib/image/python/kernel_tests/single_image_random_dot_stereograms_ops_test.py @@ -47,7 +47,7 @@ class SingleImageRandomDotStereogramsTest(test_util.TensorFlowTestCase): normalize=True) shape_1 = sirds_1.get_shape().as_list() self.assertEqual(shape_1, [768, 1024, 1]) - with self.test_session(): + with self.cached_session(): r_tf_1 = sirds_1.eval() self.assertAllEqual(shape_1, r_tf_1.shape) @@ -59,7 +59,7 @@ class SingleImageRandomDotStereogramsTest(test_util.TensorFlowTestCase): normalize=True) shape_2 = sirds_2.get_shape().as_list() self.assertEqual(shape_2, [768, 1024, 3]) - with self.test_session(): + with self.cached_session(): r_tf_2 = sirds_2.eval() self.assertAllEqual(shape_2, r_tf_2.shape) @@ -73,7 +73,7 @@ class SingleImageRandomDotStereogramsTest(test_util.TensorFlowTestCase): output_image_shape=[1200, 800, 1]) shape_3 = sirds_3.get_shape().as_list() self.assertEqual(shape_3, [800, 1200, 1]) - with self.test_session(): + with self.cached_session(): r_tf_3 = sirds_3.eval() self.assertAllEqual(shape_3, r_tf_3.shape) diff --git a/tensorflow/contrib/image/python/kernel_tests/sparse_image_warp_test.py b/tensorflow/contrib/image/python/kernel_tests/sparse_image_warp_test.py index 0135c66e29..ce9e34df73 100644 --- a/tensorflow/contrib/image/python/kernel_tests/sparse_image_warp_test.py +++ b/tensorflow/contrib/image/python/kernel_tests/sparse_image_warp_test.py @@ -107,7 +107,7 @@ class SparseImageWarpTest(test_util.TensorFlowTestCase): regularization_weight=regularization, num_boundary_points=num_boundary_points) - with self.test_session() as sess: + with self.cached_session() as sess: warped_image, input_image, _ = sess.run( [warped_image_op, input_image_op, flow_field]) @@ -149,7 +149,7 @@ class SparseImageWarpTest(test_util.TensorFlowTestCase): interpolation_order=order, num_boundary_points=num_boundary_points) - with self.test_session() as sess: + with self.cached_session() as sess: warped_image, input_image, flow = sess.run( [warped_image_op, input_image_op, flow_field]) # Check that it moved the pixel correctly. @@ -176,7 +176,7 @@ class SparseImageWarpTest(test_util.TensorFlowTestCase): test_data_dir = test.test_src_dir_path('contrib/image/python/' 'kernel_tests/test_data/') input_file = test_data_dir + 'Yellow_Smiley_Face.png' - with self.test_session() as sess: + with self.cached_session() as sess: input_image = self.load_image(input_file, sess) control_points = np.asarray([[64, 59], [180 - 64, 59], [39, 111], [180 - 39, 111], [90, 143], [58, 134], @@ -199,7 +199,7 @@ class SparseImageWarpTest(test_util.TensorFlowTestCase): control_points_op + control_point_displacements_op, interpolation_order=interpolation_order, num_boundary_points=num_boundary_points) - with self.test_session() as sess: + with self.cached_session() as sess: warped_image = sess.run(warp_op) out_image = np.uint8(warped_image[0, :, :, :] * 255) target_file = ( @@ -244,7 +244,7 @@ class SparseImageWarpTest(test_util.TensorFlowTestCase): opt_func = optimizer.apply_gradients(zip(grad, [image])) init_op = variables.global_variables_initializer() - with self.test_session() as sess: + with self.cached_session() as sess: sess.run(init_op) for _ in range(5): sess.run([loss, opt_func]) |