(x, w, k=None, factor=2, gain=1, data_format='NCHW', impl='cuda')
return _simple_upfirdn_2d(x, k, pad0=(p+1)//2+factor-1, pad1=p//2+1, data_format=data_format, impl=impl)
r"""Fused `upsample_2d()` followed by `tf.nn.conv2d()`.

    Padding is performed only once at the beginning, not between the operations.
    The fused op is considerably more efficient than performing the same calculation
    using standard TensorFlow ops. It supports gradients of arbitrary order.

    Args:
        x:            Input tensor of the shape `[N, C, H, W]` or `[N, H, W, C]`.
        w:            Weight tensor of the shape `[filterH, filterW, inChannels, outChannels]`.
                      Grouped convolution can be performed by `inChannels = x.shape[0] // numGroups`.
        k:            FIR filter of the shape `[firH, firW]` or `[firN]` (separable).
                      The default is `[1] * factor`, which corresponds to nearest-neighbor
                      upsampling.
        factor:       Integer upsampling factor (default: 2).
        gain:         Scaling factor for signal magnitude (default: 1.0).
        data_format:  `'NCHW'` or `'NHWC'` (default: `'NCHW'`).
        impl:         Name of the implementation to use. Can be `"ref"` or `"cuda"` (default).

    Returns:
        Tensor of the shape `[N, C, H * factor, W * factor]` or
        `[N, H * factor, W * factor, C]`, and same datatype as `x`.
r"""Fused `upsample_2d()` followed by `tf.nn.conv2d()`.
r Fused upsample_2d () followed by tf . nn . conv2d () .
def upsample_conv_2d(x, w, k=None, factor=2, gain=1, data_format='NCHW', impl='cuda'):
    r"""Fused `upsample_2d()` followed by `tf.nn.conv2d()`.

    Padding is performed only once at the beginning, not between the operations.
    The fused op is considerably more efficient than performing the same calculation
    using standard TensorFlow ops. It supports gradients of arbitrary order.

    Args:
        x:            Input tensor of the shape `[N, C, H, W]` or `[N, H, W, C]`.
        w:            Weight tensor of the shape `[filterH, filterW, inChannels, outChannels]`.
                      Grouped convolution can be performed by `inChannels = x.shape[0] // numGroups`.
        k:            FIR filter of the shape `[firH, firW]` or `[firN]` (separable).
                      The default is `[1] * factor`, which corresponds to nearest-neighbor
                      upsampling.
        factor:       Integer upsampling factor (default: 2).
        gain:         Scaling factor for signal magnitude (default: 1.0).
        data_format:  `'NCHW'` or `'NHWC'` (default: `'NCHW'`).
        impl:         Name of the implementation to use. Can be `"ref"` or `"cuda"` (default).

    Returns:
        Tensor of the shape `[N, C, H * factor, W * factor]` or
        `[N, H * factor, W * factor, C]`, and same datatype as `x`.
    """

    assert isinstance(factor, int) and factor >= 1

    # Check weight shape.
    w = tf.convert_to_tensor(w)
    assert w.shape.rank == 4
    convH = w.shape[0].value
    convW = w.shape[1].value
    inC = _shape(w, 2)
    outC = _shape(w, 3)
    assert convW == convH

    # Setup filter kernel.
    if k is None:
        k = [1] * factor
    k = _setup_kernel(k) * (gain * (factor ** 2))
    p = (k.shape[0] - factor) - (convW - 1)

    # Determine data dimensions.
    if data_format == 'NCHW':
        stride = [1, 1, factor, factor]
        output_shape = [_shape(x, 0), outC, (_shape(x, 2) - 1) * factor + convH, (_shape(x, 3) - 1) * factor + convW]
        num_groups = _shape(x, 1) // inC
    else:
        stride = [1, factor, factor, 1]
        output_shape = [_shape(x, 0), (_shape(x, 1) - 1) * factor + convH, (_shape(x, 2) - 1) * factor + convW, outC]
        num_groups = _shape(x, 3) // inC

    # Transpose weights.
    w = tf.reshape(w, [convH, convW, inC, num_groups, -1])
    w = tf.transpose(w[::-1, ::-1], [0, 1, 4, 3, 2])
    w = tf.reshape(w, [convH, convW, -1, num_groups * inC])

    # Execute.
    x = tf.nn.conv2d_transpose(x, w, output_shape=output_shape, strides=stride, padding='VALID', data_format=data_format)
    return _simple_upfirdn_2d(x, k, pad0=(p+1)//2+factor-1, pad1=p//2+1, data_format=data_format, impl=impl)
def upsample_conv_2d ( x , w , k = None , factor = 2 , gain = 1 , data_format = 'NCHW' , impl = 'cuda' ) : assert isinstance ( factor , int ) and factor >= 1 # Check weight shape. w = tf . convert_to_tensor ( w ) assert w . shape . rank == 4 convH = w . shape [ 0 ] . value convW = w . shape [ 1 ] . value inC = _shape ( w , 2 ) outC = _shape ( w , 3 ) assert convW == convH # Setup filter kernel. if k is None : k = [ 1 ] * factor k = _setup_kernel ( k ) * ( gain * ( factor ** 2 ) ) p = ( k . shape [ 0 ] - factor ) - ( convW - 1 ) # Determine data dimensions. if data_format == 'NCHW' : stride = [ 1 , 1 , factor , factor ] output_shape = [ _shape ( x , 0 ) , outC , ( _shape ( x , 2 ) - 1 ) * factor + convH , ( _shape ( x , 3 ) - 1 ) * factor + convW ] num_groups = _shape ( x , 1 ) // inC else : stride = [ 1 , factor , factor , 1 ] output_shape = [ _shape ( x , 0 ) , ( _shape ( x , 1 ) - 1 ) * factor + convH , ( _shape ( x , 2 ) - 1 ) * factor + convW , outC ] num_groups = _shape ( x , 3 ) // inC # Transpose weights. w = tf . reshape ( w , [ convH , convW , inC , num_groups , - 1 ] ) w = tf . transpose ( w [ : : - 1 , : : - 1 ] , [ 0 , 1 , 4 , 3 , 2 ] ) w = tf . reshape ( w , [ convH , convW , - 1 , num_groups * inC ] ) # Execute. x = tf . nn . conv2d_transpose ( x , w , output_shape = output_shape , strides = stride , padding = 'VALID' , data_format = data_format ) return _simple_upfirdn_2d ( x , k , pad0 = ( p + 1 ) // 2 + factor - 1 , pad1 = p // 2 + 1 , data_format = data_format , impl = impl )