本文整理汇总了Python中tensorflow.batch_to_space方法的典型用法代码示例。如果您正苦于以下问题:Python tensorflow.batch_to_space方法的具体用法?Python tensorflow.batch_to_space怎么用?Python tensorflow.batch_to_space使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow
的用法示例。
在下文中一共展示了tensorflow.batch_to_space方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _checkGrad
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import batch_to_space [as 别名]
def _checkGrad(self, x, crops, block_size):
assert 4 == x.ndim
with self.test_session():
tf_x = tf.convert_to_tensor(x)
tf_y = self.batch_to_space(tf_x, crops, block_size)
epsilon = 1e-5
((x_jacob_t, x_jacob_n)) = tf.test.compute_gradient(
tf_x,
x.shape,
tf_y,
tf_y.get_shape().as_list(),
x_init_value=x,
delta=epsilon)
self.assertAllClose(x_jacob_t, x_jacob_n, rtol=1e-2, atol=epsilon)
# Tests a gradient for batch_to_space of x which is a four dimensional
# tensor of shape [b * block_size * block_size, h, w, d].
示例2: upscale
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import batch_to_space [as 别名]
def upscale(images, scale):
"""Box upscaling (also called nearest neighbors) of images.
Args:
images: A 4D `Tensor` in NHWC format.
scale: A positive integer scale.
Returns:
A 4D `Tensor` of `images` up scaled by a factor `scale`.
Raises:
ValueError: If `scale` is not a positive integer.
"""
scale = _get_validated_scale(scale)
if scale == 1:
return images
return tf.batch_to_space(
tf.tile(images, [scale**2, 1, 1, 1]),
crops=[[0, 0], [0, 0]],
block_size=scale)
示例3: imageRearrange
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import batch_to_space [as 别名]
def imageRearrange(self, image, block=4):
image = tf.slice(image, [0, 0, 0, 0], [block * block, -1, -1, -1])
x1 = tf.batch_to_space(image, [[0, 0], [0, 0]], block)
image_r = tf.reshape(tf.transpose(tf.reshape(x1,
[self.output_size, block, self.output_size, block, self.c_dim])
, [1, 0, 3, 2, 4]),
[1, self.output_size * block, self.output_size * block, self.c_dim])
return image_r
示例4: conv_layers_2
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import batch_to_space [as 别名]
def conv_layers_2(x, bs, max_seq_len, im_dim):
#x = tf.cast(x, tf.float32)
wid, hei, chan = im_dim[0], im_dim[1], im_dim[2]
try:
x = tf.reshape(x, [bs * max_seq_len, wid, hei, chan])
except:
print('image dimensions not compatible')
raise
rate = 3
rem_wid, rem_hei = rate * 2 - (wid % (rate * 2)) , rate * 2 - (hei % (rate * 2))
pad = tf.constant([[np.floor(rem_hei / 2), np.ceil(rem_hei / 2)], [np.floor(rem_wid / 2), np.ceil(rem_wid / 2)]])
pad = tf.cast(pad, tf.int32)
filters1 = tf.Variable(tf.random_normal([3,3,3,5]), dtype=tf.float32)
filters2 = tf.Variable(tf.random_normal([3,3,5,5]), dtype=tf.float32)
filters3 = tf.Variable(tf.random_normal([3,3,5,5]), dtype=tf.float32)
net = space_to_batch(x,paddings=pad,block_size=rate)
net = tf.nn.conv2d(net, filters1, strides=[1, 1, 1, 1], padding="SAME", name="dil_conv_1")
# print "dil_conv_1"
# print net.get_shape()
# net = tf.nn.conv2d(net, filters2, strides=[1, 1, 1, 1], padding="SAME", name="dil_conv_2")
# print "dil_conv_2"
# print net.get_shape()
net = tf.nn.conv2d(net, filters3, strides=[1, 1, 1, 1], padding="SAME", name="dil_conv_3")
# print "dil_conv_3"
# print net.get_shape()
net = batch_to_space(net, crops=pad, block_size=rate)
# print "final_output"
# print net.get_shape()
output = tf.layers.flatten(net)
# print "output"
# print output.get_shape()
return output
示例5: imageSummary
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import batch_to_space [as 别名]
def imageSummary(opt,tag,image,H,W):
blockSize = opt.visBlockSize
imageOne = tf.batch_to_space(image[:blockSize**2],crops=[[0,0],[0,0]],block_size=blockSize)
imagePermute = tf.reshape(imageOne,[H,blockSize,W,blockSize,-1])
imageTransp = tf.transpose(imagePermute,[1,0,3,2,4])
imageBlocks = tf.reshape(imageTransp,[1,H*blockSize,W*blockSize,-1])
summary = tf.summary.image(tag,imageBlocks)
return summary
# restore model
示例6: batch_to_space
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import batch_to_space [as 别名]
def batch_to_space(*args, **kwargs):
"""Call tf.batch_to_space using the correct arguments."""
try:
return tf.batch_to_space(*args, **kwargs)
except TypeError:
if "block_shape" in kwargs:
kwargs["block_size"] = kwargs["block_shape"]
del kwargs["block_shape"]
return tf.batch_to_space(*args, **kwargs)
示例7: batch_to_space
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import batch_to_space [as 别名]
def batch_to_space(*args, **kwargs):
return tf.batch_to_space(*args, **kwargs)
示例8: testDepthToSpaceTranspose
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import batch_to_space [as 别名]
def testDepthToSpaceTranspose(self):
x = np.arange(20 * 5 * 8 * 7, dtype=np.float32).reshape([20, 5, 8, 7])
block_size = 2
crops = np.zeros((2, 2), dtype=np.int32)
y1 = self.batch_to_space(x, crops, block_size=block_size)
y2 = tf.transpose(
tf.depth_to_space(
tf.transpose(x, [3, 1, 2, 0]),
block_size=block_size), [3, 1, 2, 0])
with self.test_session():
self.assertAllEqual(y1.eval(), y2.eval())
示例9: testInputWrongDimMissingBatch
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import batch_to_space [as 别名]
def testInputWrongDimMissingBatch(self):
# The input is missing the first dimension ("batch")
x_np = [[[1], [2]], [[3], [4]]]
crops = np.zeros((2, 2), dtype=np.int32)
block_size = 2
with self.assertRaises(ValueError):
_ = self.batch_to_space(x_np, crops, block_size)
示例10: testBlockSizeOne
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import batch_to_space [as 别名]
def testBlockSizeOne(self):
# The block size is 1. The block size needs to be > 1.
x_np = [[[[1], [2]], [[3], [4]]]]
crops = np.zeros((2, 2), dtype=np.int32)
block_size = 1
with self.assertRaises(ValueError):
out_tf = self.batch_to_space(x_np, crops, block_size)
out_tf.eval()
示例11: testBlockSizeLarger
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import batch_to_space [as 别名]
def testBlockSizeLarger(self):
# The block size is too large for this input.
x_np = [[[[1], [2]], [[3], [4]]]]
crops = np.zeros((2, 2), dtype=np.int32)
block_size = 10
with self.assertRaises(ValueError):
out_tf = self.batch_to_space(x_np, crops, block_size)
out_tf.eval()
示例12: testBlockSizeSquaredNotDivisibleBatch
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import batch_to_space [as 别名]
def testBlockSizeSquaredNotDivisibleBatch(self):
# The block size squared does not divide the batch.
x_np = [[[[1], [2], [3]], [[3], [4], [7]]]]
crops = np.zeros((2, 2), dtype=np.int32)
block_size = 3
with self.assertRaises(ValueError):
_ = self.batch_to_space(x_np, crops, block_size)
示例13: testUnknownShape
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import batch_to_space [as 别名]
def testUnknownShape(self):
t = self.batch_to_space(
tf.placeholder(tf.float32),
tf.placeholder(tf.int32),
block_size=4)
self.assertEqual(4, t.get_shape().ndims)
示例14: batch_to_space
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import batch_to_space [as 别名]
def batch_to_space(*args, **kwargs):
return gen_array_ops._batch_to_space(*args, **kwargs)
示例15: _testPad
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import batch_to_space [as 别名]
def _testPad(self, inputs, paddings, block_size, outputs):
with self.test_session(use_gpu=True):
# outputs = space_to_batch(inputs)
x_tf = self.space_to_batch(
tf.to_float(inputs),
paddings, block_size=block_size)
self.assertAllEqual(x_tf.eval(), outputs)
# inputs = batch_to_space(outputs)
x_tf = self.batch_to_space(
tf.to_float(outputs),
paddings, block_size=block_size)
self.assertAllEqual(x_tf.eval(), inputs)