本文整理汇总了Python中tensorflow.python.platform.test.is_gpu_available方法的典型用法代码示例。如果您正苦于以下问题:Python test.is_gpu_available方法的具体用法?Python test.is_gpu_available怎么用?Python test.is_gpu_available使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow.python.platform.test
的用法示例。
在下文中一共展示了test.is_gpu_available方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testDynamicOutputSizeWithRateOneValidPaddingNCHW
# 需要导入模块: from tensorflow.python.platform import test [as 别名]
# 或者: from tensorflow.python.platform.test import is_gpu_available [as 别名]
def testDynamicOutputSizeWithRateOneValidPaddingNCHW(self):
if test.is_gpu_available(cuda_only=True):
num_filters = 32
input_size = [5, 3, 9, 11]
expected_size = [None, num_filters, None, None]
expected_size_dynamic = [5, num_filters, 7, 9]
with self.session(use_gpu=True):
images = array_ops.placeholder(np.float32,
[None, input_size[1], None, None])
output = layers_lib.convolution2d(
images,
num_filters, [3, 3],
rate=1,
padding='VALID',
data_format='NCHW')
variables_lib.global_variables_initializer().run()
self.assertEqual(output.op.name, 'Conv/Relu')
self.assertListEqual(output.get_shape().as_list(), expected_size)
eval_output = output.eval({images: np.zeros(input_size, np.float32)})
self.assertListEqual(list(eval_output.shape), expected_size_dynamic)
示例2: testOutputSizeWithStrideOneSamePaddingNCHW
# 需要导入模块: from tensorflow.python.platform import test [as 别名]
# 或者: from tensorflow.python.platform.test import is_gpu_available [as 别名]
def testOutputSizeWithStrideOneSamePaddingNCHW(self):
# `NCHW` data format is only supported for `GPU` device.
if test.is_gpu_available(cuda_only=True):
with self.session(use_gpu=True) as sess:
num_filters = 32
input_size = [5, 3, 10, 12]
expected_size = [5, num_filters, 10, 12]
images = random_ops.random_uniform(input_size, seed=1)
output = layers_lib.conv2d_transpose(
images,
num_filters, [3, 3],
stride=1,
padding='SAME',
data_format='NCHW')
self.assertEqual(output.op.name, 'Conv2d_transpose/Relu')
sess.run(variables_lib.global_variables_initializer())
self.assertListEqual(list(output.eval().shape), expected_size)
示例3: testOutputSizeWithStrideOneValidPaddingNCHW
# 需要导入模块: from tensorflow.python.platform import test [as 别名]
# 或者: from tensorflow.python.platform.test import is_gpu_available [as 别名]
def testOutputSizeWithStrideOneValidPaddingNCHW(self):
if test.is_gpu_available(cuda_only=True):
with self.session(use_gpu=True) as sess:
num_filters = 32
input_size = [5, 3, 10, 12]
expected_size = [5, num_filters, 12, 14]
images = random_ops.random_uniform(input_size, seed=1)
output = layers_lib.conv2d_transpose(
images,
num_filters, [3, 3],
stride=1,
padding='VALID',
data_format='NCHW')
self.assertEqual(output.op.name, 'Conv2d_transpose/Relu')
sess.run(variables_lib.global_variables_initializer())
self.assertListEqual(list(output.eval().shape), expected_size)
示例4: testOutputSizeWithStrideTwoValidPaddingNCHW
# 需要导入模块: from tensorflow.python.platform import test [as 别名]
# 或者: from tensorflow.python.platform.test import is_gpu_available [as 别名]
def testOutputSizeWithStrideTwoValidPaddingNCHW(self):
if test.is_gpu_available(cuda_only=True):
with self.session(use_gpu=True) as sess:
num_filters = 32
input_size = [5, 3, 9, 11]
expected_size = [5, num_filters, 19, 23]
images = random_ops.random_uniform(input_size, seed=1)
output = layers_lib.conv2d_transpose(
images,
num_filters, [3, 3],
stride=[2, 2],
padding='VALID',
data_format='NCHW')
self.assertEqual(output.op.name, 'Conv2d_transpose/Relu')
self.assertListEqual(list(output.get_shape().as_list()), expected_size)
sess.run(variables_lib.global_variables_initializer())
self.assertListEqual(list(output.eval().shape), expected_size)
示例5: testOutputSizeWith1x1StrideTwoSamePaddingNCHW
# 需要导入模块: from tensorflow.python.platform import test [as 别名]
# 或者: from tensorflow.python.platform.test import is_gpu_available [as 别名]
def testOutputSizeWith1x1StrideTwoSamePaddingNCHW(self):
if test.is_gpu_available(cuda_only=True):
with self.session(use_gpu=True) as sess:
num_filters = 1
input_size = [1, 1, 1, 1]
expected_size = [1, num_filters, 2, 2]
images = random_ops.random_uniform(input_size, seed=1)
output = layers_lib.conv2d_transpose(
images,
num_filters, [2, 2],
stride=[2, 2],
padding='SAME',
data_format='NCHW')
self.assertListEqual(list(output.get_shape().as_list()), expected_size)
sess.run(variables_lib.global_variables_initializer())
self.assertEqual(output.op.name, 'Conv2d_transpose/Relu')
self.assertListEqual(list(output.eval().shape), expected_size)
示例6: testOutputSizeWith2x2StrideTwoSamePaddingNCHW
# 需要导入模块: from tensorflow.python.platform import test [as 别名]
# 或者: from tensorflow.python.platform.test import is_gpu_available [as 别名]
def testOutputSizeWith2x2StrideTwoSamePaddingNCHW(self):
if test.is_gpu_available(cuda_only=True):
with self.session(use_gpu=True) as sess:
num_filters = 1
input_size = [1, 1, 2, 2]
expected_size = [1, num_filters, 4, 4]
images = random_ops.random_uniform(input_size, seed=1)
output = layers_lib.conv2d_transpose(
images,
num_filters, [2, 2],
stride=[2, 2],
padding='SAME',
data_format='NCHW')
sess.run(variables_lib.global_variables_initializer())
self.assertEqual(output.op.name, 'Conv2d_transpose/Relu')
self.assertListEqual(list(output.eval().shape), expected_size)
示例7: testOutputSizeWith2x2StrideTwoValidPaddingNCHW
# 需要导入模块: from tensorflow.python.platform import test [as 别名]
# 或者: from tensorflow.python.platform.test import is_gpu_available [as 别名]
def testOutputSizeWith2x2StrideTwoValidPaddingNCHW(self):
if test.is_gpu_available(cuda_only=True):
with self.session(use_gpu=True) as sess:
num_filters = 1
input_size = [1, 1, 2, 2]
expected_size = [1, num_filters, 4, 4]
images = random_ops.random_uniform(input_size, seed=1)
output = layers_lib.conv2d_transpose(
images,
num_filters, [2, 2],
stride=[2, 2],
padding='VALID',
data_format='NCHW')
sess.run(variables_lib.global_variables_initializer())
self.assertEqual(output.op.name, 'Conv2d_transpose/Relu')
self.assertListEqual(list(output.eval().shape), expected_size)
示例8: testOutputSizeWithStride2x1NCHW
# 需要导入模块: from tensorflow.python.platform import test [as 别名]
# 或者: from tensorflow.python.platform.test import is_gpu_available [as 别名]
def testOutputSizeWithStride2x1NCHW(self):
if test.is_gpu_available(cuda_only=True):
with self.session(use_gpu=True) as sess:
num_filters = 1
input_size = [1, 1, 3, 2]
expected_size = [1, num_filters, 6, 5]
images = random_ops.random_uniform(input_size, seed=1)
output = layers_lib.conv2d_transpose(
images,
num_filters, [2, 4],
stride=[2, 1],
padding='VALID',
data_format='NCHW')
sess.run(variables_lib.global_variables_initializer())
self.assertEqual(output.op.name, 'Conv2d_transpose/Relu')
self.assertListEqual(list(output.eval().shape), expected_size)
示例9: testOutputSizeWithStride2x4NCHW
# 需要导入模块: from tensorflow.python.platform import test [as 别名]
# 或者: from tensorflow.python.platform.test import is_gpu_available [as 别名]
def testOutputSizeWithStride2x4NCHW(self):
if test.is_gpu_available(cuda_only=True):
with self.session(use_gpu=True) as sess:
num_filters = 1
input_size = [1, 1, 3, 2]
expected_size = [1, num_filters, 6, 8]
images = random_ops.random_uniform(input_size, seed=1)
output = layers_lib.conv2d_transpose(
images,
num_filters, [2, 4],
stride=[2, 4],
padding='VALID',
data_format='NCHW')
sess.run(variables_lib.global_variables_initializer())
self.assertEqual(output.op.name, 'Conv2d_transpose/Relu')
self.assertListEqual(list(output.eval().shape), expected_size)
示例10: testOutputSizeWithStride2x5NCHW
# 需要导入模块: from tensorflow.python.platform import test [as 别名]
# 或者: from tensorflow.python.platform.test import is_gpu_available [as 别名]
def testOutputSizeWithStride2x5NCHW(self):
if test.is_gpu_available(cuda_only=True):
with self.session(use_gpu=True) as sess:
num_filters = 1
input_size = [1, 1, 3, 2]
expected_size = [1, num_filters, 6, 10]
images = random_ops.random_uniform(input_size, seed=1)
output = layers_lib.conv2d_transpose(
images,
num_filters, [2, 4],
stride=[2, 5],
padding='VALID',
data_format='NCHW')
sess.run(variables_lib.global_variables_initializer())
self.assertEqual(output.op.name, 'Conv2d_transpose/Relu')
self.assertListEqual(list(output.eval().shape), expected_size)
示例11: testCompareBilinear
# 需要导入模块: from tensorflow.python.platform import test [as 别名]
# 或者: from tensorflow.python.platform.test import is_gpu_available [as 别名]
def testCompareBilinear(self):
if test.is_gpu_available():
input_shape = [1, 5, 6, 3]
target_height = 8
target_width = 12
for nptype in [np.float32, np.float64]:
for align_corners in [True, False]:
img_np = np.arange(
0, np.prod(input_shape), dtype=nptype).reshape(input_shape)
value = {}
for use_gpu in [True, False]:
with self.test_session(use_gpu=use_gpu):
image = constant_op.constant(img_np, shape=input_shape)
new_size = constant_op.constant([target_height, target_width])
out_op = image_ops.resize_images(
image, new_size,
image_ops.ResizeMethod.BILINEAR,
align_corners=align_corners)
value[use_gpu] = out_op.eval()
self.assertAllClose(value[True], value[False], rtol=1e-5, atol=1e-5)
示例12: _check_has_gpu
# 需要导入模块: from tensorflow.python.platform import test [as 别名]
# 或者: from tensorflow.python.platform.test import is_gpu_available [as 别名]
def _check_has_gpu():
if not test.is_gpu_available(cuda_only=True):
raise ValueError(
"""You have asked to run part or all of this on GPU, but it appears
that no GPU is available. If your machine has GPUs it is possible you
do not have a version of TensorFlow with GPU support. To build with GPU
support, add --config=cuda to the build flags.\n """)
示例13: gpu_availability
# 需要导入模块: from tensorflow.python.platform import test [as 别名]
# 或者: from tensorflow.python.platform.test import is_gpu_available [as 别名]
def gpu_availability():
"""
Detect gpu on user system
:return: Whether at least a CUDA compatible GPU is detected and usable
:rtype: bool
:History: 2018-Apr-25 - Written - Henry Leung (University of Toronto)
"""
# assume if using tensorflow-gpu, then Nvidia GPU is available
if is_built_with_cuda():
return is_gpu_available()
else:
return is_built_with_cuda()
示例14: setUpClass
# 需要导入模块: from tensorflow.python.platform import test [as 别名]
# 或者: from tensorflow.python.platform.test import is_gpu_available [as 别名]
def setUpClass(cls):
if test.is_gpu_available():
cls._expected_partition_graph_count = 2
cls._expected_num_devices = 2
cls._main_device = "/job:localhost/replica:0/task:0/gpu:0"
else:
cls._expected_partition_graph_count = 1
cls._expected_num_devices = 1
cls._main_device = "/job:localhost/replica:0/task:0/cpu:0"
示例15: testMaxPoolingWithArgmax
# 需要导入模块: from tensorflow.python.platform import test [as 别名]
# 或者: from tensorflow.python.platform.test import is_gpu_available [as 别名]
def testMaxPoolingWithArgmax(self):
# MaxPoolWithArgMax is implemented only on CUDA.
if not test.is_gpu_available(cuda_only=True):
return
'''[[[[ 1. 2.]
[ 3. 4.]
[ 5. 6.]]
[[ 7. 8.]
[ 9. 10.]
[ 11. 12.]]
[[ 13. 14.]
[ 15. 16.]
[ 17. 18.]]]]'''
tensor_input = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0,
10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0]
with self.test_session(use_gpu=True) as sess:
t = constant_op.constant(tensor_input, shape=[1, 3, 3, 2])
out_op, argmax_op = segnet_vgg.max_pool_with_argmax(t)
out, argmax = sess.run([out_op, argmax_op])
self.assertShapeEqual(out, out_op)
self.assertShapeEqual(argmax, argmax_op)
'''[[[9, 10]
[11, 12]]
[[15, 16]
[17, 18]]]'''
self.assertAllClose(out.ravel(), [9., 10., 11., 12., 15., 16., 17., 18.])
self.assertAllEqual(argmax.ravel(), [8, 9, 10, 11, 14, 15, 16, 17])