aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Gunhan Gulsoy <gunan@google.com>2016-09-09 22:42:01 -0800
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2016-09-09 23:48:49 -0700
commit9faf6fe4abc4f749f7ebda1056799d8130165c09 (patch)
treec47a9db1a8510fd4476b84da5199f1336fa85929
parent60efa7994acb2c38cc855f2915ceff6e9304779e (diff)
To make the tests run both on GPU and CPU, when available, override use_gpu to
True in test_session. Change: 132750351
-rw-r--r--tensorflow/python/kernel_tests/atrous_conv2d_test.py6
-rw-r--r--tensorflow/python/kernel_tests/depthtospace_op_test.py4
-rw-r--r--tensorflow/python/kernel_tests/extract_image_patches_op_test.py2
-rw-r--r--tensorflow/python/kernel_tests/lrn_op_test.py6
-rw-r--r--tensorflow/python/kernel_tests/numerics_test.py6
-rw-r--r--tensorflow/python/kernel_tests/pad_op_test.py22
-rw-r--r--tensorflow/python/kernel_tests/scan_ops_test.py12
-rw-r--r--tensorflow/python/kernel_tests/slice_op_test.py22
-rw-r--r--tensorflow/python/kernel_tests/spacetobatch_op_test.py6
-rw-r--r--tensorflow/python/kernel_tests/unpack_op_test.py6
-rw-r--r--tensorflow/python/kernel_tests/zero_division_test.py2
-rw-r--r--tensorflow/python/ops/image_grad_test.py10
-rw-r--r--tensorflow/python/ops/image_ops_test.py122
-rw-r--r--tensorflow/python/ops/math_grad_test.py4
14 files changed, 115 insertions, 115 deletions
diff --git a/tensorflow/python/kernel_tests/atrous_conv2d_test.py b/tensorflow/python/kernel_tests/atrous_conv2d_test.py
index 7ca5a093c6..1dff6a9f72 100644
--- a/tensorflow/python/kernel_tests/atrous_conv2d_test.py
+++ b/tensorflow/python/kernel_tests/atrous_conv2d_test.py
@@ -51,7 +51,7 @@ class AtrousConv2DTest(tf.test.TestCase):
return filters_up
def testAtrousConv2DForward(self):
- with self.test_session():
+ with self.test_session(use_gpu=True):
# Input: [batch, height, width, input_depth]
height = 9
for width in [9, 10]: # Test both odd and even width.
@@ -98,7 +98,7 @@ class AtrousConv2DTest(tf.test.TestCase):
padding = "SAME" # The padding needs to be "SAME"
np.random.seed(1) # Make it reproducible.
- with self.test_session():
+ with self.test_session(use_gpu=True):
# Input: [batch, height, width, input_depth]
for height in range(15, 17):
for width in range(15, 17):
@@ -127,7 +127,7 @@ class AtrousConv2DTest(tf.test.TestCase):
self.assertAllClose(y1.eval(), y2.eval(), rtol=1e-2, atol=1e-2)
def testGradient(self):
- with self.test_session():
+ with self.test_session(use_gpu=True):
# Input: [batch, height, width, input_depth]
x_shape = [2, 5, 6, 2]
# Filter: [kernel_height, kernel_width, input_depth, output_depth]
diff --git a/tensorflow/python/kernel_tests/depthtospace_op_test.py b/tensorflow/python/kernel_tests/depthtospace_op_test.py
index 3d6ae377fe..84b396a74b 100644
--- a/tensorflow/python/kernel_tests/depthtospace_op_test.py
+++ b/tensorflow/python/kernel_tests/depthtospace_op_test.py
@@ -26,7 +26,7 @@ import tensorflow as tf
class DepthToSpaceTest(tf.test.TestCase):
def _testOne(self, inputs, block_size, outputs):
- with self.test_session():
+ with self.test_session(use_gpu=True):
x_tf = tf.depth_to_space(tf.to_float(inputs), block_size)
self.assertAllEqual(x_tf.eval(), outputs)
@@ -189,7 +189,7 @@ class DepthToSpaceGradientTest(tf.test.TestCase):
# Check the gradients.
def _checkGrad(self, x, block_size):
assert 4 == x.ndim
- with self.test_session():
+ with self.test_session(use_gpu=True):
tf_x = tf.convert_to_tensor(x)
tf_y = tf.depth_to_space(tf_x, block_size)
epsilon = 1e-2
diff --git a/tensorflow/python/kernel_tests/extract_image_patches_op_test.py b/tensorflow/python/kernel_tests/extract_image_patches_op_test.py
index 54433420be..303176cb09 100644
--- a/tensorflow/python/kernel_tests/extract_image_patches_op_test.py
+++ b/tensorflow/python/kernel_tests/extract_image_patches_op_test.py
@@ -40,7 +40,7 @@ class ExtractImagePatches(tf.test.TestCase):
strides = [1] + strides + [1]
rates = [1] + rates + [1]
- with self.test_session():
+ with self.test_session(use_gpu=True):
out_tensor = tf.extract_image_patches(
tf.constant(image),
ksizes=ksizes,
diff --git a/tensorflow/python/kernel_tests/lrn_op_test.py b/tensorflow/python/kernel_tests/lrn_op_test.py
index b759c627d4..3957d083dc 100644
--- a/tensorflow/python/kernel_tests/lrn_op_test.py
+++ b/tensorflow/python/kernel_tests/lrn_op_test.py
@@ -46,7 +46,7 @@ class LRNOpTest(tf.test.TestCase):
return output
def _RunAndVerify(self, dtype):
- with self.test_session():
+ with self.test_session(use_gpu=True):
# random shape
shape = np.random.randint(1, 16, size=4)
# Make depth at least 2 to make it meaningful
@@ -84,7 +84,7 @@ class LRNOpTest(tf.test.TestCase):
self._RunAndVerify(tf.float16)
def testGradientsZeroInput(self):
- with self.test_session():
+ with self.test_session(use_gpu=True):
shape = [4, 4, 4, 4]
p = tf.placeholder(tf.float32, shape=shape)
inp_array = np.zeros(shape).astype("f")
@@ -98,7 +98,7 @@ class LRNOpTest(tf.test.TestCase):
self.assertShapeEqual(expected, grad)
def _RunAndVerifyGradients(self, dtype):
- with self.test_session():
+ with self.test_session(use_gpu=True):
# random shape
shape = np.random.randint(1, 5, size=4)
# Make depth at least 2 to make it meaningful
diff --git a/tensorflow/python/kernel_tests/numerics_test.py b/tensorflow/python/kernel_tests/numerics_test.py
index 9abd25cb56..6e0799363b 100644
--- a/tensorflow/python/kernel_tests/numerics_test.py
+++ b/tensorflow/python/kernel_tests/numerics_test.py
@@ -29,7 +29,7 @@ class VerifyTensorAllFiniteTest(tf.test.TestCase):
def testVerifyTensorAllFiniteSucceeds(self):
x_shape = [5, 4]
x = np.random.random_sample(x_shape).astype(np.float32)
- with self.test_session():
+ with self.test_session(use_gpu=True):
t = tf.constant(x, shape=x_shape, dtype=tf.float32)
t_verified = tf.verify_tensor_all_finite(t, "Input is not a number.")
self.assertAllClose(x, t_verified.eval())
@@ -41,7 +41,7 @@ class VerifyTensorAllFiniteTest(tf.test.TestCase):
# Test NaN.
x[0] = np.nan
- with self.test_session():
+ with self.test_session(use_gpu=True):
with self.assertRaisesOpError(my_msg):
t = tf.constant(x, shape=x_shape, dtype=tf.float32)
t_verified = tf.verify_tensor_all_finite(t, my_msg)
@@ -49,7 +49,7 @@ class VerifyTensorAllFiniteTest(tf.test.TestCase):
# Test Inf.
x[0] = np.inf
- with self.test_session():
+ with self.test_session(use_gpu=True):
with self.assertRaisesOpError(my_msg):
t = tf.constant(x, shape=x_shape, dtype=tf.float32)
t_verified = tf.verify_tensor_all_finite(t, my_msg)
diff --git a/tensorflow/python/kernel_tests/pad_op_test.py b/tensorflow/python/kernel_tests/pad_op_test.py
index 315dca80de..a4e411755a 100644
--- a/tensorflow/python/kernel_tests/pad_op_test.py
+++ b/tensorflow/python/kernel_tests/pad_op_test.py
@@ -63,14 +63,14 @@ class PadOpTest(tf.test.TestCase):
def _testPad(self, np_inputs, paddings, mode):
np_val = self._npPad(np_inputs, paddings, mode=mode)
- with self.test_session():
+ with self.test_session(use_gpu=True):
tf_val = tf.pad(np_inputs, paddings, mode=mode)
out = tf_val.eval()
self.assertAllEqual(np_val, out)
self.assertShapeEqual(np_val, tf_val)
def _testGradient(self, x, a, mode):
- with self.test_session():
+ with self.test_session(use_gpu=True):
inx = tf.convert_to_tensor(x)
xs = list(x.shape)
ina = tf.convert_to_tensor(a)
@@ -94,56 +94,56 @@ class PadOpTest(tf.test.TestCase):
self._testGradient(np_inputs, paddings, mode=mode)
def testInputDims(self):
- with self.test_session():
+ with self.test_session(use_gpu=True):
with self.assertRaises(ValueError):
tf.pad(
tf.reshape([1, 2], shape=[1, 2, 1, 1, 1, 1]),
tf.reshape([1, 2], shape=[1, 2]))
def testPaddingsDim(self):
- with self.test_session():
+ with self.test_session(use_gpu=True):
with self.assertRaises(ValueError):
tf.pad(
tf.reshape([1, 2], shape=[1, 2]),
tf.reshape([1, 2], shape=[2]))
def testPaddingsDim2(self):
- with self.test_session():
+ with self.test_session(use_gpu=True):
with self.assertRaises(ValueError):
tf.pad(
tf.reshape([1, 2], shape=[1, 2]),
tf.reshape([1, 2], shape=[2, 1]))
def testPaddingsDim3(self):
- with self.test_session():
+ with self.test_session(use_gpu=True):
with self.assertRaises(ValueError):
tf.pad(
tf.reshape([1, 2], shape=[1, 2]),
tf.reshape([1, 2], shape=[1, 2]))
def testPaddingsDim4(self):
- with self.test_session():
+ with self.test_session(use_gpu=True):
with self.assertRaises(ValueError):
tf.pad(
tf.reshape([1, 2], shape=[1, 2]),
tf.reshape([1, 2, 3, 4, 5, 6], shape=[3, 2]))
def testPaddingsNonNegative(self):
- with self.test_session():
+ with self.test_session(use_gpu=True):
with self.assertRaisesRegexp(ValueError, "must be non-negative"):
tf.pad(
tf.constant([1], shape=[1]),
tf.constant([-1, 0], shape=[1, 2]))
def testPaddingsNonNegative2(self):
- with self.test_session():
+ with self.test_session(use_gpu=True):
with self.assertRaisesRegexp(ValueError, "must be non-negative"):
tf.pad(
tf.constant([1], shape=[1]),
tf.constant([-1, 0], shape=[1, 2]))
def testPaddingsMaximum(self):
- with self.test_session():
+ with self.test_session(use_gpu=True):
with self.assertRaises(Exception):
tf.pad(
tf.constant([1], shape=[2]),
@@ -199,7 +199,7 @@ class PadOpTest(tf.test.TestCase):
def testScalars(self):
paddings = np.zeros((0, 2), dtype=np.int32)
inp = np.asarray(7)
- with self.test_session():
+ with self.test_session(use_gpu=True):
tf_val = tf.pad(inp, paddings)
out = tf_val.eval()
self.assertAllEqual(inp, out)
diff --git a/tensorflow/python/kernel_tests/scan_ops_test.py b/tensorflow/python/kernel_tests/scan_ops_test.py
index 71a7f62d23..6d6e19f8cf 100644
--- a/tensorflow/python/kernel_tests/scan_ops_test.py
+++ b/tensorflow/python/kernel_tests/scan_ops_test.py
@@ -69,7 +69,7 @@ class CumsumTest(tf.test.TestCase):
def _compare(self, x, axis, exclusive, reverse):
np_out = handle_options(np.cumsum, x, axis, exclusive, reverse)
- with self.test_session():
+ with self.test_session(use_gpu=True):
tf_out = tf.cumsum(x, axis, exclusive, reverse).eval()
self.assertAllClose(np_out, tf_out)
@@ -106,7 +106,7 @@ class CumsumTest(tf.test.TestCase):
def testInvalidAxis(self):
x = np.arange(0, 10).reshape([2, 5]).astype(np.float32)
input_tensor = tf.convert_to_tensor(x)
- with self.test_session():
+ with self.test_session(use_gpu=True):
with self.assertRaisesWithPredicateMatch(
tf.errors.InvalidArgumentError,
lambda e: "Expected scan axis in the range [-2, 2)" in str(e)):
@@ -122,7 +122,7 @@ class CumsumTest(tf.test.TestCase):
def _compareGradient(self, shape, axis, exclusive, reverse):
x = np.arange(0, 50).reshape(shape).astype(np.float64)
- with self.test_session():
+ with self.test_session(use_gpu=True):
t = tf.convert_to_tensor(x)
result = tf.cumsum(t, axis, exclusive, reverse)
jacob_t, jacob_n = tf.test.compute_gradient(t,
@@ -163,7 +163,7 @@ class CumprodTest(tf.test.TestCase):
def _compare(self, x, axis, exclusive, reverse):
np_out = handle_options(np.cumprod, x, axis, exclusive, reverse)
- with self.test_session():
+ with self.test_session(use_gpu=True):
tf_out = tf.cumprod(x, axis, exclusive, reverse).eval()
self.assertAllClose(np_out, tf_out)
@@ -200,7 +200,7 @@ class CumprodTest(tf.test.TestCase):
def testInvalidAxis(self):
x = np.arange(0, 10).reshape([2, 5]).astype(np.float32)
input_tensor = tf.convert_to_tensor(x)
- with self.test_session():
+ with self.test_session(use_gpu=True):
with self.assertRaisesWithPredicateMatch(
tf.errors.InvalidArgumentError,
lambda e: "Expected scan axis in the range [-2, 2)" in str(e)):
@@ -216,7 +216,7 @@ class CumprodTest(tf.test.TestCase):
def _compareGradient(self, shape, axis, exclusive, reverse):
x = np.arange(1, 9).reshape(shape).astype(np.float64)
- with self.test_session():
+ with self.test_session(use_gpu=True):
t = tf.convert_to_tensor(x)
result = tf.cumprod(t, axis, exclusive, reverse)
jacob_t, jacob_n = tf.test.compute_gradient(t,
diff --git a/tensorflow/python/kernel_tests/slice_op_test.py b/tensorflow/python/kernel_tests/slice_op_test.py
index efb2c0cda0..27506126e0 100644
--- a/tensorflow/python/kernel_tests/slice_op_test.py
+++ b/tensorflow/python/kernel_tests/slice_op_test.py
@@ -28,7 +28,7 @@ class SliceTest(tf.test.TestCase):
def testEmpty(self):
inp = np.random.rand(4, 4).astype("f")
for k in xrange(4):
- with self.test_session():
+ with self.test_session(use_gpu=True):
a = tf.constant(inp, shape=[4, 4], dtype=tf.float32)
slice_t = a[2, k:k]
slice_val = slice_t.eval()
@@ -37,7 +37,7 @@ class SliceTest(tf.test.TestCase):
def testInt32(self):
inp = np.random.rand(4, 4).astype("i")
for k in xrange(4):
- with self.test_session():
+ with self.test_session(use_gpu=True):
a = tf.constant(inp, shape=[4, 4], dtype=tf.int32)
slice_t = a[2, k:k]
slice_val = slice_t.eval()
@@ -45,7 +45,7 @@ class SliceTest(tf.test.TestCase):
def testSelectAll(self):
for _ in range(10):
- with self.test_session():
+ with self.test_session(use_gpu=True):
inp = np.random.rand(4, 4, 4, 4).astype("f")
a = tf.constant(inp, shape=[4, 4, 4, 4],
dtype=tf.float32)
@@ -60,7 +60,7 @@ class SliceTest(tf.test.TestCase):
def testSingleDimension(self):
for _ in range(10):
- with self.test_session():
+ with self.test_session(use_gpu=True):
inp = np.random.rand(10).astype("f")
a = tf.constant(inp, shape=[10], dtype=tf.float32)
@@ -78,7 +78,7 @@ class SliceTest(tf.test.TestCase):
self.assertAllEqual(slice_val, inp[lo:hi])
def _testSliceMatrixDim0(self, x, begin, size):
- with self.test_session():
+ with self.test_session(use_gpu=True):
tf_ans = tf.slice(x, [begin, 0], [size, x.shape[1]]).eval()
np_ans = x[begin:begin+size, :]
self.assertAllEqual(tf_ans, np_ans)
@@ -93,7 +93,7 @@ class SliceTest(tf.test.TestCase):
def testSingleElementAll(self):
for _ in range(10):
- with self.test_session():
+ with self.test_session(use_gpu=True):
inp = np.random.rand(4, 4).astype("f")
a = tf.constant(inp, shape=[4, 4], dtype=tf.float32)
@@ -103,7 +103,7 @@ class SliceTest(tf.test.TestCase):
self.assertAllEqual(slice_val, inp[x, 0:y])
def testSimple(self):
- with self.test_session() as sess:
+ with self.test_session(use_gpu=True) as sess:
inp = np.random.rand(4, 4).astype("f")
a = tf.constant([float(x) for x in inp.ravel(order="C")],
shape=[4, 4], dtype=tf.float32)
@@ -116,7 +116,7 @@ class SliceTest(tf.test.TestCase):
self.assertEqual(slice2_val.shape, slice2_t.get_shape())
def testComplex(self):
- with self.test_session():
+ with self.test_session(use_gpu=True):
inp = np.random.rand(4, 10, 10, 4).astype("f")
a = tf.constant(inp, dtype=tf.float32)
@@ -133,7 +133,7 @@ class SliceTest(tf.test.TestCase):
# Random dims of rank 6
input_shape = np.random.randint(0, 20, size=6)
inp = np.random.rand(*input_shape).astype("f")
- with self.test_session() as sess:
+ with self.test_session(use_gpu=True) as sess:
a = tf.constant([float(x) for x in inp.ravel(order="C")],
shape=input_shape, dtype=tf.float32)
indices = [0 if x == 0 else np.random.randint(x) for x in input_shape]
@@ -161,7 +161,7 @@ class SliceTest(tf.test.TestCase):
self.assertEqual(expected_val.shape, slice2_t.get_shape())
def _testGradientSlice(self, input_shape, slice_begin, slice_size):
- with self.test_session():
+ with self.test_session(use_gpu=True):
num_inputs = np.prod(input_shape)
num_grads = np.prod(slice_size)
inp = np.random.rand(num_inputs).astype("f").reshape(input_shape)
@@ -184,7 +184,7 @@ class SliceTest(tf.test.TestCase):
self.assertAllClose(np_ans, result)
def _testGradientVariableSize(self):
- with self.test_session():
+ with self.test_session(use_gpu=True):
inp = tf.constant([1.0, 2.0, 3.0], name="in")
out = tf.slice(inp, [1], [-1])
grad_actual = tf.gradients(out, inp)[0].eval()
diff --git a/tensorflow/python/kernel_tests/spacetobatch_op_test.py b/tensorflow/python/kernel_tests/spacetobatch_op_test.py
index b340394017..9f346aa3de 100644
--- a/tensorflow/python/kernel_tests/spacetobatch_op_test.py
+++ b/tensorflow/python/kernel_tests/spacetobatch_op_test.py
@@ -27,7 +27,7 @@ class SpaceToBatchTest(tf.test.TestCase):
"""Tests input-output pairs for the SpaceToBatch and BatchToSpace ops."""
def _testPad(self, inputs, paddings, block_size, outputs):
- with self.test_session():
+ with self.test_session(use_gpu=True):
# outputs = space_to_batch(inputs)
x_tf = tf.space_to_batch(
tf.to_float(inputs), paddings, block_size=block_size)
@@ -129,7 +129,7 @@ class SpaceToBatchSpaceToDepth(tf.test.TestCase):
tf.space_to_depth(
tf.transpose(x, [3, 1, 2, 0]), block_size=block_size),
[3, 1, 2, 0])
- with self.test_session():
+ with self.test_session(use_gpu=True):
self.assertAllEqual(y1.eval(), y2.eval())
@@ -205,7 +205,7 @@ class SpaceToBatchGradientTest(tf.test.TestCase):
# Check the gradients.
def _checkGrad(self, x, paddings, block_size):
assert 4 == x.ndim
- with self.test_session():
+ with self.test_session(use_gpu=True):
tf_x = tf.convert_to_tensor(x)
tf_y = tf.space_to_batch(tf_x, paddings, block_size)
epsilon = 1e-5
diff --git a/tensorflow/python/kernel_tests/unpack_op_test.py b/tensorflow/python/kernel_tests/unpack_op_test.py
index f4bc4955f4..c815f7abc8 100644
--- a/tensorflow/python/kernel_tests/unpack_op_test.py
+++ b/tensorflow/python/kernel_tests/unpack_op_test.py
@@ -35,7 +35,7 @@ class UnpackOpTest(tf.test.TestCase):
def testSimple(self):
np.random.seed(7)
- with self.test_session():
+ with self.test_session(use_gpu=True):
for shape in (2,), (3,), (2, 3), (3, 2), (4, 3, 2):
data = np.random.randn(*shape)
# Convert data to a single tensorflow tensor
@@ -52,7 +52,7 @@ class UnpackOpTest(tf.test.TestCase):
data = np.random.randn(*shape)
shapes = [shape[1:]] * shape[0]
for i in xrange(shape[0]):
- with self.test_session():
+ with self.test_session(use_gpu=True):
x = tf.constant(data)
cs = tf.unpack(x, num=shape[0])
err = tf.test.compute_gradient_error(x, shape, cs[i], shapes[i])
@@ -64,7 +64,7 @@ class UnpackOpTest(tf.test.TestCase):
out_shape = list(shape)
del out_shape[1]
for i in xrange(shape[1]):
- with self.test_session():
+ with self.test_session(use_gpu=True):
x = tf.constant(data)
cs = tf.unpack(x, num=shape[1], axis=1)
err = tf.test.compute_gradient_error(x, shape, cs[i], out_shape)
diff --git a/tensorflow/python/kernel_tests/zero_division_test.py b/tensorflow/python/kernel_tests/zero_division_test.py
index e635aff84d..85455e1e31 100644
--- a/tensorflow/python/kernel_tests/zero_division_test.py
+++ b/tensorflow/python/kernel_tests/zero_division_test.py
@@ -25,7 +25,7 @@ import tensorflow as tf
class ZeroDivisionTest(tf.test.TestCase):
def testZeros(self):
- with self.test_session():
+ with self.test_session(use_gpu=True):
for dtype in tf.uint8, tf.int16, tf.int32, tf.int64:
zero = tf.constant(0, dtype=dtype)
one = tf.constant(1, dtype=dtype)
diff --git a/tensorflow/python/ops/image_grad_test.py b/tensorflow/python/ops/image_grad_test.py
index 03503fa8b1..fa00d4407a 100644
--- a/tensorflow/python/ops/image_grad_test.py
+++ b/tensorflow/python/ops/image_grad_test.py
@@ -33,7 +33,7 @@ class ResizeNearestNeighborOpTest(tf.test.TestCase):
for nptype in self.TYPES:
x = np.arange(0, 4).reshape(in_shape).astype(nptype)
- with self.test_session() as sess:
+ with self.test_session(use_gpu=True) as sess:
input_tensor = tf.constant(x, shape=in_shape)
resize_out = tf.image.resize_nearest_neighbor(input_tensor,
out_shape[1:3])
@@ -49,7 +49,7 @@ class ResizeNearestNeighborOpTest(tf.test.TestCase):
for nptype in self.TYPES:
x = np.arange(0, 6).reshape(in_shape).astype(nptype)
- with self.test_session():
+ with self.test_session(use_gpu=True):
input_tensor = tf.constant(x, shape=in_shape)
resize_out = tf.image.resize_nearest_neighbor(input_tensor,
out_shape[1:3])
@@ -67,7 +67,7 @@ class ResizeNearestNeighborOpTest(tf.test.TestCase):
for nptype in self.TYPES:
x = np.arange(0, 24).reshape(in_shape).astype(nptype)
- with self.test_session():
+ with self.test_session(use_gpu=True):
input_tensor = tf.constant(x, shape=in_shape)
resize_out = tf.image.resize_nearest_neighbor(input_tensor,
out_shape[1:3])
@@ -214,7 +214,7 @@ class CropAndResizeOpTest(tf.test.TestCase):
boxes = np.array([[0, 0, 1, 1], [.1, .2, .7, .8]], dtype=np.float32)
box_ind = np.array([0, 1], dtype=np.int32)
- with self.test_session() as sess:
+ with self.test_session(use_gpu=True) as sess:
crops = tf.image.crop_and_resize(
tf.constant(image, shape=image_shape),
tf.constant(boxes, shape=[num_boxes, 4]),
@@ -299,7 +299,7 @@ class CropAndResizeOpTest(tf.test.TestCase):
boxes = np.array(boxes, dtype=np.float32)
box_ind = np.arange(batch, dtype=np.int32)
- with self.test_session():
+ with self.test_session(use_gpu=True):
image_tensor = tf.constant(image, shape=image_shape)
boxes_tensor = tf.constant(boxes, shape=[num_boxes, 4])
box_ind_tensor = tf.constant(box_ind, shape=[num_boxes])
diff --git a/tensorflow/python/ops/image_ops_test.py b/tensorflow/python/ops/image_ops_test.py
index ddf8a6f51d..15abde14b4 100644
--- a/tensorflow/python/ops/image_ops_test.py
+++ b/tensorflow/python/ops/image_ops_test.py
@@ -48,7 +48,7 @@ class RGBToHSVTest(test_util.TensorFlowTestCase):
inp = np.random.rand(*shape).astype(nptype)
# Convert to HSV and back, as a batch and individually
- with self.test_session() as sess:
+ with self.test_session(use_gpu=True) as sess:
batch0 = constant_op.constant(inp)
batch1 = image_ops.rgb_to_hsv(batch0)
batch2 = image_ops.hsv_to_rgb(batch1)
@@ -68,7 +68,7 @@ class RGBToHSVTest(test_util.TensorFlowTestCase):
data = [0, 5, 13, 54, 135, 226, 37, 8, 234, 90, 255, 1]
for nptype in [np.float32, np.float64]:
rgb_np = np.array(data, dtype=nptype).reshape([2, 2, 3]) / 255.
- with self.test_session():
+ with self.test_session(use_gpu=True):
hsv = image_ops.rgb_to_hsv(rgb_np)
rgb = image_ops.hsv_to_rgb(hsv)
rgb_tf = rgb.eval()
@@ -99,7 +99,7 @@ class GrayscaleToRGBTest(test_util.TensorFlowTestCase):
def _TestRGBToGrayscale(self, x_np):
y_np = self._RGBToGrayscale(x_np)
- with self.test_session():
+ with self.test_session(use_gpu=True):
x_tf = constant_op.constant(x_np, shape=x_np.shape)
y = image_ops.rgb_to_grayscale(x_tf)
y_tf = y.eval()
@@ -121,7 +121,7 @@ class GrayscaleToRGBTest(test_util.TensorFlowTestCase):
y_np = np.array([[1, 1, 1], [2, 2, 2]],
dtype=np.uint8).reshape([1, 1, 2, 3])
- with self.test_session():
+ with self.test_session(use_gpu=True):
x_tf = constant_op.constant(x_np, shape=x_np.shape)
y = image_ops.grayscale_to_rgb(x_tf)
y_tf = y.eval()
@@ -131,7 +131,7 @@ class GrayscaleToRGBTest(test_util.TensorFlowTestCase):
x_np = np.array([[1, 2]], dtype=np.uint8).reshape([1, 2, 1])
y_np = np.array([[1, 1, 1], [2, 2, 2]], dtype=np.uint8).reshape([1, 2, 3])
- with self.test_session():
+ with self.test_session(use_gpu=True):
x_tf = constant_op.constant(x_np, shape=x_np.shape)
y = image_ops.grayscale_to_rgb(x_tf)
y_tf = y.eval()
@@ -141,23 +141,23 @@ class GrayscaleToRGBTest(test_util.TensorFlowTestCase):
# Shape inference works and produces expected output where possible
rgb_shape = [7, None, 19, 3]
gray_shape = rgb_shape[:-1] + [1]
- with self.test_session():
+ with self.test_session(use_gpu=True):
rgb_tf = array_ops.placeholder(dtypes.uint8, shape=rgb_shape)
gray = image_ops.rgb_to_grayscale(rgb_tf)
self.assertEqual(gray_shape, gray.get_shape().as_list())
- with self.test_session():
+ with self.test_session(use_gpu=True):
gray_tf = array_ops.placeholder(dtypes.uint8, shape=gray_shape)
rgb = image_ops.grayscale_to_rgb(gray_tf)
self.assertEqual(rgb_shape, rgb.get_shape().as_list())
# Shape inference does not break for unknown shapes
- with self.test_session():
+ with self.test_session(use_gpu=True):
rgb_tf_unknown = array_ops.placeholder(dtypes.uint8)
gray_unknown = image_ops.rgb_to_grayscale(rgb_tf_unknown)
self.assertFalse(gray_unknown.get_shape())
- with self.test_session():
+ with self.test_session(use_gpu=True):
gray_tf_unknown = array_ops.placeholder(dtypes.uint8)
rgb_unknown = image_ops.grayscale_to_rgb(gray_tf_unknown)
self.assertFalse(rgb_unknown.get_shape())
@@ -174,7 +174,7 @@ class AdjustHueTest(test_util.TensorFlowTestCase):
y_data = [0, 13, 1, 54, 226, 59, 8, 234, 150, 255, 39, 1]
y_np = np.array(y_data, dtype=np.uint8).reshape(x_shape)
- with self.test_session():
+ with self.test_session(use_gpu=True):
x = constant_op.constant(x_np, shape=x_shape)
y = image_ops.adjust_hue(x, delta)
y_tf = y.eval()
@@ -189,7 +189,7 @@ class AdjustHueTest(test_util.TensorFlowTestCase):
y_data = [13, 0, 11, 226, 54, 221, 234, 8, 92, 1, 217, 255]
y_np = np.array(y_data, dtype=np.uint8).reshape(x_shape)
- with self.test_session():
+ with self.test_session(use_gpu=True):
x = constant_op.constant(x_np, shape=x_shape)
y = image_ops.adjust_hue(x, delta)
y_tf = y.eval()
@@ -207,7 +207,7 @@ class AdjustSaturationTest(test_util.TensorFlowTestCase):
y_data = [6, 9, 13, 140, 180, 226, 135, 121, 234, 172, 255, 128]
y_np = np.array(y_data, dtype=np.uint8).reshape(x_shape)
- with self.test_session():
+ with self.test_session(use_gpu=True):
x = constant_op.constant(x_np, shape=x_shape)
y = image_ops.adjust_saturation(x, saturation_factor)
y_tf = y.eval()
@@ -222,7 +222,7 @@ class AdjustSaturationTest(test_util.TensorFlowTestCase):
y_data = [0, 5, 13, 0, 106, 226, 30, 0, 234, 89, 255, 0]
y_np = np.array(y_data, dtype=np.uint8).reshape(x_shape)
- with self.test_session():
+ with self.test_session(use_gpu=True):
x = constant_op.constant(x_np, shape=x_shape)
y = image_ops.adjust_saturation(x, saturation_factor)
y_tf = y.eval()
@@ -233,7 +233,7 @@ class FlipTransposeRotateTest(test_util.TensorFlowTestCase):
def testIdempotentLeftRight(self):
x_np = np.array([[1, 2, 3], [1, 2, 3]], dtype=np.uint8).reshape([2, 3, 1])
- with self.test_session():
+ with self.test_session(use_gpu=True):
x_tf = constant_op.constant(x_np, shape=x_np.shape)
y = image_ops.flip_left_right(image_ops.flip_left_right(x_tf))
y_tf = y.eval()
@@ -243,7 +243,7 @@ class FlipTransposeRotateTest(test_util.TensorFlowTestCase):
x_np = np.array([[1, 2, 3], [1, 2, 3]], dtype=np.uint8).reshape([2, 3, 1])
y_np = np.array([[3, 2, 1], [3, 2, 1]], dtype=np.uint8).reshape([2, 3, 1])
- with self.test_session():
+ with self.test_session(use_gpu=True):
x_tf = constant_op.constant(x_np, shape=x_np.shape)
y = image_ops.flip_left_right(x_tf)
y_tf = y.eval()
@@ -252,7 +252,7 @@ class FlipTransposeRotateTest(test_util.TensorFlowTestCase):
def testIdempotentUpDown(self):
x_np = np.array([[1, 2, 3], [4, 5, 6]], dtype=np.uint8).reshape([2, 3, 1])
- with self.test_session():
+ with self.test_session(use_gpu=True):
x_tf = constant_op.constant(x_np, shape=x_np.shape)
y = image_ops.flip_up_down(image_ops.flip_up_down(x_tf))
y_tf = y.eval()
@@ -262,7 +262,7 @@ class FlipTransposeRotateTest(test_util.TensorFlowTestCase):
x_np = np.array([[1, 2, 3], [4, 5, 6]], dtype=np.uint8).reshape([2, 3, 1])
y_np = np.array([[4, 5, 6], [1, 2, 3]], dtype=np.uint8).reshape([2, 3, 1])
- with self.test_session():
+ with self.test_session(use_gpu=True):
x_tf = constant_op.constant(x_np, shape=x_np.shape)
y = image_ops.flip_up_down(x_tf)
y_tf = y.eval()
@@ -271,7 +271,7 @@ class FlipTransposeRotateTest(test_util.TensorFlowTestCase):
def testIdempotentTranspose(self):
x_np = np.array([[1, 2, 3], [4, 5, 6]], dtype=np.uint8).reshape([2, 3, 1])
- with self.test_session():
+ with self.test_session(use_gpu=True):
x_tf = constant_op.constant(x_np, shape=x_np.shape)
y = image_ops.transpose_image(image_ops.transpose_image(x_tf))
y_tf = y.eval()
@@ -281,7 +281,7 @@ class FlipTransposeRotateTest(test_util.TensorFlowTestCase):
x_np = np.array([[1, 2, 3], [4, 5, 6]], dtype=np.uint8).reshape([2, 3, 1])
y_np = np.array([[1, 4], [2, 5], [3, 6]], dtype=np.uint8).reshape([3, 2, 1])
- with self.test_session():
+ with self.test_session(use_gpu=True):
x_tf = constant_op.constant(x_np, shape=x_np.shape)
y = image_ops.transpose_image(x_tf)
y_tf = y.eval()
@@ -316,7 +316,7 @@ class FlipTransposeRotateTest(test_util.TensorFlowTestCase):
def testRot90GroupOrder(self):
image = np.arange(24, dtype=np.uint8).reshape([2, 4, 3])
- with self.test_session():
+ with self.test_session(use_gpu=True):
rotated = image
for _ in xrange(4):
rotated = image_ops.rot90(rotated)
@@ -324,7 +324,7 @@ class FlipTransposeRotateTest(test_util.TensorFlowTestCase):
def testRot90NumpyEquivalence(self):
image = np.arange(24, dtype=np.uint8).reshape([2, 4, 3])
- with self.test_session():
+ with self.test_session(use_gpu=True):
k_placeholder = array_ops.placeholder(dtypes.int32, shape=[])
y_tf = image_ops.rot90(image, k_placeholder)
for k in xrange(4):
@@ -339,7 +339,7 @@ class RandomFlipTest(test_util.TensorFlowTestCase):
num_iterations = 500
hist = [0, 0]
- with self.test_session():
+ with self.test_session(use_gpu=True):
x_tf = constant_op.constant(x_np, shape=x_np.shape)
y = image_ops.random_flip_left_right(x_tf)
for _ in xrange(num_iterations):
@@ -355,7 +355,7 @@ class RandomFlipTest(test_util.TensorFlowTestCase):
num_iterations = 500
hist = [0, 0]
- with self.test_session():
+ with self.test_session(use_gpu=True):
x_tf = constant_op.constant(x_np, shape=x_np.shape)
y = image_ops.random_flip_up_down(x_tf)
for _ in xrange(num_iterations):
@@ -370,7 +370,7 @@ class RandomFlipTest(test_util.TensorFlowTestCase):
class AdjustContrastTest(test_util.TensorFlowTestCase):
def _testContrast(self, x_np, y_np, contrast_factor):
- with self.test_session():
+ with self.test_session(use_gpu=True):
x = constant_op.constant(x_np, shape=x_np.shape)
y = image_ops.adjust_contrast(x, contrast_factor)
y_tf = y.eval()
@@ -421,7 +421,7 @@ class AdjustContrastTest(test_util.TensorFlowTestCase):
class AdjustBrightnessTest(test_util.TensorFlowTestCase):
def _testBrightness(self, x_np, y_np, delta):
- with self.test_session():
+ with self.test_session(use_gpu=True):
x = constant_op.constant(x_np, shape=x_np.shape)
y = image_ops.adjust_brightness(x, delta)
y_tf = y.eval()
@@ -477,7 +477,7 @@ class PerImageWhiteningTest(test_util.TensorFlowTestCase):
x_np = np.arange(0, np.prod(x_shape), dtype=np.int32).reshape(x_shape)
y_np = self._NumpyPerImageWhitening(x_np)
- with self.test_session():
+ with self.test_session(use_gpu=True):
x = constant_op.constant(x_np, shape=x_shape)
y = image_ops.per_image_whitening(x)
y_tf = y.eval()
@@ -487,7 +487,7 @@ class PerImageWhiteningTest(test_util.TensorFlowTestCase):
im_np = np.ones([19, 19, 3]).astype(np.float32) * 249
im = constant_op.constant(im_np)
whiten = image_ops.per_image_whitening(im)
- with self.test_session():
+ with self.test_session(use_gpu=True):
whiten_np = whiten.eval()
self.assertFalse(np.any(np.isnan(whiten_np)))
@@ -512,7 +512,7 @@ class CropToBoundingBoxTest(test_util.TensorFlowTestCase):
if not use_tensor_inputs:
self.assertTrue(y.get_shape().is_fully_defined())
- with self.test_session():
+ with self.test_session(use_gpu=True):
return y.eval(feed_dict=feed_dict)
def _assertReturns(self, x, x_shape, offset_height, offset_width,
@@ -639,7 +639,7 @@ class CentralCropTest(test_util.TensorFlowTestCase):
def testNoOp(self):
x_shape = [13, 9, 3]
x_np = np.ones(x_shape, dtype=np.float32)
- with self.test_session():
+ with self.test_session(use_gpu=True):
x = constant_op.constant(x_np, shape=x_shape)
y = image_ops.central_crop(x, 1.0)
y_tf = y.eval()
@@ -652,7 +652,7 @@ class CentralCropTest(test_util.TensorFlowTestCase):
[1, 2, 3, 4, 5, 6, 7, 8], [1, 2, 3, 4, 5, 6, 7, 8]],
dtype=np.int32).reshape(x_shape)
y_np = np.array([[3, 4, 5, 6], [3, 4, 5, 6]]).reshape([2, 4, 1])
- with self.test_session():
+ with self.test_session(use_gpu=True):
x = constant_op.constant(x_np, shape=x_shape)
y = image_ops.central_crop(x, 0.5)
y_tf = y.eval()
@@ -661,7 +661,7 @@ class CentralCropTest(test_util.TensorFlowTestCase):
def testError(self):
x_shape = [13, 9, 3]
x_np = np.ones(x_shape, dtype=np.float32)
- with self.test_session():
+ with self.test_session(use_gpu=True):
x = constant_op.constant(x_np, shape=x_shape)
with self.assertRaises(ValueError):
_ = image_ops.central_crop(x, 0.0)
@@ -689,7 +689,7 @@ class PadToBoundingBoxTest(test_util.TensorFlowTestCase):
if not use_tensor_inputs:
self.assertTrue(y.get_shape().is_fully_defined())
- with self.test_session():
+ with self.test_session(use_gpu=True):
return y.eval(feed_dict=feed_dict)
def _assertReturns(self, x, x_shape, offset_height, offset_width,
@@ -834,7 +834,7 @@ class SelectDistortedCropBoxTest(test_util.TensorFlowTestCase):
fraction_object_covered = []
num_iter = 1000
- with self.test_session():
+ with self.test_session(use_gpu=True):
image_tf = constant_op.constant(image,
shape=image.shape)
image_size_tf = constant_op.constant(image_size_np,
@@ -937,7 +937,7 @@ class SelectDistortedCropBoxTest(test_util.TensorFlowTestCase):
area_range=(0.05, 1.0))
def testSampleDistortedBoundingBoxShape(self):
- with self.test_session():
+ with self.test_session(use_gpu=True):
image_size = constant_op.constant([40, 50, 1],
shape=[3],
dtype=dtypes.int32)
@@ -993,7 +993,7 @@ class ResizeImagesTest(test_util.TensorFlowTestCase):
for opt in self.OPTIONS:
if test.is_gpu_available() and self.shouldRunOnGPU(opt, nptype):
- with self.test_session() as sess:
+ with self.test_session(use_gpu=True) as sess:
image = constant_op.constant(img_np, shape=img_shape)
y = image_ops.resize_images(image, target_height, target_width, opt)
yshape = array_ops.shape(y)
@@ -1002,7 +1002,7 @@ class ResizeImagesTest(test_util.TensorFlowTestCase):
self.assertAllClose(resized, img_np, atol=1e-5)
# Resizing with a single image must leave the shape unchanged also.
- with self.test_session():
+ with self.test_session(use_gpu=True):
img_single = img_np.reshape(single_shape)
image = constant_op.constant(img_single, shape=single_shape)
y = image_ops.resize_images(image, target_height, target_width,
@@ -1028,7 +1028,7 @@ class ResizeImagesTest(test_util.TensorFlowTestCase):
img_np = np.array(data, dtype=np.uint8).reshape(img_shape)
for opt in self.OPTIONS:
- with self.test_session() as sess:
+ with self.test_session(use_gpu=True) as sess:
image = constant_op.constant(img_np, shape=img_shape)
y = image_ops.resize_images(image, target_height, target_width, opt)
yshape = array_ops.shape(y)
@@ -1038,7 +1038,7 @@ class ResizeImagesTest(test_util.TensorFlowTestCase):
self.assertAllClose(resized, img_np, atol=1e-5)
# Resizing with a single image must leave the shape unchanged also.
- with self.test_session():
+ with self.test_session(use_gpu=True):
img_single = img_np.reshape(single_shape)
image = constant_op.constant(img_single, shape=single_shape)
y = image_ops.resize_images(image, target_height, target_width,
@@ -1090,7 +1090,7 @@ class ResizeImagesTest(test_util.TensorFlowTestCase):
for opt in self.OPTIONS:
if test.is_gpu_available() and self.shouldRunOnGPU(opt, nptype):
- with self.test_session():
+ with self.test_session(use_gpu=True):
image = constant_op.constant(img_np, shape=img_shape)
y = image_ops.resize_images(image, target_height, target_width, opt)
expected = np.array(expected_data).reshape(target_shape)
@@ -1133,7 +1133,7 @@ class ResizeImagesTest(test_util.TensorFlowTestCase):
image_ops.ResizeMethod.NEAREST_NEIGHBOR,
image_ops.ResizeMethod.AREA]:
if test.is_gpu_available() and self.shouldRunOnGPU(opt, nptype):
- with self.test_session():
+ with self.test_session(use_gpu=True):
img_np = np.array(data, dtype=nptype).reshape(img_shape)
image = constant_op.constant(img_np, shape=img_shape)
y = image_ops.resize_images(image, target_height, target_width, opt)
@@ -1162,7 +1162,7 @@ class ResizeImagesTest(test_util.TensorFlowTestCase):
70, 69, 75, 81, 80, 72, 69, 70,
105, 112, 75, 36, 45, 92, 111, 105]
- with self.test_session():
+ with self.test_session(use_gpu=True):
image = constant_op.constant(img_np, shape=img_shape)
y = image_ops.resize_images(image, target_height, target_width,
image_ops.ResizeMethod.BICUBIC)
@@ -1188,7 +1188,7 @@ class ResizeImagesTest(test_util.TensorFlowTestCase):
14, 16, 19, 21,
14, 16, 19, 21]
- with self.test_session():
+ with self.test_session(use_gpu=True):
image = constant_op.constant(img_np, shape=img_shape)
y = image_ops.resize_images(image, target_height, target_width,
image_ops.ResizeMethod.AREA)
@@ -1261,7 +1261,7 @@ class ResizeImageWithCropOrPadTest(test_util.TensorFlowTestCase):
if not use_tensor_inputs:
self.assertTrue(y.get_shape().is_fully_defined())
- with self.test_session():
+ with self.test_session(use_gpu=True):
return y.eval(feed_dict=feed_dict)
def _assertReturns(self, x, x_shape, y, y_shape,
@@ -1495,7 +1495,7 @@ class JpegTest(test_util.TensorFlowTestCase):
# Read a real jpeg and verify shape
path = ('tensorflow/core/lib/jpeg/testdata/'
'jpeg_merge_test1.jpg')
- with self.test_session() as sess:
+ with self.test_session(use_gpu=True) as sess:
jpeg0 = io_ops.read_file(path)
image0 = image_ops.decode_jpeg(jpeg0)
image1 = image_ops.decode_jpeg(image_ops.encode_jpeg(image0))
@@ -1511,7 +1511,7 @@ class JpegTest(test_util.TensorFlowTestCase):
cmyk_path = os.path.join(base, 'jpeg_merge_test1_cmyk.jpg')
shape = 256, 128, 3
for channels in 3, 0:
- with self.test_session() as sess:
+ with self.test_session(use_gpu=True) as sess:
rgb = image_ops.decode_jpeg(io_ops.read_file(rgb_path),
channels=channels)
cmyk = image_ops.decode_jpeg(io_ops.read_file(cmyk_path),
@@ -1523,7 +1523,7 @@ class JpegTest(test_util.TensorFlowTestCase):
self.assertLess(error, 4)
def testSynthetic(self):
- with self.test_session() as sess:
+ with self.test_session(use_gpu=True) as sess:
# Encode it, then decode it, then encode it
image0 = constant_op.constant(_SimpleColorRamp())
jpeg0 = image_ops.encode_jpeg(image0)
@@ -1542,7 +1542,7 @@ class JpegTest(test_util.TensorFlowTestCase):
self.assertLessEqual(len(jpeg0), 6000)
def testShape(self):
- with self.test_session() as sess:
+ with self.test_session(use_gpu=True) as sess:
jpeg = constant_op.constant('nonsense')
for channels in 0, 1, 3:
image = image_ops.decode_jpeg(jpeg, channels=channels)
@@ -1558,7 +1558,7 @@ class PngTest(test_util.TensorFlowTestCase):
inputs = (1, 'lena_gray.png'), (4, 'lena_rgba.png')
for channels_in, filename in inputs:
for channels in 0, 1, 3, 4:
- with self.test_session() as sess:
+ with self.test_session(use_gpu=True) as sess:
png0 = io_ops.read_file(prefix + filename)
image0 = image_ops.decode_png(png0, channels=channels)
png0, image0 = sess.run([png0, image0])
@@ -1568,7 +1568,7 @@ class PngTest(test_util.TensorFlowTestCase):
self.assertAllEqual(image0, image1.eval())
def testSynthetic(self):
- with self.test_session() as sess:
+ with self.test_session(use_gpu=True) as sess:
# Encode it, then decode it
image0 = constant_op.constant(_SimpleColorRamp())
png0 = image_ops.encode_png(image0, compression=7)
@@ -1583,7 +1583,7 @@ class PngTest(test_util.TensorFlowTestCase):
self.assertLessEqual(len(png0), 750)
def testSyntheticUint16(self):
- with self.test_session() as sess:
+ with self.test_session(use_gpu=True) as sess:
# Encode it, then decode it
image0 = constant_op.constant(_SimpleColorRamp(), dtype=dtypes.uint16)
png0 = image_ops.encode_png(image0, compression=7)
@@ -1598,7 +1598,7 @@ class PngTest(test_util.TensorFlowTestCase):
self.assertLessEqual(len(png0), 1500)
def testSyntheticTwoChannel(self):
- with self.test_session() as sess:
+ with self.test_session(use_gpu=True) as sess:
# Strip the b channel from an rgb image to get a two-channel image.
gray_alpha = _SimpleColorRamp()[:, :, 0:2]
image0 = constant_op.constant(gray_alpha)
@@ -1609,7 +1609,7 @@ class PngTest(test_util.TensorFlowTestCase):
self.assertAllEqual(image0, image1)
def testSyntheticTwoChannelUint16(self):
- with self.test_session() as sess:
+ with self.test_session(use_gpu=True) as sess:
# Strip the b channel from an rgb image to get a two-channel image.
gray_alpha = _SimpleColorRamp()[:, :, 0:2]
image0 = constant_op.constant(gray_alpha, dtype=dtypes.uint16)
@@ -1620,7 +1620,7 @@ class PngTest(test_util.TensorFlowTestCase):
self.assertAllEqual(image0, image1)
def testShape(self):
- with self.test_session():
+ with self.test_session(use_gpu=True):
png = constant_op.constant('nonsense')
for channels in 0, 1, 3:
image = image_ops.decode_png(png, channels=channels)
@@ -1639,7 +1639,7 @@ class GifTest(test_util.TensorFlowTestCase):
STRIDE = 5
shape = (12, HEIGHT, WIDTH, 3)
- with self.test_session() as sess:
+ with self.test_session(use_gpu=True) as sess:
gif0 = io_ops.read_file(prefix + filename)
image0 = image_ops.decode_gif(gif0)
gif0, image0 = sess.run([gif0, image0])
@@ -1665,14 +1665,14 @@ class GifTest(test_util.TensorFlowTestCase):
prefix = 'tensorflow/core/lib/gif/testdata/'
filename = 'optimized.gif'
- with self.test_session() as sess:
+ with self.test_session(use_gpu=True) as sess:
gif0 = io_ops.read_file(prefix + filename)
image0 = image_ops.decode_gif(gif0)
with self.assertRaises(errors.InvalidArgumentError):
gif0, image0 = sess.run([gif0, image0])
def testShape(self):
- with self.test_session() as sess:
+ with self.test_session(use_gpu=True) as sess:
gif = constant_op.constant('nonsense')
image = image_ops.decode_gif(gif)
self.assertEqual(image.get_shape().as_list(),
@@ -1684,7 +1684,7 @@ class ConvertImageTest(test_util.TensorFlowTestCase):
x_np = np.array(original, dtype=original_dtype.as_numpy_dtype())
y_np = np.array(expected, dtype=output_dtype.as_numpy_dtype())
- with self.test_session():
+ with self.test_session(use_gpu=True):
image = constant_op.constant(x_np)
y = image_ops.convert_image_dtype(image, output_dtype)
self.assertTrue(y.dtype == output_dtype)
@@ -1692,7 +1692,7 @@ class ConvertImageTest(test_util.TensorFlowTestCase):
def testNoConvert(self):
# Make sure converting to the same data type creates only an identity op
- with self.test_session():
+ with self.test_session(use_gpu=True):
image = constant_op.constant([1], dtype=dtypes.uint8)
image_ops.convert_image_dtype(image, dtypes.uint8)
y = image_ops.convert_image_dtype(image, dtypes.uint8)
@@ -1701,13 +1701,13 @@ class ConvertImageTest(test_util.TensorFlowTestCase):
def testConvertBetweenInteger(self):
# Make sure converting to between integer types scales appropriately
- with self.test_session():
+ with self.test_session(use_gpu=True):
self._convert([0, 255], dtypes.uint8, dtypes.int16, [0, 255 * 128])
self._convert([0, 32767], dtypes.int16, dtypes.uint8, [0, 255])
def testConvertBetweenFloat(self):
# Make sure converting to between float types does nothing interesting
- with self.test_session():
+ with self.test_session(use_gpu=True):
self._convert([-1.0, 0, 1.0, 200000], dtypes.float32, dtypes.float64,
[-1.0, 0, 1.0, 200000])
self._convert([-1.0, 0, 1.0, 200000], dtypes.float64, dtypes.float32,
@@ -1715,7 +1715,7 @@ class ConvertImageTest(test_util.TensorFlowTestCase):
def testConvertBetweenIntegerAndFloat(self):
# Make sure converting from and to a float type scales appropriately
- with self.test_session():
+ with self.test_session(use_gpu=True):
self._convert([0, 1, 255], dtypes.uint8, dtypes.float32,
[0, 1.0 / 255.0, 1])
self._convert([0, 1.1 / 255.0, 1], dtypes.float32, dtypes.uint8,
diff --git a/tensorflow/python/ops/math_grad_test.py b/tensorflow/python/ops/math_grad_test.py
index 861ff64224..c121a1c098 100644
--- a/tensorflow/python/ops/math_grad_test.py
+++ b/tensorflow/python/ops/math_grad_test.py
@@ -33,7 +33,7 @@ class SquaredDifferenceOpTest(tf.test.TestCase):
l = np.random.randn(*left_shape)
r = np.random.randn(*right_shape)
- with self.test_session():
+ with self.test_session(use_gpu=True):
left_tensor = tf.constant(l, shape=left_shape)
right_tensor = tf.constant(r, shape=right_shape)
output = tf.squared_difference(left_tensor, right_tensor)
@@ -71,7 +71,7 @@ class AbsOpTest(tf.test.TestCase):
value = tf.convert_to_tensor(self._biasedRandN(shape, bias=bias),
dtype=dtype)
- with self.test_session():
+ with self.test_session(use_gpu=True):
if dtype in (tf.complex64, tf.complex128):
output = tf.complex_abs(value)
else: