本文整理汇总了Python中tensorflow.depth_to_space方法的典型用法代码示例。如果您正苦于以下问题:Python tensorflow.depth_to_space方法的具体用法?Python tensorflow.depth_to_space怎么用?Python tensorflow.depth_to_space使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow
的用法示例。
在下文中一共展示了tensorflow.depth_to_space方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: depth_to_space
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import depth_to_space [as 别名]
def depth_to_space(input, scale, data_format=None):
""" Uses phase shift algorithm to convert channels/depth for spatial resolution.
# Arguments
input: Input tensor
scale: n `int` that is `>= 2`. The size of the spatial block.
data_format: 'channels_first' or 'channels_last'.
Whether to use Theano or TensorFlow dimension
ordering in inputs/kernels/ouputs.
# Returns
TODO (PR welcome): Filling this section.
"""
if data_format is None:
data_format = K.image_data_format()
data_format = data_format.lower()
input = _preprocess_conv2d_input(input, data_format)
out = tf.depth_to_space(input, scale)
out = _postprocess_conv2d_output(out, data_format)
return out
示例2: vae_simple_decoder
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import depth_to_space [as 别名]
def vae_simple_decoder(z, scope="VAESimpleDecoder"):
def _upsample_conv2d(net, factor, filters, **kwargs):
net = tf.layers.conv2d(net, filters=factor*factor*filters, **kwargs)
net = tf.depth_to_space(net, block_size=factor)
return net
with tf.variable_scope(scope):
endpoints = {}
net = z # shape (b, 1, 1, c)
net = _upsample_conv2d(
net, kernel_size=3, filters=128, factor=16, activation=tf.nn.relu,
padding="SAME") # shape out: (b, 16, 16, 128)
net = _upsample_conv2d(
net, kernel_size=3, filters=512, factor=2, activation=tf.nn.relu,
padding="SAME") # shape out: (b, 32, 32, 512)
net = _upsample_conv2d(
net, kernel_size=3, filters=512, factor=2, activation=tf.nn.relu,
padding="SAME") # shape out: (b, 64, 64, 512)
net = tf.layers.conv2d(net, kernel_size=3, filters=3, padding="SAME")
return net, endpoints
示例3: upsample_conv
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import depth_to_space [as 别名]
def upsample_conv(inputs, num_outputs, kernel_size, sn, activation_fn=None,
normalizer_fn=None, normalizer_params=None,
weights_regularizer=None,
weights_initializer=ly.xavier_initializer_conv2d(),
biases_initializer=tf.zeros_initializer(),
data_format='NCHW'):
output = inputs
output = tf.concat([output, output, output, output], axis=1 if data_format == 'NCHW' else 3)
if data_format == 'NCHW':
output = tf.transpose(output, [0, 2, 3, 1])
output = tf.depth_to_space(output, 2)
if data_format == 'NCHW':
output = tf.transpose(output, [0, 3, 1, 2])
output = conv2d(output, num_outputs, kernel_size, sn=sn, activation_fn=activation_fn,
normalizer_fn=normalizer_fn, normalizer_params=normalizer_params,
weights_regularizer=weights_regularizer, weights_initializer=weights_initializer,
biases_initializer=biases_initializer,
data_format=data_format)
return output
示例4: forward
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import depth_to_space [as 别名]
def forward(self, x, is_train):
# shape of x: [B,T_in,H,W,C]
# Generate filters and residual
# Fx: [B,1,H,W,1*5*5,R*R]
# Rx: [B,1,H,W,3*R*R]
with tf.variable_scope('G',reuse=tf.AUTO_REUSE) as scope:
Fx, Rx = FR_52L(x, is_train)
x_c = []
for c in range(3):
t = DynFilter3D(x[:,self.num_frames//2:self.num_frames//2+1,:,:,c], Fx[:,0,:,:,:,:], [1,5,5]) # [B,H,W,R*R]
t = tf.depth_to_space(t, self.scale) # [B,H*R,W*R,1]
x_c += [t]
x = tf.concat(x_c, axis=3) # [B,H*R,W*R,3]
x = tf.expand_dims(x, axis=1)
Rx = depth_to_space_3D(Rx, self.scale) # [B,1,H*R,W*R,3]
x += Rx
return x
示例5: upsample2d_block
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import depth_to_space [as 别名]
def upsample2d_block(
inputs,
filters,
kernel_size,
strides,
shuffle_size=2,
name_prefix='upsample2d_block_'):
h1 = conv2d_layer(inputs=inputs, filters=filters, kernel_size=kernel_size, strides=strides, activation=None,
name=name_prefix + 'h1_conv')
h1_shuffle = tf.depth_to_space(input=h1, block_size=2, name='h1_shuffle')
h1_norm = instance_norm_layer(inputs=h1_shuffle, activation_fn=None, name=name_prefix + 'h1_norm')
h1_gates = conv2d_layer(inputs=inputs, filters=filters, kernel_size=kernel_size, strides=strides, activation=None,
name=name_prefix + 'h1_gates')
h1_shuffle_gates = tf.depth_to_space(input=h1_gates, block_size=2, name='h1_shuffle_gates')
h1_norm_gates = instance_norm_layer(inputs=h1_shuffle_gates, activation_fn=None, name=name_prefix + 'h1_norm_gates')
h1_glu = gated_linear_layer(inputs=h1_norm, gates=h1_norm_gates, name=name_prefix + 'h1_glu')
return h1_glu
示例6: build_graph
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import depth_to_space [as 别名]
def build_graph(self):
super(FFDNet, self).build_graph() # build inputs placeholder
with tf.variable_scope(self.name):
# build layers
inputs = self.inputs_preproc[-1] / 255
if self.training:
sigma = tf.random_uniform((), maxval=self.sigma / 255)
inputs += tf.random_normal(tf.shape(inputs)) * sigma
else:
sigma = self.sigma / 255
inputs = tf.space_to_depth(inputs, block_size=self.space_down)
noise_map = tf.ones_like(inputs)[..., 0:1] * sigma
x = tf.concat([inputs, noise_map], axis=-1)
x = self.relu_conv2d(x, 64, 3)
for i in range(1, self.layers - 1):
x = self.bn_relu_conv2d(x, 64, 3, use_bias=False)
# the last layer w/o BN and ReLU
x = self.conv2d(x, self.channel * self.space_down ** 2, 3)
denoised = tf.depth_to_space(x, block_size=self.space_down)
self.outputs.append(denoised * 255)
示例7: subpixel
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import depth_to_space [as 别名]
def subpixel(inp, nfm, upscale=2, name='subpixel'):
# assert inp.get_shape().as_list()[1] % upscale == 0
output = conv2d(inp, nout=nfm * (upscale ** 2), kernel=1, name=name, print_struct=False)
output = tf.transpose(output, [0, 2, 3, 1])
output = tf.depth_to_space(output, upscale)
output = tf.transpose(output, [0, 3, 1, 2])
print name + ': ' + str(output.get_shape().as_list())
return output
示例8: decompress_step
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import depth_to_space [as 别名]
def decompress_step(source, hparams, first_relu, is_2d, name):
"""Decompression function."""
with tf.variable_scope(name):
shape = common_layers.shape_list(source)
multiplier = 4 if is_2d else 2
kernel = (1, 1) if is_2d else (1, 1)
thicker = common_layers.conv_block(
source, hparams.hidden_size * multiplier, [((1, 1), kernel)],
first_relu=first_relu, name="decompress_conv")
if is_2d:
return tf.depth_to_space(thicker, 2)
return tf.reshape(thicker, [shape[0], shape[1] * 2, 1, hparams.hidden_size])
示例9: layer_conv_dts
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import depth_to_space [as 别名]
def layer_conv_dts(self, net, args, options):
options = hc.Config(options)
config = self.config
ops = self.ops
self.ops.activation_name = options.activation_name
activation_s = options.activation or self.ops.config_option("activation")
activation = self.ops.lookup(activation_s)
stride = options.stride or self.ops.config_option("stride", [1,1])[0]
stride = int(stride)
fltr = options.filter or self.ops.config_option("filter", [3,3])
if type(fltr) == type(""):
fltr=[int(fltr), int(fltr)]
depth = int(args[0])
initializer = None # default to global
trainable = True
if options.trainable == 'false':
trainable = False
bias = True
if options.bias == 'false':
bias=False
net = ops.conv2d(net, fltr[0], fltr[1], stride, stride, depth*4, initializer=initializer, trainable=trainable, bias=bias)
s = ops.shape(net)
net = tf.depth_to_space(net, 2)
if activation:
#net = self.layer_regularizer(net)
net = activation(net)
avg_pool = options.avg_pool or self.ops.config_option("avg_pool")
if type(avg_pool) == type(""):
avg_pool = [int(avg_pool), int(avg_pool)]
if avg_pool:
ksize = [1,avg_pool[0], avg_pool[1],1]
stride = ksize
net = tf.nn.avg_pool(net, ksize=ksize, strides=stride, padding='SAME')
return net
示例10: SubpixelConv2D
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import depth_to_space [as 别名]
def SubpixelConv2D(*args, **kwargs):
kwargs['output_dim'] = 4*kwargs['output_dim']
output = lib.ops.conv2d.Conv2D(*args, **kwargs)
output = tf.transpose(output, [0,2,3,1])
output = tf.depth_to_space(output, 2)
output = tf.transpose(output, [0,3,1,2])
return output
示例11: UpsampleConv
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import depth_to_space [as 别名]
def UpsampleConv(name, input_dim, output_dim, filter_size, inputs, he_init=True, biases=True):
output = inputs
output = tf.concat([output, output, output, output], axis=1)
output = tf.transpose(output, [0,2,3,1])
output = tf.depth_to_space(output, 2)
output = tf.transpose(output, [0,3,1,2])
output = lib.ops.conv2d.Conv2D(name, input_dim, output_dim, filter_size, output, he_init=he_init, biases=biases)
return output
示例12: conv_pixel_shuffle_up
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import depth_to_space [as 别名]
def conv_pixel_shuffle_up(x, scale_factor=2, use_bias=True, sn=False, scope='pixel_shuffle'):
channel = x.get_shape()[-1] * (scale_factor ** 2)
x = conv(x, channel, kernel=1, stride=1, use_bias=use_bias, sn=sn, scope=scope)
x = tf.depth_to_space(x, block_size=scale_factor)
return x
示例13: UpsampleConv
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import depth_to_space [as 别名]
def UpsampleConv(input, output_dim, filter_size, name, spectral_normed=False, update_collection=None, he_init=True):
output = input
output = tf.concat([output, output, output, output], axis=3)
output = tf.depth_to_space(output, 2)
return conv2d(output, output_dim, filter_size, spectral_normed=spectral_normed,
update_collection=update_collection, name=name, he_init=he_init)
示例14: depth_to_space
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import depth_to_space [as 别名]
def depth_to_space(input, scale, data_format=None):
''' Uses phase shift algorithm to convert channels/depth for spatial resolution '''
data_format = 'NHWC'
data_format = data_format.lower()
out = tf.depth_to_space(input, scale, data_format=data_format)
return out
示例15: upsample
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import depth_to_space [as 别名]
def upsample(x):
x = tf.concat([x, x, x, x], axis=-1)
x = tf.depth_to_space(x, 2)
return x
##################################################################################
# Activation function
##################################################################################