def subpixel_conv(inputs, factor=2, name='subpixel', data_format='channels_last', **kwargs):
""" Resize input tensor with subpixel convolution (depth to space operation)
Parameters
----------
inputs : tf.Tensor
a tensor to resize
factor : int
upsampling factor
name : str
scope name
data_format : {'channels_last', 'channels_first'}
position of the channels dimension
Returns
-------
tf.Tensor
"""
dim = inputs.shape.ndims - 2
_, channels = _calc_size(inputs, factor, data_format)
layout = kwargs.get('layout', 'cna')
kwargs['filters'] = channels*factor**dim
with tf.variable_scope(name):
x = conv_block(inputs, layout, kernel_size=1, name='conv', data_format=data_format, **kwargs)
x = depth_to_space(x, block_size=factor, name='d2s', data_format=data_format)
return x
评论列表
文章目录