aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/python/kernel_tests
diff options
context:
space:
mode:
authorGravatar wangsiyu <siyu.wsy@gmail.com>2018-09-25 13:01:50 +0800
committerGravatar wangsiyu <siyu.wsy@gmail.com>2018-09-25 13:01:50 +0800
commit351ef3409fb913067cc26eccb3c6de350e84ca52 (patch)
treec97e38fea0f3a62000128312ebe83415f18debea /tensorflow/python/kernel_tests
parent6dd7a09211cc74d11ff1554624b527c432020cbc (diff)
parentc1644948d23cae271b140d67101c1a386e5495fd (diff)
Merge branch 'master' of github.com:tensorflow/tensorflow into assign_in_part_vars
Diffstat (limited to 'tensorflow/python/kernel_tests')
-rw-r--r--tensorflow/python/kernel_tests/BUILD12
-rw-r--r--tensorflow/python/kernel_tests/basic_gpu_test.py2
-rw-r--r--tensorflow/python/kernel_tests/boosted_trees/prediction_ops_test.py4
-rw-r--r--tensorflow/python/kernel_tests/boosted_trees/quantile_ops_test.py4
-rw-r--r--tensorflow/python/kernel_tests/cond_v2_test.py60
-rw-r--r--tensorflow/python/kernel_tests/control_flow_ops_py_test.py25
-rw-r--r--tensorflow/python/kernel_tests/depthwise_conv_op_test.py4
-rw-r--r--tensorflow/python/kernel_tests/extract_volume_patches_op_test.py131
-rw-r--r--tensorflow/python/kernel_tests/functional_ops_test.py10
-rw-r--r--tensorflow/python/kernel_tests/init_ops_test.py34
-rw-r--r--tensorflow/python/kernel_tests/linalg/linear_operator_addition_test.py24
-rw-r--r--tensorflow/python/kernel_tests/logging_ops_logging_level_test.py6
-rw-r--r--tensorflow/python/kernel_tests/logging_ops_test.py40
-rw-r--r--tensorflow/python/kernel_tests/lookup_ops_test.py70
-rw-r--r--tensorflow/python/kernel_tests/numerics_test.py8
-rw-r--r--tensorflow/python/kernel_tests/reduction_ops_test.py6
-rw-r--r--tensorflow/python/kernel_tests/reduction_ops_test_big.py12
-rw-r--r--tensorflow/python/kernel_tests/rnn_test.py8
-rw-r--r--tensorflow/python/kernel_tests/scalar_test.py2
-rw-r--r--tensorflow/python/kernel_tests/softmax_op_test.py21
-rw-r--r--tensorflow/python/kernel_tests/sparse_tensors_map_ops_test.py2
-rw-r--r--tensorflow/python/kernel_tests/string_format_op_test.py54
-rw-r--r--tensorflow/python/kernel_tests/summary_audio_op_test.py2
-rw-r--r--tensorflow/python/kernel_tests/summary_image_op_test.py4
-rw-r--r--tensorflow/python/kernel_tests/while_v2_test.py18
25 files changed, 361 insertions, 202 deletions
diff --git a/tensorflow/python/kernel_tests/BUILD b/tensorflow/python/kernel_tests/BUILD
index 17831fa5cb..5183e4d30c 100644
--- a/tensorflow/python/kernel_tests/BUILD
+++ b/tensorflow/python/kernel_tests/BUILD
@@ -1663,6 +1663,18 @@ cuda_py_test(
)
cuda_py_test(
+ name = "extract_volume_patches_op_test",
+ size = "small",
+ srcs = ["extract_volume_patches_op_test.py"],
+ additional_deps = [
+ "//third_party/py/numpy",
+ "//tensorflow/python:array_ops",
+ "//tensorflow/python:client_testlib",
+ "//tensorflow/python:framework_for_generated_wrappers",
+ ],
+)
+
+cuda_py_test(
name = "functional_ops_test",
size = "small",
srcs = ["functional_ops_test.py"],
diff --git a/tensorflow/python/kernel_tests/basic_gpu_test.py b/tensorflow/python/kernel_tests/basic_gpu_test.py
index e651fa0070..67e8618198 100644
--- a/tensorflow/python/kernel_tests/basic_gpu_test.py
+++ b/tensorflow/python/kernel_tests/basic_gpu_test.py
@@ -260,7 +260,7 @@ class GpuMultiSessionMemoryTest(test_util.TensorFlowTestCase):
threads = []
results = []
for _ in xrange(n_threads):
- session = self.test_session(graph=ops.Graph(), use_gpu=True)
+ session = self.session(graph=ops.Graph(), use_gpu=True)
results.append(set())
args = (session, results[-1])
threads.append(threading.Thread(target=self._run_session, args=args))
diff --git a/tensorflow/python/kernel_tests/boosted_trees/prediction_ops_test.py b/tensorflow/python/kernel_tests/boosted_trees/prediction_ops_test.py
index 3b28d44cf8..467e33ec87 100644
--- a/tensorflow/python/kernel_tests/boosted_trees/prediction_ops_test.py
+++ b/tensorflow/python/kernel_tests/boosted_trees/prediction_ops_test.py
@@ -934,7 +934,7 @@ class FeatureContribsOpsTest(test_util.TensorFlowTestCase):
For example, this could happen if the final ensemble contains one tree that
got pruned up to the root.
"""
- with self.test_session() as session:
+ with self.cached_session() as session:
tree_ensemble_config = boosted_trees_pb2.TreeEnsemble()
text_format.Merge(
"""
@@ -990,7 +990,7 @@ class FeatureContribsOpsTest(test_util.TensorFlowTestCase):
def testContribsMultipleTreeWhenFirstTreeIsABiasNode(self):
"""Tests case when, after training, first tree contains only a bias node."""
- with self.test_session() as session:
+ with self.cached_session() as session:
tree_ensemble_config = boosted_trees_pb2.TreeEnsemble()
text_format.Merge(
"""
diff --git a/tensorflow/python/kernel_tests/boosted_trees/quantile_ops_test.py b/tensorflow/python/kernel_tests/boosted_trees/quantile_ops_test.py
index c71b8df4ad..e0d46bae83 100644
--- a/tensorflow/python/kernel_tests/boosted_trees/quantile_ops_test.py
+++ b/tensorflow/python/kernel_tests/boosted_trees/quantile_ops_test.py
@@ -78,7 +78,7 @@ class QuantileOpsTest(test_util.TensorFlowTestCase):
self.num_quantiles = constant_op.constant(3, dtype=dtypes.int64)
def testBasicQuantileBucketsSingleResource(self):
- with self.test_session() as sess:
+ with self.cached_session() as sess:
quantile_accumulator_handle = self.create_resource("floats", self.eps,
self.max_elements, 2)
resources.initialize_resources(resources.shared_resources()).run()
@@ -102,7 +102,7 @@ class QuantileOpsTest(test_util.TensorFlowTestCase):
self.assertAllClose(self._feature_1_quantiles, quantiles[1].eval())
def testBasicQuantileBucketsMultipleResources(self):
- with self.test_session() as sess:
+ with self.cached_session() as sess:
quantile_accumulator_handle_0 = self.create_resource("float_0", self.eps,
self.max_elements)
quantile_accumulator_handle_1 = self.create_resource("float_1", self.eps,
diff --git a/tensorflow/python/kernel_tests/cond_v2_test.py b/tensorflow/python/kernel_tests/cond_v2_test.py
index a1efecf28a..377c041675 100644
--- a/tensorflow/python/kernel_tests/cond_v2_test.py
+++ b/tensorflow/python/kernel_tests/cond_v2_test.py
@@ -41,7 +41,7 @@ class CondV2Test(test.TestCase):
def _testCond(self, true_fn, false_fn, train_vals, feed_dict=None):
if not feed_dict:
feed_dict = {}
- with self.test_session(graph=ops.get_default_graph()) as sess:
+ with self.session(graph=ops.get_default_graph()) as sess:
pred = array_ops.placeholder(dtypes.bool, name="pred")
expected = control_flow_ops.cond(pred, true_fn, false_fn, name="expected")
@@ -131,7 +131,7 @@ class CondV2Test(test.TestCase):
def false_fn():
return x + 1
- return cond_v2.cond_v2(pred, true_fn, false_fn, name=name)[0].op
+ return cond_v2.cond_v2(pred, true_fn, false_fn, name=name).op
def testDefaultName(self):
with ops.Graph().as_default():
@@ -382,7 +382,7 @@ class CondV2Test(test.TestCase):
with ops.Graph().as_default():
grads, pred_outer, pred_inner = build_graph()
- with self.test_session(graph=ops.get_default_graph()) as sess:
+ with self.session(graph=ops.get_default_graph()) as sess:
self.assertSequenceEqual(
sess.run(grads, {
pred_outer: True,
@@ -445,7 +445,7 @@ class CondV2Test(test.TestCase):
with ops.Graph().as_default():
grads, pred_outer, pred_inner = build_graph()
- with self.test_session(graph=ops.get_default_graph()) as sess:
+ with self.session(graph=ops.get_default_graph()) as sess:
self.assertSequenceEqual(
sess.run(grads, {
pred_outer: True,
@@ -504,7 +504,7 @@ class CondV2Test(test.TestCase):
with ops.Graph().as_default():
grads, pred_outer, pred_inner = build_graph()
- with self.test_session(graph=ops.get_default_graph()) as sess:
+ with self.session(graph=ops.get_default_graph()) as sess:
self.assertSequenceEqual(
sess.run(grads, {
pred_outer: True,
@@ -569,12 +569,11 @@ class CondV2Test(test.TestCase):
ops.add_to_collection("pred", pred)
cond = cond_v2.cond_v2(pred, true_fn, false_fn, name="cond")
- for c in cond:
- ops.add_to_collection("cond", c)
+ ops.add_to_collection("cond", cond)
meta_graph = saver.export_meta_graph()
with ops.Graph().as_default() as g:
- with self.test_session(graph=g) as sess:
+ with self.session(graph=g) as sess:
saver.import_meta_graph(meta_graph)
x = ops.get_collection("x")[0]
pred = ops.get_collection("pred")[0]
@@ -598,7 +597,7 @@ class CondV2Test(test.TestCase):
def testLowering(self):
with ops.Graph().as_default() as g:
- with self.test_session(graph=g) as sess:
+ with self.session(graph=g) as sess:
out_cond = self._createCond("cond")
run_options = config_pb2.RunOptions(output_partition_graphs=True)
@@ -624,7 +623,7 @@ class CondV2Test(test.TestCase):
"An `If` op was found, but it should be lowered.")
def testLoweringDisabledInXLA(self):
- with self.test_session(graph=ops.Graph()) as sess:
+ with self.session(graph=ops.Graph()) as sess:
# Build the cond_v2 in an XLA context
xla_context = control_flow_ops.XLAControlFlowContext()
xla_context.Enter()
@@ -661,7 +660,7 @@ class CondV2CollectionTest(test.TestCase):
def testCollectionIntValueAccessInCond(self):
"""Read values from graph collections inside of cond_v2."""
with ops.Graph().as_default() as g:
- with self.test_session(graph=g):
+ with self.session(graph=g):
x = 2
y = 5
ops.add_to_collection("x", x)
@@ -672,12 +671,12 @@ class CondV2CollectionTest(test.TestCase):
return math_ops.add(x_const, y_const)
cnd = cond_v2.cond_v2(True, fn, fn)
- self.assertEquals(cnd[0].eval(), 7)
+ self.assertEquals(cnd.eval(), 7)
def testCollectionTensorValueAccessInCond(self):
"""Read tensors from collections inside of cond_v2 & use them."""
with ops.Graph().as_default() as g:
- with self.test_session(graph=g):
+ with self.session(graph=g):
x = constant_op.constant(2)
y = constant_op.constant(5)
ops.add_to_collection("x", x)
@@ -689,12 +688,12 @@ class CondV2CollectionTest(test.TestCase):
return math_ops.add(x_read, y_read)
cnd = cond_v2.cond_v2(math_ops.less(x, y), fn, fn)
- self.assertEquals(cnd[0].eval(), 7)
+ self.assertEquals(cnd.eval(), 7)
def testCollectionIntValueWriteInCond(self):
"""Make sure Int writes to collections work inside of cond_v2."""
with ops.Graph().as_default() as g:
- with self.test_session(graph=g):
+ with self.session(graph=g):
x = constant_op.constant(2)
y = constant_op.constant(5)
def true_fn():
@@ -709,7 +708,7 @@ class CondV2CollectionTest(test.TestCase):
cnd = cond_v2.cond_v2(
True, true_fn,
false_fn)
- self.assertEquals(cnd[0].eval(), 14)
+ self.assertEquals(cnd.eval(), 14)
read_z_collection = ops.get_collection("z")
self.assertEquals(read_z_collection, [7])
@@ -725,7 +724,7 @@ class CondV2ContainerTest(test.TestCase):
"""
self.skipTest("b/113048653")
with ops.Graph().as_default() as g:
- with self.test_session(graph=g):
+ with self.session(graph=g):
v0 = variables.Variable([0])
q0 = data_flow_ops.FIFOQueue(1, dtypes.float32)
@@ -782,10 +781,10 @@ class CondV2ContainerTest(test.TestCase):
with ops.container("l1"):
cnd_true = cond_v2.cond_v2(True, true_fn, false_fn)
- self.assertEquals(cnd_true[0].eval(), 2)
+ self.assertEquals(cnd_true.eval(), 2)
cnd_false = cond_v2.cond_v2(False, true_fn, false_fn)
- self.assertEquals(cnd_false[0].eval(), 6)
+ self.assertEquals(cnd_false.eval(), 6)
v4 = variables.Variable([3])
q4 = data_flow_ops.FIFOQueue(1, dtypes.float32)
@@ -802,7 +801,7 @@ class CondV2ColocationGroupAndDeviceTest(test.TestCase):
def testColocateWithBeforeCond(self):
with ops.Graph().as_default() as g:
- with self.test_session(graph=g):
+ with self.session(graph=g):
a = constant_op.constant([2.0], name="a")
b = constant_op.constant([2.0], name="b")
@@ -813,7 +812,7 @@ class CondV2ColocationGroupAndDeviceTest(test.TestCase):
return c
with ops.colocate_with(a.op):
- self.assertEquals(cond_v2.cond_v2(True, fn, fn)[0].eval(), 3)
+ self.assertEquals(cond_v2.cond_v2(True, fn, fn).eval(), 3)
def fn2():
c = constant_op.constant(3.0)
@@ -822,11 +821,11 @@ class CondV2ColocationGroupAndDeviceTest(test.TestCase):
with ops.colocate_with(a.op):
with ops.colocate_with(b.op):
- self.assertEquals(cond_v2.cond_v2(True, fn2, fn2)[0].eval(), 3)
+ self.assertEquals(cond_v2.cond_v2(True, fn2, fn2).eval(), 3)
def testColocateWithInAndOutOfCond(self):
with ops.Graph().as_default() as g:
- with self.test_session(graph=g):
+ with self.session(graph=g):
a = constant_op.constant([2.0], name="a")
b = constant_op.constant([2.0], name="b")
@@ -838,7 +837,7 @@ class CondV2ColocationGroupAndDeviceTest(test.TestCase):
return c
with ops.colocate_with(a.op):
- self.assertEquals(cond_v2.cond_v2(True, fn2, fn2)[0].eval(), 3)
+ self.assertEquals(cond_v2.cond_v2(True, fn2, fn2).eval(), 3)
d = constant_op.constant([2.0], name="d")
self.assertEqual([b"loc:@a"], d.op.colocation_groups())
@@ -859,7 +858,7 @@ class CondV2ColocationGroupAndDeviceTest(test.TestCase):
with ops.colocate_with(b.op):
c = math_ops.add(a, a, name="c")
return c
- out_cond_2 = cond_v2.cond_v2(True, fn, fn)[0]
+ out_cond_2 = cond_v2.cond_v2(True, fn, fn)
run_options = config_pb2.RunOptions(output_partition_graphs=True)
run_metadata = config_pb2.RunMetadata()
@@ -873,14 +872,15 @@ class CondV2ColocationGroupAndDeviceTest(test.TestCase):
def testDeviceBeforeCond(self):
with ops.Graph().as_default() as g:
- with self.test_session(graph=g):
+ with self.session(graph=g):
+
def fn():
c = constant_op.constant(3.0)
self.assertEqual("/device:CPU:0", c.op.device)
return c
with ops.device("/device:CPU:0"):
- self.assertEquals(cond_v2.cond_v2(True, fn, fn)[0].eval(), 3)
+ self.assertEquals(cond_v2.cond_v2(True, fn, fn).eval(), 3)
def fn2():
c = constant_op.constant(3.0)
@@ -888,7 +888,7 @@ class CondV2ColocationGroupAndDeviceTest(test.TestCase):
return c
with ops.device("/device:GPU:0"):
- self.assertEquals(cond_v2.cond_v2(True, fn2, fn2)[0].eval(), 3)
+ self.assertEquals(cond_v2.cond_v2(True, fn2, fn2).eval(), 3)
def testDeviceInAndOutOfCond(self):
with ops.Graph().as_default() as g:
@@ -902,7 +902,7 @@ class CondV2ColocationGroupAndDeviceTest(test.TestCase):
return c
with ops.device("/device:CPU:0"):
- self.assertEquals(cond_v2.cond_v2(True, fn2, fn2)[0].eval(), 3)
+ self.assertEquals(cond_v2.cond_v2(True, fn2, fn2).eval(), 3)
d = constant_op.constant(4.0)
self.assertEqual("/device:CPU:0", d.op.device)
@@ -921,7 +921,7 @@ class CondV2ColocationGroupAndDeviceTest(test.TestCase):
with ops.device("/device:CPU:0"):
a = constant_op.constant([2.0], name="a")
- out_cond_2 = cond_v2.cond_v2(True, fn, fn)[0]
+ out_cond_2 = cond_v2.cond_v2(True, fn, fn)
run_options = config_pb2.RunOptions(output_partition_graphs=True)
run_metadata = config_pb2.RunMetadata()
diff --git a/tensorflow/python/kernel_tests/control_flow_ops_py_test.py b/tensorflow/python/kernel_tests/control_flow_ops_py_test.py
index ebeabcfe1a..fc4d2a3809 100644
--- a/tensorflow/python/kernel_tests/control_flow_ops_py_test.py
+++ b/tensorflow/python/kernel_tests/control_flow_ops_py_test.py
@@ -422,8 +422,6 @@ class ControlFlowTest(test.TestCase):
self.assertAllEqual(r.values.get_shape(), (2,))
def testCondResource(self):
- if control_flow_ops.ENABLE_COND_V2:
- return unittest.skip("b/111124878 (don't return tuple)")
with self.cached_session():
rv = resource_variable_ops.ResourceVariable(True)
@@ -484,15 +482,12 @@ class ControlFlowTest(test.TestCase):
self.assertAllEqual(11, result)
def testCond_1(self):
- if control_flow_ops.ENABLE_COND_V2:
- return unittest.skip("b/111124878 (don't return tuple)")
self._testCond_1(use_gpu=False)
- self._testCond_1(use_gpu=True)
+ # TODO(b/116526896): Enable GPU tests.
+ # self._testCond_1(use_gpu=True)
def testCond_2(self):
- if control_flow_ops.ENABLE_COND_V2:
- return unittest.skip("b/111124878 (don't return tuple)")
with self.cached_session():
x = constant_op.constant(10)
@@ -503,8 +498,6 @@ class ControlFlowTest(test.TestCase):
self.assertAllEqual(9, result)
def testCond_3(self):
- if control_flow_ops.ENABLE_COND_V2:
- return unittest.skip("b/111124878 (don't return tuple)")
with self.cached_session():
x = constant_op.constant(10)
@@ -556,8 +549,6 @@ class ControlFlowTest(test.TestCase):
self.assertAllEqual(4, count.eval())
def testCond_6(self):
- if control_flow_ops.ENABLE_COND_V2:
- return unittest.skip("b/111124878 (don't return tuple)")
with self.cached_session():
v1 = variables.Variable([7])
@@ -583,8 +574,6 @@ class ControlFlowTest(test.TestCase):
self.assertAllEqual([11, 12], sess.run(r))
def testCondRef(self):
- if control_flow_ops.ENABLE_COND_V2:
- return unittest.skip("b/111124878 (don't return tuple)")
with self.cached_session():
x = gen_state_ops.variable(
@@ -1444,7 +1433,7 @@ class ControlFlowTest(test.TestCase):
def testCondWhile_1(self):
if control_flow_ops.ENABLE_COND_V2:
- return unittest.skip("b/111124878 (don't return tuple)")
+ return unittest.skip("b/113294340 (enable while_v2)")
with self.cached_session():
n = ops.convert_to_tensor(0, name="n")
@@ -1457,7 +1446,7 @@ class ControlFlowTest(test.TestCase):
def testCondWhile_2(self):
if control_flow_ops.ENABLE_COND_V2:
- return unittest.skip("b/111124878 (don't return tuple)")
+ return unittest.skip("b/113294340 (enable while_v2)")
with self.cached_session():
n = ops.convert_to_tensor(0)
@@ -1783,7 +1772,7 @@ class ControlFlowTest(test.TestCase):
else:
self.assertFalse(gpu_dev_name in dev)
- with self.test_session(graph=graph) as sess:
+ with self.session(graph=graph) as sess:
self.assertAllClose(1024.0, sess.run(r))
def testWhileGrad_ColocateGradients(self):
@@ -2633,8 +2622,6 @@ class ControlFlowTest(test.TestCase):
self.assertEqual(5.0, result.eval())
def testOneValueCond(self):
- if control_flow_ops.ENABLE_COND_V2:
- return unittest.skip("b/111124878 (don't return tuple)")
with self.cached_session():
c = array_ops.placeholder(dtypes.int32, shape=[])
@@ -2651,8 +2638,6 @@ class ControlFlowTest(test.TestCase):
self.assertEqual([2], i.eval(feed_dict={c: 0}))
def testExampleCond(self):
- if control_flow_ops.ENABLE_COND_V2:
- return unittest.skip("b/111124878 (don't return tuple)")
with self.cached_session():
x = ops.convert_to_tensor([-2.0, 2.0], name="x")
diff --git a/tensorflow/python/kernel_tests/depthwise_conv_op_test.py b/tensorflow/python/kernel_tests/depthwise_conv_op_test.py
index 5741f2ec64..200da772e5 100644
--- a/tensorflow/python/kernel_tests/depthwise_conv_op_test.py
+++ b/tensorflow/python/kernel_tests/depthwise_conv_op_test.py
@@ -128,7 +128,7 @@ class DepthwiseConv2DTest(test.TestCase):
x2 = [f * 1.0 / filter_size for f in range(1, filter_size + 1)]
ops.reset_default_graph()
graph = ops.get_default_graph()
- with self.test_session(graph=graph, use_gpu=use_gpu) as sess:
+ with self.session(graph=graph, use_gpu=use_gpu) as sess:
tolerance = {
dtypes.float16: 4e-2,
dtypes.float32: 1e-8,
@@ -366,7 +366,7 @@ class DepthwiseConv2DTest(test.TestCase):
filter_data = [x * 1.0 / filter_size for x in range(0, filter_size)]
ops.reset_default_graph()
graph = ops.get_default_graph()
- with self.test_session(graph=graph, use_gpu=use_gpu) as sess:
+ with self.session(graph=graph, use_gpu=use_gpu) as sess:
tolerance = {
dtypes.float16: 4e-0,
dtypes.float32: 8e-4,
diff --git a/tensorflow/python/kernel_tests/extract_volume_patches_op_test.py b/tensorflow/python/kernel_tests/extract_volume_patches_op_test.py
new file mode 100644
index 0000000000..64757a3e07
--- /dev/null
+++ b/tensorflow/python/kernel_tests/extract_volume_patches_op_test.py
@@ -0,0 +1,131 @@
+# Copyright 2018 The TensorFlow Authors. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ==============================================================================
+"""Functional tests for ExtractVolumePatches op."""
+
+from __future__ import absolute_import
+from __future__ import division
+from __future__ import print_function
+
+import numpy as np
+
+from tensorflow.python.framework import constant_op
+from tensorflow.python.ops import array_ops
+from tensorflow.python.platform import test
+
+class ExtractVolumePatches(test.TestCase):
+ """Functional tests for ExtractVolumePatches op."""
+
+ def _VerifyValues(self, image, ksizes, strides, padding, patches):
+ """Tests input-output pairs for the ExtractVolumePatches op.
+
+ Args:
+ image: Input tensor with shape:
+ [batch, in_planes, in_rows, in_cols, depth].
+ ksizes: Patch size specified as: [ksize_planes, ksize_rows, ksize_cols].
+ strides: Output strides, specified as:
+ [stride_planes, stride_rows, stride_cols].
+ padding: Padding type.
+ patches: Expected output.
+
+ Note:
+ rates are not supported as of now.
+ """
+ ksizes = [1] + ksizes + [1]
+ strides = [1] + strides + [1]
+
+ with self.test_session(use_gpu=True):
+ out_tensor = array_ops.extract_volume_patches(
+ constant_op.constant(image),
+ ksizes=ksizes,
+ strides=strides,
+ padding=padding,
+ name="im2col_3d")
+ self.assertAllClose(patches, out_tensor.eval())
+
+ # pylint: disable=bad-whitespace
+ def testKsize1x1x1Stride1x1x1(self):
+ """Verifies that for 1x1x1 kernel the output equals the input."""
+ image = np.arange(2 * 3 * 4 * 5 * 6).reshape([2, 3, 4, 5, 6]) + 1
+ patches = image
+ for padding in ["VALID", "SAME"]:
+ self._VerifyValues(
+ image,
+ ksizes=[1, 1, 1],
+ strides=[1, 1, 1],
+ padding=padding,
+ patches=patches)
+
+ def testKsize1x1x1Stride2x3x4(self):
+ """Test for 1x1x1 kernel and strides."""
+ image = np.arange(6 * 2 * 4 * 5 * 3).reshape([6, 2, 4, 5, 3]) + 1
+ patches = image[:, ::2, ::3, ::4, :]
+ for padding in ["VALID", "SAME"]:
+ self._VerifyValues(
+ image,
+ ksizes=[1, 1, 1],
+ strides=[2, 3, 4],
+ padding=padding,
+ patches=patches)
+
+ def testKsize1x1x2Stride2x2x3(self):
+ """Test for 1x1x2 kernel and strides."""
+ image = np.arange(45).reshape([1, 3, 3, 5, 1]) + 1
+ patches = np.array([[[[[ 1, 2],
+ [ 4, 5]],
+ [[11, 12],
+ [14, 15]]],
+ [[[31, 32],
+ [34, 35]],
+ [[41, 42],
+ [44, 45]]]]])
+ for padding in ["VALID", "SAME"]:
+ self._VerifyValues(
+ image,
+ ksizes=[1, 1, 2],
+ strides=[2, 2, 3],
+ padding=padding,
+ patches=patches)
+
+ def testKsize2x2x2Stride1x1x1Valid(self):
+ """Test for 2x2x2 kernel with VALID padding."""
+ image = np.arange(8).reshape([1, 2, 2, 2, 1]) + 1
+ patches = np.array([[[[[1, 2, 3, 4, 5, 6, 7, 8]]]]])
+ self._VerifyValues(
+ image,
+ ksizes=[2, 2, 2],
+ strides=[1, 1, 1],
+ padding="VALID",
+ patches=patches)
+
+ def testKsize2x2x2Stride1x1x1Same(self):
+ """Test for 2x2x2 kernel with SAME padding."""
+ image = np.arange(8).reshape([1, 2, 2, 2, 1]) + 1
+ patches = np.array([[[[[1, 2, 3, 4, 5, 6, 7, 8],
+ [2, 0, 4, 0, 6, 0, 8, 0]],
+ [[3, 4, 0, 0, 7, 8, 0, 0],
+ [4, 0, 0, 0, 8, 0, 0, 0]]],
+ [[[5, 6, 7, 8, 0, 0, 0, 0],
+ [6, 0, 8, 0, 0, 0, 0, 0]],
+ [[7, 8, 0, 0, 0, 0, 0, 0],
+ [8, 0, 0, 0, 0, 0, 0, 0]]]]])
+ self._VerifyValues(
+ image,
+ ksizes=[2, 2, 2],
+ strides=[1, 1, 1],
+ padding="SAME",
+ patches=patches)
+
+if __name__ == "__main__":
+ test.main()
diff --git a/tensorflow/python/kernel_tests/functional_ops_test.py b/tensorflow/python/kernel_tests/functional_ops_test.py
index e39daf1371..30d11852c7 100644
--- a/tensorflow/python/kernel_tests/functional_ops_test.py
+++ b/tensorflow/python/kernel_tests/functional_ops_test.py
@@ -735,7 +735,7 @@ class FunctionalOpsTest(test.TestCase):
def Run(sess, n):
return sess.run(functional_ops.While([n, 0.], Cond, Body))[1]
- with self.test_session(graph=g, use_gpu=use_gpu) as sess:
+ with self.session(graph=g, use_gpu=use_gpu) as sess:
self.assertAllEqual(Run(sess, 20.), 210.)
self.assertAllEqual(Run(sess, 100.), 5050.)
@@ -765,7 +765,7 @@ class FunctionalOpsTest(test.TestCase):
fetch = outputs[1]
else:
fetch = "my_while:1"
- with self.test_session(graph=g, use_gpu=use_gpu) as sess:
+ with self.session(graph=g, use_gpu=use_gpu) as sess:
return sess.run(fetch)
self.assertAllEqual(Run(20., False), 210.)
@@ -793,7 +793,7 @@ class FunctionalOpsTest(test.TestCase):
def BodyReturnsTooManyArgs(n, x):
return n - 1, x + n, x
- with self.test_session(graph=g, use_gpu=use_gpu):
+ with self.session(graph=g, use_gpu=use_gpu):
with self.assertRaisesRegexp(
errors.InvalidArgumentError,
"Expected a single scalar.*got 2 tensors."):
@@ -818,7 +818,7 @@ class FunctionalOpsTest(test.TestCase):
def Body(n, x):
return n - 1, x + n
- with self.test_session(graph=g, use_gpu=use_gpu) as sess:
+ with self.session(graph=g, use_gpu=use_gpu) as sess:
n = array_ops.placeholder(dtypes.float32)
_, result = functional_ops.While([n, 0.], Cond, Body)
c = constant_op.constant(37.)
@@ -831,7 +831,7 @@ class FunctionalOpsTest(test.TestCase):
def _tfSum(self, use_gpu, rewrite_with_while):
with ops.Graph().as_default() as g:
- with self.test_session(graph=g, use_gpu=use_gpu) as sess:
+ with self.session(graph=g, use_gpu=use_gpu) as sess:
@function.Defun(dtypes.int32, dtypes.float32)
def Body(n, x):
diff --git a/tensorflow/python/kernel_tests/init_ops_test.py b/tensorflow/python/kernel_tests/init_ops_test.py
index 79ce965242..292679e4b9 100644
--- a/tensorflow/python/kernel_tests/init_ops_test.py
+++ b/tensorflow/python/kernel_tests/init_ops_test.py
@@ -522,7 +522,7 @@ class LinSpaceTest(test.TestCase):
def _LinSpace(self, start, stop, num):
# NOTE(touts): Needs to pass a graph to get a new session each time.
with ops.Graph().as_default() as graph:
- with self.test_session(graph=graph, force_gpu=self.force_gpu):
+ with self.session(graph=graph, force_gpu=self.force_gpu):
tf_ans = math_ops.linspace(start, stop, num, name="linspace")
self.assertEqual([num], tf_ans.get_shape())
return tf_ans.eval()
@@ -606,7 +606,7 @@ class OrthogonalInitializerTest(test.TestCase):
def testInvalidShape(self):
init1 = init_ops.orthogonal_initializer()
- with self.test_session(graph=ops.Graph(), use_gpu=True):
+ with self.session(graph=ops.Graph(), use_gpu=True):
self.assertRaises(ValueError, init1, shape=[5])
def testGain(self):
@@ -614,7 +614,7 @@ class OrthogonalInitializerTest(test.TestCase):
for dtype in [dtypes.float32, dtypes.float64]:
init1 = init_ops.orthogonal_initializer(seed=1, dtype=dtype)
init2 = init_ops.orthogonal_initializer(gain=3.14, seed=1, dtype=dtype)
- with self.test_session(graph=ops.Graph(), use_gpu=True):
+ with self.session(graph=ops.Graph(), use_gpu=True):
t1 = init1(shape).eval()
t2 = init2(shape).eval()
return np.allclose(t1, t2 / 3.14, rtol=1e-15, atol=1e-15)
@@ -624,7 +624,7 @@ class OrthogonalInitializerTest(test.TestCase):
for shape in [(10, 10), (10, 9, 8), (100, 5, 5), (50, 40), (40, 50)]:
init = init_ops.orthogonal_initializer(dtype=dtype)
tol = 1e-5 if dtype == dtypes.float32 else 1e-12
- with self.test_session(graph=ops.Graph(), use_gpu=True):
+ with self.session(graph=ops.Graph(), use_gpu=True):
# Check the shape
t = init(shape).eval()
self.assertAllEqual(shape, t.shape)
@@ -663,7 +663,7 @@ class ConvolutionDeltaOrthogonalInitializerTest(test.TestCase):
def testInvalidShape(self):
init1 = init_ops.convolutional_delta_orthogonal()
- with self.test_session(graph=ops.Graph(), use_gpu=True):
+ with self.session(graph=ops.Graph(), use_gpu=True):
self.assertRaises(ValueError, init1, shape=[3, 3, 6, 5])
def testGain(self):
@@ -672,7 +672,7 @@ class ConvolutionDeltaOrthogonalInitializerTest(test.TestCase):
init1 = init_ops.convolutional_delta_orthogonal(seed=1, dtype=dtype)
init2 = init_ops.convolutional_delta_orthogonal(gain=3.14,
seed=1, dtype=dtype)
- with self.test_session(graph=ops.Graph(), use_gpu=True):
+ with self.session(graph=ops.Graph(), use_gpu=True):
t1 = init1(shape).eval()
t2 = init2(shape).eval()
return np.allclose(t1, t2 / 3.14, rtol=1e-15, atol=1e-15)
@@ -763,7 +763,7 @@ class ConvolutionOrthogonal1dInitializerTest(test.TestCase):
def testInvalidShape(self):
init1 = init_ops.convolutional_orthogonal_1d()
- with self.test_session(graph=ops.Graph(), use_gpu=True):
+ with self.session(graph=ops.Graph(), use_gpu=True):
self.assertRaises(ValueError, init1, shape=[3, 6, 5])
def testGain(self):
@@ -772,7 +772,7 @@ class ConvolutionOrthogonal1dInitializerTest(test.TestCase):
init1 = init_ops.convolutional_orthogonal_1d(seed=1, dtype=dtype)
init2 = init_ops.convolutional_orthogonal_1d(gain=3.14,
seed=1, dtype=dtype)
- with self.test_session(graph=ops.Graph(), use_gpu=True):
+ with self.session(graph=ops.Graph(), use_gpu=True):
t1 = init1(shape).eval()
t2 = init2(shape).eval()
return np.allclose(t1, t2 / 3.14, rtol=1e-15, atol=1e-15)
@@ -877,7 +877,7 @@ class ConvolutionOrthogonal2dInitializerTest(test.TestCase):
def testInvalidShape(self):
init1 = init_ops.convolutional_orthogonal_2d()
- with self.test_session(graph=ops.Graph(), use_gpu=True):
+ with self.session(graph=ops.Graph(), use_gpu=True):
self.assertRaises(ValueError, init1, shape=[3, 3, 6, 5])
def testGain(self):
@@ -886,7 +886,7 @@ class ConvolutionOrthogonal2dInitializerTest(test.TestCase):
init1 = init_ops.convolutional_orthogonal_2d(seed=1, dtype=dtype)
init2 = init_ops.convolutional_orthogonal_2d(gain=3.14,
seed=1, dtype=dtype)
- with self.test_session(graph=ops.Graph(), use_gpu=True):
+ with self.session(graph=ops.Graph(), use_gpu=True):
t1 = init1(shape).eval()
t2 = init2(shape).eval()
return np.allclose(t1, t2 / 3.14, rtol=1e-15, atol=1e-15)
@@ -972,7 +972,7 @@ class ConvolutionOrthogonal3dInitializerTest(test.TestCase):
def testInvalidShape(self):
init1 = init_ops.convolutional_orthogonal_3d()
- with self.test_session(graph=ops.Graph(), use_gpu=True):
+ with self.session(graph=ops.Graph(), use_gpu=True):
self.assertRaises(ValueError, init1, shape=[3, 3, 3, 6, 5])
def testGain(self):
@@ -981,7 +981,7 @@ class ConvolutionOrthogonal3dInitializerTest(test.TestCase):
init1 = init_ops.convolutional_orthogonal_3d(seed=1, dtype=dtype)
init2 = init_ops.convolutional_orthogonal_3d(gain=3.14,
seed=1, dtype=dtype)
- with self.test_session(graph=ops.Graph(), use_gpu=True):
+ with self.session(graph=ops.Graph(), use_gpu=True):
t1 = init1(shape).eval()
t2 = init2(shape).eval()
return np.allclose(t1, t2 / 3.14, rtol=1e-15, atol=1e-15)
@@ -1080,7 +1080,7 @@ class IdentityInitializerTest(test.TestCase):
def testInvalidShape(self):
init = init_ops.identity_initializer()
- with self.test_session(graph=ops.Graph(), use_gpu=True):
+ with self.session(graph=ops.Graph(), use_gpu=True):
self.assertRaises(ValueError, init, shape=[5, 7, 7])
self.assertRaises(ValueError, init, shape=[5])
self.assertRaises(ValueError, init, shape=[])
@@ -1088,7 +1088,7 @@ class IdentityInitializerTest(test.TestCase):
def testNonSquare(self):
init = init_ops.identity_initializer()
shape = (10, 5)
- with self.test_session(graph=ops.Graph(), use_gpu=True):
+ with self.session(graph=ops.Graph(), use_gpu=True):
self.assertAllClose(init(shape).eval(), np.eye(*shape))
def testGain(self):
@@ -1096,16 +1096,16 @@ class IdentityInitializerTest(test.TestCase):
for dtype in [dtypes.float32, dtypes.float64]:
init_default = init_ops.identity_initializer(dtype=dtype)
init_custom = init_ops.identity_initializer(gain=0.9, dtype=dtype)
- with self.test_session(graph=ops.Graph(), use_gpu=True):
+ with self.session(graph=ops.Graph(), use_gpu=True):
self.assertAllClose(init_default(shape).eval(), np.eye(*shape))
- with self.test_session(graph=ops.Graph(), use_gpu=True):
+ with self.session(graph=ops.Graph(), use_gpu=True):
self.assertAllClose(init_custom(shape).eval(), np.eye(*shape) * 0.9)
def testPartitions(self):
shape = (10, 10)
init = init_ops.identity_initializer()
partitioner = partitioned_variables.variable_axis_size_partitioner(1)
- with self.test_session(graph=ops.Graph(), use_gpu=True):
+ with self.session(graph=ops.Graph(), use_gpu=True):
with variable_scope.variable_scope(
"foo", partitioner=partitioner, initializer=init):
v = array_ops.identity(variable_scope.get_variable("bar", shape=shape))
diff --git a/tensorflow/python/kernel_tests/linalg/linear_operator_addition_test.py b/tensorflow/python/kernel_tests/linalg/linear_operator_addition_test.py
index 7c79fedf65..cf56168d63 100644
--- a/tensorflow/python/kernel_tests/linalg/linear_operator_addition_test.py
+++ b/tensorflow/python/kernel_tests/linalg/linear_operator_addition_test.py
@@ -76,7 +76,7 @@ class LinearOperatorAdditionCorrectnessTest(test.TestCase):
[1., 1.], is_positive_definite=True, name="A")
op_b = linalg.LinearOperatorDiag(
[2., 2.], is_positive_definite=True, name="B")
- with self.test_session():
+ with self.cached_session():
op_sum = add_operators([op_a, op_b])
self.assertEqual(1, len(op_sum))
op = op_sum[0]
@@ -98,7 +98,7 @@ class LinearOperatorAdditionCorrectnessTest(test.TestCase):
[2., 2.], is_positive_definite=True, name="op2")
op3 = linalg.LinearOperatorDiag(
[3., 3.], is_positive_definite=True, name="op3")
- with self.test_session():
+ with self.cached_session():
op_sum = add_operators([op1, op2, op3])
self.assertEqual(1, len(op_sum))
op = op_sum[0]
@@ -121,7 +121,7 @@ class LinearOperatorAdditionCorrectnessTest(test.TestCase):
name="tril")
op3 = linalg.LinearOperatorDiag(
[3., 3.], is_non_singular=True, name="diag_b")
- with self.test_session():
+ with self.cached_session():
op_sum = add_operators([op1, op2, op3])
self.assertEqual(1, len(op_sum))
op = op_sum[0]
@@ -143,7 +143,7 @@ class LinearOperatorAdditionCorrectnessTest(test.TestCase):
op2 = linalg.LinearOperatorLowerTriangular(
[[2., 0.], [1.5, 2.]], name="tril")
op3 = linalg.LinearOperatorDiag([3., 3.], name="diag_b")
- with self.test_session():
+ with self.cached_session():
op_sum = add_operators([op0, op1, op2, op3], operator_name="my_operator")
self.assertEqual(1, len(op_sum))
op = op_sum[0]
@@ -233,7 +233,7 @@ class LinearOperatorOrderOfAdditionTest(test.TestCase):
self.assertEqual(2, len(op_sum))
found_diag = False
found_tril = False
- with self.test_session():
+ with self.cached_session():
for op in op_sum:
if isinstance(op, linalg.LinearOperatorDiag):
found_diag = True
@@ -273,7 +273,7 @@ class AddAndReturnScaledIdentityTest(test.TestCase):
operator = self._adder.add(id1, id2, "my_operator", hints)
self.assertIsInstance(operator, linalg.LinearOperatorScaledIdentity)
- with self.test_session():
+ with self.cached_session():
self.assertAllClose(2 *
linalg_ops.eye(num_rows=2, batch_shape=[3]).eval(),
operator.to_dense().eval())
@@ -291,7 +291,7 @@ class AddAndReturnScaledIdentityTest(test.TestCase):
operator = self._adder.add(id1, id2, "my_operator", hints)
self.assertIsInstance(operator, linalg.LinearOperatorScaledIdentity)
- with self.test_session():
+ with self.cached_session():
self.assertAllClose(3.2 *
linalg_ops.eye(num_rows=2, batch_shape=[3]).eval(),
operator.to_dense().eval())
@@ -310,7 +310,7 @@ class AddAndReturnScaledIdentityTest(test.TestCase):
operator = self._adder.add(id1, id2, "my_operator", hints)
self.assertIsInstance(operator, linalg.LinearOperatorScaledIdentity)
- with self.test_session():
+ with self.cached_session():
self.assertAllClose(1.2 *
linalg_ops.eye(num_rows=2, batch_shape=[3]).eval(),
operator.to_dense().eval())
@@ -334,7 +334,7 @@ class AddAndReturnDiagTest(test.TestCase):
operator = self._adder.add(id1, id2, "my_operator", hints)
self.assertIsInstance(operator, linalg.LinearOperatorDiag)
- with self.test_session():
+ with self.cached_session():
self.assertAllClose(2 *
linalg_ops.eye(num_rows=2, batch_shape=[3]).eval(),
operator.to_dense().eval())
@@ -354,7 +354,7 @@ class AddAndReturnDiagTest(test.TestCase):
operator = self._adder.add(op1, op2, "my_operator", hints)
self.assertIsInstance(operator, linalg.LinearOperatorDiag)
- with self.test_session():
+ with self.cached_session():
self.assertAllClose(
linalg.LinearOperatorDiag(diag1 + diag2).to_dense().eval(),
operator.to_dense().eval())
@@ -379,7 +379,7 @@ class AddAndReturnTriLTest(test.TestCase):
operator = self._adder.add(diag, tril, "my_operator", hints)
self.assertIsInstance(operator, linalg.LinearOperatorLowerTriangular)
- with self.test_session():
+ with self.cached_session():
self.assertAllClose([[11., 0.], [30., 2.]], operator.to_dense().eval())
self.assertTrue(operator.is_positive_definite)
self.assertTrue(operator.is_non_singular)
@@ -401,7 +401,7 @@ class AddAndReturnMatrixTest(test.TestCase):
operator = self._adder.add(diag1, diag2, "my_operator", hints)
self.assertIsInstance(operator, linalg.LinearOperatorFullMatrix)
- with self.test_session():
+ with self.cached_session():
self.assertAllClose([[0., 0.], [0., 5.]], operator.to_dense().eval())
self.assertFalse(operator.is_positive_definite)
self.assertFalse(operator.is_non_singular)
diff --git a/tensorflow/python/kernel_tests/logging_ops_logging_level_test.py b/tensorflow/python/kernel_tests/logging_ops_logging_level_test.py
index 252090b7bd..0e8197dccb 100644
--- a/tensorflow/python/kernel_tests/logging_ops_logging_level_test.py
+++ b/tensorflow/python/kernel_tests/logging_ops_logging_level_test.py
@@ -31,7 +31,7 @@ class PrintV2LoggingLevelTest(test.TestCase):
@test_util.run_in_graph_and_eager_modes()
def testPrintOneTensorLogInfo(self):
- with self.test_session():
+ with self.cached_session():
tensor = math_ops.range(10)
with self.captureWritesToStream(sys.stderr) as printed:
print_op = logging_ops.print_v2(
@@ -43,7 +43,7 @@ class PrintV2LoggingLevelTest(test.TestCase):
@test_util.run_in_graph_and_eager_modes()
def testPrintOneTensorLogWarning(self):
- with self.test_session():
+ with self.cached_session():
tensor = math_ops.range(10)
with self.captureWritesToStream(sys.stderr) as printed:
print_op = logging_ops.print_v2(
@@ -55,7 +55,7 @@ class PrintV2LoggingLevelTest(test.TestCase):
@test_util.run_in_graph_and_eager_modes()
def testPrintOneTensorLogError(self):
- with self.test_session():
+ with self.cached_session():
tensor = math_ops.range(10)
with self.captureWritesToStream(sys.stderr) as printed:
print_op = logging_ops.print_v2(
diff --git a/tensorflow/python/kernel_tests/logging_ops_test.py b/tensorflow/python/kernel_tests/logging_ops_test.py
index b24a0d0f9b..4beddd00bb 100644
--- a/tensorflow/python/kernel_tests/logging_ops_test.py
+++ b/tensorflow/python/kernel_tests/logging_ops_test.py
@@ -69,7 +69,7 @@ class PrintV2Test(test.TestCase):
@test_util.run_in_graph_and_eager_modes()
def testPrintOneTensor(self):
- with self.test_session():
+ with self.cached_session():
tensor = math_ops.range(10)
with self.captureWritesToStream(sys.stderr) as printed:
print_op = logging_ops.print_v2(tensor)
@@ -80,7 +80,7 @@ class PrintV2Test(test.TestCase):
@test_util.run_in_graph_and_eager_modes()
def testPrintOneTensorVarySummarize(self):
- with self.test_session():
+ with self.cached_session():
tensor = math_ops.range(10)
with self.captureWritesToStream(sys.stderr) as printed:
print_op = logging_ops.print_v2(tensor, summarize=1)
@@ -89,7 +89,7 @@ class PrintV2Test(test.TestCase):
expected = "[0 ... 9]"
self.assertTrue((expected + "\n") in printed.contents())
- with self.test_session():
+ with self.cached_session():
tensor = math_ops.range(10)
with self.captureWritesToStream(sys.stderr) as printed:
print_op = logging_ops.print_v2(tensor, summarize=2)
@@ -98,7 +98,7 @@ class PrintV2Test(test.TestCase):
expected = "[0 1 ... 8 9]"
self.assertTrue((expected + "\n") in printed.contents())
- with self.test_session():
+ with self.cached_session():
tensor = math_ops.range(10)
with self.captureWritesToStream(sys.stderr) as printed:
print_op = logging_ops.print_v2(tensor, summarize=3)
@@ -107,7 +107,7 @@ class PrintV2Test(test.TestCase):
expected = "[0 1 2 ... 7 8 9]"
self.assertTrue((expected + "\n") in printed.contents())
- with self.test_session():
+ with self.cached_session():
tensor = math_ops.range(10)
with self.captureWritesToStream(sys.stderr) as printed:
print_op = logging_ops.print_v2(tensor, summarize=-1)
@@ -118,7 +118,7 @@ class PrintV2Test(test.TestCase):
@test_util.run_in_graph_and_eager_modes()
def testPrintOneVariable(self):
- with self.test_session():
+ with self.cached_session():
var = variables.Variable(math_ops.range(10))
if not context.executing_eagerly():
variables.global_variables_initializer().run()
@@ -130,7 +130,7 @@ class PrintV2Test(test.TestCase):
@test_util.run_in_graph_and_eager_modes()
def testPrintTwoVariablesInStructWithAssignAdd(self):
- with self.test_session():
+ with self.cached_session():
var_one = variables.Variable(2.14)
plus_one = var_one.assign_add(1.0)
var_two = variables.Variable(math_ops.range(10))
@@ -145,7 +145,7 @@ class PrintV2Test(test.TestCase):
@test_util.run_in_graph_and_eager_modes()
def testPrintTwoTensors(self):
- with self.test_session():
+ with self.cached_session():
tensor = math_ops.range(10)
with self.captureWritesToStream(sys.stderr) as printed:
print_op = logging_ops.print_v2(tensor, tensor * 10)
@@ -155,7 +155,7 @@ class PrintV2Test(test.TestCase):
@test_util.run_in_graph_and_eager_modes()
def testPrintPlaceholderGeneration(self):
- with self.test_session():
+ with self.cached_session():
tensor = math_ops.range(10)
with self.captureWritesToStream(sys.stderr) as printed:
print_op = logging_ops.print_v2("{}6", {"{}": tensor * 10})
@@ -165,7 +165,7 @@ class PrintV2Test(test.TestCase):
@test_util.run_in_graph_and_eager_modes()
def testPrintNoTensors(self):
- with self.test_session():
+ with self.cached_session():
with self.captureWritesToStream(sys.stderr) as printed:
print_op = logging_ops.print_v2(23, [23, 5], {"6": 12})
self.evaluate(print_op)
@@ -174,7 +174,7 @@ class PrintV2Test(test.TestCase):
@test_util.run_in_graph_and_eager_modes()
def testPrintFloatScalar(self):
- with self.test_session():
+ with self.cached_session():
tensor = ops.convert_to_tensor(434.43)
with self.captureWritesToStream(sys.stderr) as printed:
print_op = logging_ops.print_v2(tensor)
@@ -184,7 +184,7 @@ class PrintV2Test(test.TestCase):
@test_util.run_in_graph_and_eager_modes()
def testPrintStringScalar(self):
- with self.test_session():
+ with self.cached_session():
tensor = ops.convert_to_tensor("scalar")
with self.captureWritesToStream(sys.stderr) as printed:
print_op = logging_ops.print_v2(tensor)
@@ -194,7 +194,7 @@ class PrintV2Test(test.TestCase):
@test_util.run_in_graph_and_eager_modes()
def testPrintComplexTensorStruct(self):
- with self.test_session():
+ with self.cached_session():
tensor = math_ops.range(10)
small_tensor = constant_op.constant([0.3, 12.4, -16.1])
big_tensor = math_ops.mul(tensor, 10)
@@ -214,7 +214,7 @@ class PrintV2Test(test.TestCase):
@test_util.run_in_graph_and_eager_modes()
def testPrintSparseTensor(self):
- with self.test_session():
+ with self.cached_session():
ind = [[0, 0], [1, 0], [1, 3], [4, 1], [1, 4], [3, 2], [3, 3]]
val = [0, 10, 13, 4, 14, 32, 33]
shape = [5, 6]
@@ -238,7 +238,7 @@ class PrintV2Test(test.TestCase):
@test_util.run_in_graph_and_eager_modes()
def testPrintSparseTensorInDataStruct(self):
- with self.test_session():
+ with self.cached_session():
ind = [[0, 0], [1, 0], [1, 3], [4, 1], [1, 4], [3, 2], [3, 3]]
val = [0, 10, 13, 4, 14, 32, 33]
shape = [5, 6]
@@ -262,7 +262,7 @@ class PrintV2Test(test.TestCase):
@test_util.run_in_graph_and_eager_modes()
def testPrintOneTensorStdout(self):
- with self.test_session():
+ with self.cached_session():
tensor = math_ops.range(10)
with self.captureWritesToStream(sys.stdout) as printed:
print_op = logging_ops.print_v2(
@@ -273,7 +273,7 @@ class PrintV2Test(test.TestCase):
@test_util.run_in_graph_and_eager_modes()
def testInvalidOutputStreamRaisesError(self):
- with self.test_session():
+ with self.cached_session():
tensor = math_ops.range(10)
with self.assertRaises(ValueError):
print_op = logging_ops.print_v2(
@@ -281,13 +281,13 @@ class PrintV2Test(test.TestCase):
self.evaluate(print_op)
def testPrintOpName(self):
- with self.test_session():
+ with self.cached_session():
tensor = math_ops.range(10)
print_op = logging_ops.print_v2(tensor, name="print_name")
self.assertEqual(print_op.name, "print_name")
def testNoDuplicateFormatOpGraphModeAfterExplicitFormat(self):
- with self.test_session():
+ with self.cached_session():
tensor = math_ops.range(10)
formatted_string = string_ops.string_format("{}", tensor)
print_op = logging_ops.print_v2(formatted_string)
@@ -298,7 +298,7 @@ class PrintV2Test(test.TestCase):
self.assertEqual(len(format_ops), 1)
def testPrintOneTensorEagerOnOpCreate(self):
- with self.test_session():
+ with self.cached_session():
with context.eager_mode():
tensor = math_ops.range(10)
expected = "[0 1 2 ... 7 8 9]"
diff --git a/tensorflow/python/kernel_tests/lookup_ops_test.py b/tensorflow/python/kernel_tests/lookup_ops_test.py
index 38b14e34cc..6791a03e2e 100644
--- a/tensorflow/python/kernel_tests/lookup_ops_test.py
+++ b/tensorflow/python/kernel_tests/lookup_ops_test.py
@@ -21,6 +21,7 @@ import os
import numpy as np
from tensorflow.python.client import session
+from tensorflow.python.eager import context
from tensorflow.python.framework import constant_op
from tensorflow.python.framework import dtypes
from tensorflow.python.framework import errors_impl
@@ -29,6 +30,7 @@ from tensorflow.python.framework import sparse_tensor
from tensorflow.python.framework import test_util
from tensorflow.python.ops import array_ops
from tensorflow.python.ops import lookup_ops
+from tensorflow.python.ops import variables
from tensorflow.python.platform import test
from tensorflow.python.training import server_lib
@@ -53,6 +55,12 @@ class HashTableOpTest(test.TestCase):
result = output.eval()
self.assertAllEqual([0, 1, -1], result)
+ exported_keys_tensor, exported_values_tensor = table.export()
+
+ self.assertItemsEqual([b"brain", b"salad", b"surgery"],
+ exported_keys_tensor.eval())
+ self.assertItemsEqual([0, 1, 2], exported_values_tensor.eval())
+
def testHashTableFindHighRank(self):
with self.cached_session():
default_val = -1
@@ -181,6 +189,11 @@ class HashTableOpTest(test.TestCase):
lookup_ops.KeyValueTensorInitializer(keys, values), default_val)
table.init.run()
+ # Ref types do not produce a lookup signature mismatch.
+ input_string_ref = variables.Variable("brain")
+ variables.global_variables_initializer().run()
+ self.assertEqual(0, table.lookup(input_string_ref).eval())
+
input_string = constant_op.constant([1, 2, 3], dtypes.int64)
with self.assertRaises(TypeError):
table.lookup(input_string)
@@ -261,6 +274,21 @@ class HashTableOpTest(test.TestCase):
table.init.run()
self.assertAllEqual(3, table.size().eval())
+ def testHashTableInt32String(self):
+ with self.cached_session():
+ default_val = "n/a"
+ keys = constant_op.constant([0, 1, 2], dtypes.int32)
+ values = constant_op.constant(["brain", "salad", "surgery"])
+ table = lookup_ops.HashTable(
+ lookup_ops.KeyValueTensorInitializer(keys, values), default_val)
+ table.init.run()
+
+ input_tensor = constant_op.constant([0, 1, -1])
+ output = table.lookup(input_tensor)
+
+ result = output.eval()
+ self.assertAllEqual([b"brain", b"salad", b"n/a"], result)
+
class IndexTableFromFile(test.TestCase):
@@ -335,6 +363,7 @@ class IndexTableFromFile(test.TestCase):
ids = table.lookup(constant_op.constant(["salad", "surgery", "tarkus"]))
self.assertRaises(errors_impl.OpError, ids.eval)
+
feed_dict = {vocabulary_placeholder.name: vocabulary_file}
lookup_ops.tables_initializer().run(feed_dict=feed_dict)
self.assertAllEqual((1, 2, 3), ids.eval())
@@ -531,15 +560,22 @@ class KeyValueTensorInitializerTest(test.TestCase):
class IndexTableFromTensor(test.TestCase):
+ @test_util.run_in_graph_and_eager_modes
def test_index_table_from_tensor_with_tensor_init(self):
- with self.cached_session():
+ table = lookup_ops.index_table_from_tensor(
+ vocabulary_list=("brain", "salad", "surgery"), num_oov_buckets=1)
+
+ if not context.executing_eagerly():
+ with self.assertRaises(errors_impl.OpError):
+ self.evaluate(
+ table.lookup(constant_op.constant(("salad", "surgery", "tarkus"))))
+ else:
+ # Reinitializing a table in eager should work.
table = lookup_ops.index_table_from_tensor(
vocabulary_list=("brain", "salad", "surgery"), num_oov_buckets=1)
- ids = table.lookup(constant_op.constant(("salad", "surgery", "tarkus")))
-
- self.assertRaises(errors_impl.OpError, ids.eval)
- lookup_ops.tables_initializer().run()
- self.assertAllEqual((1, 2, 3), ids.eval())
+ self.evaluate(lookup_ops.tables_initializer())
+ ids = table.lookup(constant_op.constant(("salad", "surgery", "tarkus")))
+ self.assertAllEqual((1, 2, 3), self.evaluate(ids))
def test_int32_index_table_from_tensor_with_tensor_init(self):
with self.cached_session():
@@ -761,22 +797,20 @@ class InitializeTableFromFileOpTest(test.TestCase):
f.write("\n".join(values) + "\n")
return vocabulary_file
+ @test_util.run_in_graph_and_eager_modes
def testInitializeStringTable(self):
vocabulary_file = self._createVocabFile("one_column_1.txt")
+ default_value = -1
+ table = lookup_ops.HashTable(
+ lookup_ops.TextFileInitializer(
+ vocabulary_file, dtypes.string, lookup_ops.TextFileIndex.WHOLE_LINE,
+ dtypes.int64, lookup_ops.TextFileIndex.LINE_NUMBER), default_value)
+ self.evaluate(table.init)
- with self.cached_session():
- default_value = -1
- table = lookup_ops.HashTable(
- lookup_ops.TextFileInitializer(
- vocabulary_file, dtypes.string,
- lookup_ops.TextFileIndex.WHOLE_LINE, dtypes.int64,
- lookup_ops.TextFileIndex.LINE_NUMBER), default_value)
- table.init.run()
-
- output = table.lookup(constant_op.constant(["brain", "salad", "tank"]))
+ output = table.lookup(constant_op.constant(["brain", "salad", "tank"]))
- result = output.eval()
- self.assertAllEqual([0, 1, -1], result)
+ result = self.evaluate(output)
+ self.assertAllEqual([0, 1, -1], result)
def testInitializeInt64Table(self):
vocabulary_file = self._createVocabFile(
diff --git a/tensorflow/python/kernel_tests/numerics_test.py b/tensorflow/python/kernel_tests/numerics_test.py
index 89ada8430e..6cc70f7c89 100644
--- a/tensorflow/python/kernel_tests/numerics_test.py
+++ b/tensorflow/python/kernel_tests/numerics_test.py
@@ -66,7 +66,7 @@ class VerifyTensorAllFiniteTest(test.TestCase):
class NumericsTest(test.TestCase):
def testInf(self):
- with self.test_session(graph=ops.Graph()):
+ with self.session(graph=ops.Graph()):
t1 = constant_op.constant(1.0)
t2 = constant_op.constant(0.0)
a = math_ops.div(t1, t2)
@@ -76,7 +76,7 @@ class NumericsTest(test.TestCase):
a.eval()
def testNaN(self):
- with self.test_session(graph=ops.Graph()):
+ with self.session(graph=ops.Graph()):
t1 = constant_op.constant(0.0)
t2 = constant_op.constant(0.0)
a = math_ops.div(t1, t2)
@@ -86,7 +86,7 @@ class NumericsTest(test.TestCase):
a.eval()
def testBoth(self):
- with self.test_session(graph=ops.Graph()):
+ with self.session(graph=ops.Graph()):
t1 = constant_op.constant([1.0, 0.0])
t2 = constant_op.constant([0.0, 0.0])
a = math_ops.div(t1, t2)
@@ -96,7 +96,7 @@ class NumericsTest(test.TestCase):
a.eval()
def testPassThrough(self):
- with self.test_session(graph=ops.Graph()):
+ with self.session(graph=ops.Graph()):
t1 = constant_op.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3])
checked = array_ops.check_numerics(t1, message="pass through test")
value = checked.eval()
diff --git a/tensorflow/python/kernel_tests/reduction_ops_test.py b/tensorflow/python/kernel_tests/reduction_ops_test.py
index 496a452a03..248036a82a 100644
--- a/tensorflow/python/kernel_tests/reduction_ops_test.py
+++ b/tensorflow/python/kernel_tests/reduction_ops_test.py
@@ -212,7 +212,7 @@ class SumReductionTest(BaseReductionTest):
arr = np.ones([68000], dtype=np.float16)
- with self.test_session(graph=ops.Graph(), use_gpu=True) as sess:
+ with self.session(graph=ops.Graph(), use_gpu=True) as sess:
tf_arr = variables.Variable(arr)
variables.global_variables_initializer().run()
tf_mean = math_ops.reduce_mean(tf_arr, 0, False)
@@ -235,7 +235,7 @@ class SumReductionTest(BaseReductionTest):
col_sum = np.sum(arr, axis=0)
row_sum = np.sum(arr, axis=1)
- with self.test_session(graph=ops.Graph(), use_gpu=True) as sess:
+ with self.session(graph=ops.Graph(), use_gpu=True) as sess:
tf_row_sum = self._tf_reduce(arr, 1, False)
tf_col_sum = self._tf_reduce(arr, 0, False)
tf_out_row, tf_out_col = sess.run([tf_row_sum, tf_col_sum])
@@ -249,7 +249,7 @@ class SumReductionTest(BaseReductionTest):
sum_y = np.sum(arr, axis=1)
sum_xz = np.sum(arr, axis=(0, 2))
- with self.test_session(graph=ops.Graph(), use_gpu=True) as sess:
+ with self.session(graph=ops.Graph(), use_gpu=True) as sess:
tf_sum_xz = self._tf_reduce(arr, [0, 2], False)
tf_sum_y = self._tf_reduce(arr, 1, False)
tf_out_sum_xz, tf_out_sum_y = sess.run([tf_sum_xz, tf_sum_y])
diff --git a/tensorflow/python/kernel_tests/reduction_ops_test_big.py b/tensorflow/python/kernel_tests/reduction_ops_test_big.py
index d70360775a..1e8524f72a 100644
--- a/tensorflow/python/kernel_tests/reduction_ops_test_big.py
+++ b/tensorflow/python/kernel_tests/reduction_ops_test_big.py
@@ -63,7 +63,7 @@ class BigReductionTest(BaseReductionTest):
row_sum = np.ones([size_x], dtype=np.float32) * size_y
full_sum = np.ones([], dtype=np.float32) * size_x * size_y
- with self.test_session(graph=ops.Graph(), use_gpu=True) as sess:
+ with self.session(graph=ops.Graph(), use_gpu=True) as sess:
tf_row_sum = self._tf_reduce_sum(arr, 1, False)
tf_col_sum = self._tf_reduce_sum(arr, 0, False)
tf_full_sum = self._tf_reduce_sum(arr, [0, 1], False)
@@ -81,7 +81,7 @@ class BigReductionTest(BaseReductionTest):
sum_y = np.ones([size_x, size_z], dtype=np.float32)
sum_xz = np.ones([size_y], dtype=np.float32)
- with self.test_session(graph=ops.Graph(), use_gpu=True) as sess:
+ with self.session(graph=ops.Graph(), use_gpu=True) as sess:
tf_sum_xz = self._tf_reduce_mean(arr, [0, 2], False)
tf_sum_y = self._tf_reduce_mean(arr, 1, False)
tf_out_sum_xz, tf_out_sum_y = sess.run([tf_sum_xz, tf_sum_y])
@@ -106,7 +106,7 @@ class BigReductionTest(BaseReductionTest):
row_max = np.max(arr, axis=1)
full_max = np.max(col_max)
- with self.test_session(graph=ops.Graph(), use_gpu=True) as sess:
+ with self.session(graph=ops.Graph(), use_gpu=True) as sess:
tf_row_max = self._tf_reduce_max(arr, 1, False)
tf_col_max = self._tf_reduce_max(arr, 0, False)
tf_full_max = self._tf_reduce_max(arr, [0, 1], False)
@@ -125,7 +125,7 @@ class BigReductionTest(BaseReductionTest):
sum_y = np.max(arr, axis=1)
sum_xz = np.max(arr, axis=(0, 2))
- with self.test_session(graph=ops.Graph(), use_gpu=True) as sess:
+ with self.session(graph=ops.Graph(), use_gpu=True) as sess:
tf_sum_xz = self._tf_reduce_max(arr, [0, 2], False)
tf_sum_y = self._tf_reduce_max(arr, 1, False)
tf_out_sum_xz, tf_out_sum_y = sess.run([tf_sum_xz, tf_sum_y])
@@ -149,7 +149,7 @@ class BigReductionTest(BaseReductionTest):
row_sum = np.ones([size_x], dtype=np.bool)
full_sum = np.ones([1], dtype=np.bool).reshape([])
- with self.test_session(graph=ops.Graph(), use_gpu=True) as sess:
+ with self.session(graph=ops.Graph(), use_gpu=True) as sess:
tf_row_sum = self._tf_reduce_all(arr, 1, False)
tf_col_sum = self._tf_reduce_all(arr, 0, False)
tf_full_sum = self._tf_reduce_all(arr, [0, 1], False)
@@ -167,7 +167,7 @@ class BigReductionTest(BaseReductionTest):
sum_y = np.ones([size_x, size_z], dtype=np.bool)
sum_xz = np.ones([size_y], dtype=np.bool)
- with self.test_session(graph=ops.Graph(), use_gpu=True) as sess:
+ with self.session(graph=ops.Graph(), use_gpu=True) as sess:
tf_sum_xz = self._tf_reduce_all(arr, [0, 2], False)
tf_sum_y = self._tf_reduce_all(arr, 1, False)
tf_out_sum_xz, tf_out_sum_y = sess.run([tf_sum_xz, tf_sum_y])
diff --git a/tensorflow/python/kernel_tests/rnn_test.py b/tensorflow/python/kernel_tests/rnn_test.py
index a28cdc3b26..05ad9f6336 100644
--- a/tensorflow/python/kernel_tests/rnn_test.py
+++ b/tensorflow/python/kernel_tests/rnn_test.py
@@ -516,7 +516,7 @@ class RNNTest(test.TestCase):
fix_weights_generator.build((None, input_shape))
weights = fix_weights_generator.get_weights()
- with self.test_session(graph=ops_lib.Graph()) as sess:
+ with self.session(graph=ops_lib.Graph()) as sess:
inputs = array_ops.placeholder(
dtypes.float32, shape=(None, timestep, input_shape))
cell = keras.layers.SimpleRNNCell(output_shape)
@@ -524,7 +524,7 @@ class RNNTest(test.TestCase):
cell, inputs, dtype=dtypes.float32)
cell.set_weights(weights)
[tf_out, tf_state] = sess.run([tf_out, tf_state], {inputs: x_train})
- with self.test_session(graph=ops_lib.Graph()) as sess:
+ with self.session(graph=ops_lib.Graph()) as sess:
k_input = keras.Input(shape=(timestep, input_shape),
dtype=dtypes.float32)
cell = keras.layers.SimpleRNNCell(output_shape)
@@ -536,7 +536,7 @@ class RNNTest(test.TestCase):
self.assertAllClose(tf_state, k_state)
def testBasicLSTMCellInterchangeWithLSTMCell(self):
- with self.test_session(graph=ops_lib.Graph()) as sess:
+ with self.session(graph=ops_lib.Graph()) as sess:
basic_cell = rnn_cell_impl.BasicLSTMCell(1)
basic_cell(array_ops.ones([1, 1]),
state=basic_cell.get_initial_state(inputs=None,
@@ -548,7 +548,7 @@ class RNNTest(test.TestCase):
prefix = os.path.join(self.get_temp_dir(), "ckpt")
save_path = save.save(sess, prefix)
- with self.test_session(graph=ops_lib.Graph()) as sess:
+ with self.session(graph=ops_lib.Graph()) as sess:
lstm_cell = rnn_cell_impl.LSTMCell(1, name="basic_lstm_cell")
lstm_cell(array_ops.ones([1, 1]),
state=lstm_cell.get_initial_state(inputs=None,
diff --git a/tensorflow/python/kernel_tests/scalar_test.py b/tensorflow/python/kernel_tests/scalar_test.py
index 287919bab7..d15f2c7b50 100644
--- a/tensorflow/python/kernel_tests/scalar_test.py
+++ b/tensorflow/python/kernel_tests/scalar_test.py
@@ -53,7 +53,7 @@ class ScalarTest(test.TestCase):
for version in strict + lenient:
with ops.Graph().as_default() as g:
test_util.set_producer_version(g, version)
- with self.test_session(graph=g) as sess:
+ with self.session(graph=g) as sess:
feed = {}
xs = placeholders(args, feed)
x = op(*xs)
diff --git a/tensorflow/python/kernel_tests/softmax_op_test.py b/tensorflow/python/kernel_tests/softmax_op_test.py
index e53347c4bc..89f4697e5c 100644
--- a/tensorflow/python/kernel_tests/softmax_op_test.py
+++ b/tensorflow/python/kernel_tests/softmax_op_test.py
@@ -22,7 +22,6 @@ import unittest
import numpy as np
-from tensorflow.python.compat import compat
from tensorflow.python.framework import dtypes
from tensorflow.python.framework import errors_impl
from tensorflow.python.ops import array_ops
@@ -163,10 +162,9 @@ class SoftmaxTest(test.TestCase):
self._testOverflow(use_gpu=False)
def test1DTensorAsInputNoReshape(self):
- with compat.forward_compatibility_horizon(2018, 8, 27):
- self._testSoftmax(
- np.array([3., 2., 3., 9.]).astype(np.float64), use_gpu=False)
- self._testOverflow(use_gpu=False)
+ self._testSoftmax(
+ np.array([3., 2., 3., 9.]).astype(np.float64), use_gpu=False)
+ self._testOverflow(use_gpu=False)
def test3DTensorAsInput(self):
self._testSoftmax(
@@ -177,13 +175,12 @@ class SoftmaxTest(test.TestCase):
self._testOverflow(use_gpu=False)
def test3DTensorAsInputNoReshape(self):
- with compat.forward_compatibility_horizon(2018, 8, 27):
- self._testSoftmax(
- np.array([[[1., 1., 1., 1.], [1., 2., 3., 4.]],
- [[2., 3., 4., 5.], [6., 7., 8., 9.]],
- [[5., 4., 3., 2.], [1., 2., 3., 4.]]]).astype(np.float32),
- use_gpu=False)
- self._testOverflow(use_gpu=False)
+ self._testSoftmax(
+ np.array([[[1., 1., 1., 1.], [1., 2., 3., 4.]],
+ [[2., 3., 4., 5.], [6., 7., 8., 9.]],
+ [[5., 4., 3., 2.], [1., 2., 3., 4.]]]).astype(np.float32),
+ use_gpu=False)
+ self._testOverflow(use_gpu=False)
def testAlongFirstDimension(self):
self._testSoftmax(
diff --git a/tensorflow/python/kernel_tests/sparse_tensors_map_ops_test.py b/tensorflow/python/kernel_tests/sparse_tensors_map_ops_test.py
index 96793d5af3..31e84341ae 100644
--- a/tensorflow/python/kernel_tests/sparse_tensors_map_ops_test.py
+++ b/tensorflow/python/kernel_tests/sparse_tensors_map_ops_test.py
@@ -76,7 +76,7 @@ class SparseTensorsMapTest(test.TestCase):
return sparse_tensor_lib.SparseTensorValue(ind, val, shape)
def testAddTakeMany(self):
- with self.test_session(graph=ops.Graph(), use_gpu=False) as sess:
+ with self.session(graph=ops.Graph(), use_gpu=False) as sess:
sp_input0 = self._SparseTensorValue_5x6(np.arange(6))
sp_input1 = self._SparseTensorValue_3x4(np.arange(6))
handle0 = add_sparse_to_tensors_map(sp_input0, shared_name="a")
diff --git a/tensorflow/python/kernel_tests/string_format_op_test.py b/tensorflow/python/kernel_tests/string_format_op_test.py
index afa71db909..74a5072bab 100644
--- a/tensorflow/python/kernel_tests/string_format_op_test.py
+++ b/tensorflow/python/kernel_tests/string_format_op_test.py
@@ -34,14 +34,14 @@ class StringFormatOpTest(test.TestCase):
@test_util.run_in_graph_and_eager_modes()
def testFormatOneTensorOneDim(self):
- with self.test_session():
+ with self.cached_session():
tensor = math_ops.range(10)
format_output = string_ops.string_format("{}", tensor)
out = self.evaluate(format_output)
expected = "[0 1 2 ... 7 8 9]"
self.assertEqual(compat.as_text(out), expected)
- with self.test_session():
+ with self.cached_session():
tensor = math_ops.range(10)
format_output = string_ops.string_format("{}", [tensor])
out = self.evaluate(format_output)
@@ -50,7 +50,7 @@ class StringFormatOpTest(test.TestCase):
@test_util.run_in_graph_and_eager_modes()
def testFormatOneVariableScalar(self):
- with self.test_session():
+ with self.cached_session():
var = variables.Variable(3.34)
format_output = string_ops.string_format("{}", [var])
if not context.executing_eagerly():
@@ -61,7 +61,7 @@ class StringFormatOpTest(test.TestCase):
@test_util.run_in_graph_and_eager_modes()
def testFormatOneVariableOneDim(self):
- with self.test_session():
+ with self.cached_session():
var = variables.Variable(math_ops.range(10))
format_output = string_ops.string_format("{}", [var])
if not context.executing_eagerly():
@@ -72,7 +72,7 @@ class StringFormatOpTest(test.TestCase):
@test_util.run_in_graph_and_eager_modes()
def testFormatTwoVariablesWithAssignAdd(self):
- with self.test_session():
+ with self.cached_session():
var_one = variables.Variable(2.14)
plus_one = var_one.assign_add(1.0)
var_two = variables.Variable(math_ops.range(10))
@@ -86,7 +86,7 @@ class StringFormatOpTest(test.TestCase):
@test_util.run_in_graph_and_eager_modes()
def testFormatOneTensorOneDimFloat(self):
- with self.test_session():
+ with self.cached_session():
tensor = constant_op.constant([0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7])
format_output = string_ops.string_format("{}", tensor)
out = self.evaluate(format_output)
@@ -95,7 +95,7 @@ class StringFormatOpTest(test.TestCase):
@test_util.run_in_graph_and_eager_modes()
def testFormatOneTensorOneDimMatchesSummarize(self):
- with self.test_session():
+ with self.cached_session():
tensor = math_ops.range(6)
format_output = string_ops.string_format("{}", tensor, summarize=3)
out = self.evaluate(format_output)
@@ -104,28 +104,28 @@ class StringFormatOpTest(test.TestCase):
@test_util.run_in_graph_and_eager_modes()
def testFormatOneTensorOneDimVarySummarize(self):
- with self.test_session():
+ with self.cached_session():
tensor = math_ops.range(6)
format_output = string_ops.string_format("{}", tensor, summarize=-1)
out = self.evaluate(format_output)
expected = "[0 1 2 3 4 5]"
self.assertEqual(compat.as_text(out), expected)
- with self.test_session():
+ with self.cached_session():
tensor = math_ops.range(6)
format_output = string_ops.string_format("{}", tensor, summarize=1)
out = self.evaluate(format_output)
expected = "[0 ... 5]"
self.assertEqual(compat.as_text(out), expected)
- with self.test_session():
+ with self.cached_session():
tensor = math_ops.range(6)
format_output = string_ops.string_format("{}", tensor, summarize=2)
out = self.evaluate(format_output)
expected = "[0 1 ... 4 5]"
self.assertEqual(compat.as_text(out), expected)
- with self.test_session():
+ with self.cached_session():
tensor = math_ops.range(6)
format_output = string_ops.string_format("{}", tensor, summarize=10)
out = self.evaluate(format_output)
@@ -134,7 +134,7 @@ class StringFormatOpTest(test.TestCase):
@test_util.run_in_graph_and_eager_modes()
def testFormatOneTensorOneDimAlmostSummarize(self):
- with self.test_session():
+ with self.cached_session():
tensor = math_ops.range(5)
format_output = string_ops.string_format("{}", tensor, summarize=3)
out = self.evaluate(format_output)
@@ -143,7 +143,7 @@ class StringFormatOpTest(test.TestCase):
@test_util.run_in_graph_and_eager_modes()
def testFormatOneTensorTwoDimLessThanSummarize(self):
- with self.test_session():
+ with self.cached_session():
tensor = array_ops.reshape(math_ops.range(4), [2, 2])
format_output = string_ops.string_format("{}", tensor, summarize=3)
out = self.evaluate(format_output)
@@ -153,7 +153,7 @@ class StringFormatOpTest(test.TestCase):
@test_util.run_in_graph_and_eager_modes()
def testFormatOneTensorTwoDim(self):
- with self.test_session():
+ with self.cached_session():
tensor = array_ops.reshape(math_ops.range(100), [10, 10])
format_output = string_ops.string_format("{}", tensor)
out = self.evaluate(format_output)
@@ -168,7 +168,7 @@ class StringFormatOpTest(test.TestCase):
@test_util.run_in_graph_and_eager_modes()
def testFormatOneTensorTwoDimSummarizeTwo(self):
- with self.test_session():
+ with self.cached_session():
tensor = array_ops.reshape(math_ops.range(100), [10, 10])
format_output = string_ops.string_format("{}", tensor, summarize=2)
out = self.evaluate(format_output)
@@ -181,7 +181,7 @@ class StringFormatOpTest(test.TestCase):
@test_util.run_in_graph_and_eager_modes()
def testFormatOneTensorThreeDim(self):
- with self.test_session():
+ with self.cached_session():
tensor = array_ops.reshape(math_ops.range(1000), [10, 10, 10])
format_output = string_ops.string_format("{}", tensor)
out = self.evaluate(format_output)
@@ -237,7 +237,7 @@ class StringFormatOpTest(test.TestCase):
@test_util.run_in_graph_and_eager_modes()
def testFormatOneTensorTemplatePrefix(self):
- with self.test_session():
+ with self.cached_session():
tensor = array_ops.reshape(math_ops.range(100), [10, 10])
format_output = string_ops.string_format("tensor summary: {}", tensor)
out = self.evaluate(format_output)
@@ -252,7 +252,7 @@ class StringFormatOpTest(test.TestCase):
@test_util.run_in_graph_and_eager_modes()
def testFormatOneTensorTemplatePrefixAndSuffix(self):
- with self.test_session():
+ with self.cached_session():
tensor = array_ops.reshape(math_ops.range(100), [10, 10])
format_output = string_ops.string_format("tensor summary: {}, suffix",
tensor)
@@ -268,7 +268,7 @@ class StringFormatOpTest(test.TestCase):
@test_util.run_in_graph_and_eager_modes()
def testFormatOneTensorTemplateSuffix(self):
- with self.test_session():
+ with self.cached_session():
tensor = array_ops.reshape(math_ops.range(100), [10, 10])
format_output = string_ops.string_format("{}, suffix", tensor)
out = self.evaluate(format_output)
@@ -283,7 +283,7 @@ class StringFormatOpTest(test.TestCase):
@test_util.run_in_graph_and_eager_modes()
def testFormatNoTensor(self):
- with self.test_session():
+ with self.cached_session():
format_output = string_ops.string_format("No tensor.", ())
out = self.evaluate(format_output)
expected = "No tensor."
@@ -291,7 +291,7 @@ class StringFormatOpTest(test.TestCase):
@test_util.run_in_graph_and_eager_modes()
def testFormatMultiTensor(self):
- with self.test_session():
+ with self.cached_session():
tensor_one = array_ops.reshape(math_ops.range(100), [10, 10])
tensor_two = tensor_one * 10
format_output = string_ops.string_format("One: {},\nTwo: {}",
@@ -315,7 +315,7 @@ class StringFormatOpTest(test.TestCase):
@test_util.run_in_graph_and_eager_modes()
def testFormatSummarizeOne(self):
- with self.test_session():
+ with self.cached_session():
tensor = array_ops.reshape(math_ops.range(100), [10, 10])
format_output = string_ops.string_format("tensor summary: {}", tensor,
summarize=1)
@@ -327,7 +327,7 @@ class StringFormatOpTest(test.TestCase):
@test_util.run_in_graph_and_eager_modes()
def testFormatSummarizeTwo(self):
- with self.test_session():
+ with self.cached_session():
tensor = array_ops.reshape(math_ops.range(100), [10, 10])
format_output = string_ops.string_format("tensor summary: {}", tensor,
summarize=2)
@@ -341,7 +341,7 @@ class StringFormatOpTest(test.TestCase):
@test_util.run_in_graph_and_eager_modes()
def testFormatPlaceholder(self):
- with self.test_session():
+ with self.cached_session():
tensor = array_ops.reshape(math_ops.range(100), [10, 10])
format_output = string_ops.string_format("tensor summary: %t%", tensor,
placeholder="%t%")
@@ -357,21 +357,21 @@ class StringFormatOpTest(test.TestCase):
@test_util.run_in_graph_and_eager_modes()
def testTensorCountMustMatchPlaceholderCount(self):
- with self.test_session():
+ with self.cached_session():
with self.assertRaisesRegexp(
ValueError, r"2 placeholder\(s\) in template does not match 1 "
r"tensor\(s\) provided as input"):
tensor = math_ops.range(10)
format_output = string_ops.string_format("{} {}", tensor)
self.evaluate(format_output)
- with self.test_session():
+ with self.cached_session():
with self.assertRaisesRegexp(
ValueError, r"2 placeholder\(s\) in template does not match 1 "
r"tensor\(s\) provided as input"):
tensor = math_ops.range(10)
format_output = string_ops.string_format("{} {}", [tensor])
self.evaluate(format_output)
- with self.test_session():
+ with self.cached_session():
with self.assertRaisesRegexp(
ValueError, r"1 placeholder\(s\) in template does not match 2 "
r"tensor\(s\) provided as input"):
diff --git a/tensorflow/python/kernel_tests/summary_audio_op_test.py b/tensorflow/python/kernel_tests/summary_audio_op_test.py
index eaae671192..e59a2ceef7 100644
--- a/tensorflow/python/kernel_tests/summary_audio_op_test.py
+++ b/tensorflow/python/kernel_tests/summary_audio_op_test.py
@@ -50,7 +50,7 @@ class SummaryAudioOpTest(test.TestCase):
def testAudioSummary(self):
np.random.seed(7)
for channels in (1, 2, 5, 8):
- with self.test_session(graph=ops.Graph()) as sess:
+ with self.session(graph=ops.Graph()) as sess:
num_frames = 7
shape = (4, num_frames, channels)
# Generate random audio in the range [-1.0, 1.0).
diff --git a/tensorflow/python/kernel_tests/summary_image_op_test.py b/tensorflow/python/kernel_tests/summary_image_op_test.py
index 4718827e88..b650e10404 100644
--- a/tensorflow/python/kernel_tests/summary_image_op_test.py
+++ b/tensorflow/python/kernel_tests/summary_image_op_test.py
@@ -52,7 +52,7 @@ class SummaryImageOpTest(test.TestCase):
def testImageSummary(self):
for depth in (1, 3, 4):
for positive in False, True:
- with self.test_session(graph=ops.Graph()) as sess:
+ with self.session(graph=ops.Graph()) as sess:
shape = (4, 5, 7) + (depth,)
bad_color = [255, 0, 0, 255][:depth]
# Build a mostly random image with one nan
@@ -87,7 +87,7 @@ class SummaryImageOpTest(test.TestCase):
def testImageSummaryUint8(self):
np.random.seed(7)
for depth in (1, 3, 4):
- with self.test_session(graph=ops.Graph()) as sess:
+ with self.session(graph=ops.Graph()) as sess:
shape = (4, 5, 7) + (depth,)
# Build a random uint8 image
diff --git a/tensorflow/python/kernel_tests/while_v2_test.py b/tensorflow/python/kernel_tests/while_v2_test.py
index 0c3b72408e..3a070544e8 100644
--- a/tensorflow/python/kernel_tests/while_v2_test.py
+++ b/tensorflow/python/kernel_tests/while_v2_test.py
@@ -41,7 +41,7 @@ class WhileV2Test(test.TestCase, parameterized.TestCase):
x = constant_op.constant(2.)
ret = while_loop_v2(lambda v: v < 8., lambda v: v * v, [x])
grad = gradients_impl.gradients(ret, [x])
- with self.test_session() as sess:
+ with self.cached_session() as sess:
self.assertEqual(sess.run(ret), 16.)
self.assertSequenceEqual(sess.run(grad), [32.])
@@ -58,7 +58,7 @@ class WhileV2Test(test.TestCase, parameterized.TestCase):
# Note: This is simply d_ret[0]/d_x since d_ret[1]/d_x is 0.
grad = gradients_impl.gradients(ret, [x]) # [2*x*y]
- with self.test_session() as sess:
+ with self.cached_session() as sess:
self.assertSequenceEqual(sess.run(ret), [45., 3.])
self.assertSequenceEqual(sess.run(grad), [9.])
@@ -81,7 +81,7 @@ class WhileV2Test(test.TestCase, parameterized.TestCase):
grady_0 = gradients_impl.gradients(ret[0], [y]) # [2*x*y + x**2]
grady_1 = gradients_impl.gradients(ret[1], [y]) # [x + 1]
grady_2 = gradients_impl.gradients(ret, [y]) # [2*x*y + x**2 + x + 1]
- with self.test_session() as sess:
+ with self.cached_session() as sess:
self.assertSequenceEqual(sess.run(ret), [120., 23.])
self.assertSequenceEqual(sess.run(gradx_0), [39.])
self.assertSequenceEqual(sess.run(gradx_1), [4.])
@@ -96,7 +96,7 @@ class WhileV2Test(test.TestCase, parameterized.TestCase):
ret2 = while_loop_v2(lambda v: v < 16., lambda v: v * v, ret1) # x**4
grad = gradients_impl.gradients(ret2, [x]) # 4x**3
grad_grad = gradients_impl.gradients(grad, [x]) # 12x**2
- with self.test_session() as sess:
+ with self.cached_session() as sess:
self.assertSequenceEqual(sess.run(grad), [32.])
self.assertSequenceEqual(sess.run(grad_grad), [48.])
@@ -105,7 +105,7 @@ class WhileV2Test(test.TestCase, parameterized.TestCase):
ret = while_loop_v2(lambda v: v < 8., lambda v: v**2, [x]) # x**4
grad = gradients_impl.gradients(ret, [x]) # 4x**3
grad_grad = gradients_impl.gradients(grad, [x]) # 12x**2
- with self.test_session() as sess:
+ with self.cached_session() as sess:
self.assertEqual(sess.run(ret), 16.)
self.assertSequenceEqual(sess.run(grad), [32.])
self.assertSequenceEqual(sess.run(grad_grad), [48.])
@@ -148,7 +148,7 @@ class WhileV2Test(test.TestCase, parameterized.TestCase):
y = constant_op.constant(1.)
ret = while_loop_v2(lambda v: v + y < 9., lambda v: v * 3., [x])
grad = gradients_impl.gradients(ret, [x])
- with self.test_session() as sess:
+ with self.cached_session() as sess:
self.assertEqual(sess.run(ret), 18.)
self.assertSequenceEqual(sess.run(grad), [9.])
@@ -157,7 +157,7 @@ class WhileV2Test(test.TestCase, parameterized.TestCase):
y = constant_op.constant(3.)
ret = while_loop_v2(lambda v: v < 8., lambda v: v * y, [x])
grad = gradients_impl.gradients(ret, [x])
- with self.test_session() as sess:
+ with self.cached_session() as sess:
self.assertEqual(sess.run(ret), 18.)
self.assertSequenceEqual(sess.run(grad), [9.])
@@ -178,7 +178,7 @@ class WhileV2Test(test.TestCase, parameterized.TestCase):
ret = while_loop_v2(Cond, Body, [x, tensor_list])
grad = gradients_impl.gradients(ret[0], x)
- with self.test_session() as sess:
+ with self.cached_session() as sess:
self.assertEqual(sess.run(ret[0]), 16.)
self.assertSequenceEqual(sess.run(grad), [32.])
@@ -212,7 +212,7 @@ class WhileV2Test(test.TestCase, parameterized.TestCase):
self.assertEqual(accumulator_count, 1)
grad = gradients_impl.gradients(ret[0], x)
- with self.test_session() as sess:
+ with self.cached_session() as sess:
self.assertEqual(sess.run(ret[0]), 16.)
self.assertSequenceEqual(sess.run(grad), [32.])