(x, k, upx, upy, downx, downy, padx0, padx1, pady0, pady1)
return func(x)
Fast CUDA implementation of `upfirdn_2d()` using custom ops.
Fast CUDA implementation of `upfirdn_2d()` using custom ops.
Fast CUDA implementation of upfirdn_2d () using custom ops .
def _upfirdn_2d_cuda(x, k, upx, upy, downx, downy, padx0, padx1, pady0, pady1):
    """Fast CUDA implementation of `upfirdn_2d()` using custom ops."""

    x = tf.convert_to_tensor(x)
    k = np.asarray(k, dtype=np.float32)
    majorDim, inH, inW, minorDim = x.shape.as_list()
    kernelH, kernelW = k.shape
    assert inW >= 1 and inH >= 1
    assert kernelW >= 1 and kernelH >= 1
    assert isinstance(upx, int) and isinstance(upy, int)
    assert isinstance(downx, int) and isinstance(downy, int)
    assert isinstance(padx0, int) and isinstance(padx1, int)
    assert isinstance(pady0, int) and isinstance(pady1, int)

    outW = (inW * upx + padx0 + padx1 - kernelW) // downx + 1
    outH = (inH * upy + pady0 + pady1 - kernelH) // downy + 1
    assert outW >= 1 and outH >= 1

    kc = tf.constant(k, dtype=x.dtype)
    gkc = tf.constant(k[::-1, ::-1], dtype=x.dtype)
    gpadx0 = kernelW - padx0 - 1
    gpady0 = kernelH - pady0 - 1
    gpadx1 = inW * upx - outW * downx + padx0 - upx + 1
    gpady1 = inH * upy - outH * downy + pady0 - upy + 1

    @tf.custom_gradient
    def func(x):
        y = _get_plugin().up_fir_dn2d(x=x, k=kc, upx=upx, upy=upy, downx=downx, downy=downy, padx0=padx0, padx1=padx1, pady0=pady0, pady1=pady1)
        y.set_shape([majorDim, outH, outW, minorDim])
        @tf.custom_gradient
        def grad(dy):
            dx = _get_plugin().up_fir_dn2d(x=dy, k=gkc, upx=downx, upy=downy, downx=upx, downy=upy, padx0=gpadx0, padx1=gpadx1, pady0=gpady0, pady1=gpady1)
            dx.set_shape([majorDim, inH, inW, minorDim])
            return dx, func
        return y, grad
    return func(x)
def _upfirdn_2d_cuda ( x , k , upx , upy , downx , downy , padx0 , padx1 , pady0 , pady1 ) : x = tf . convert_to_tensor ( x ) k = np . asarray ( k , dtype = np . float32 ) majorDim , inH , inW , minorDim = x . shape . as_list ( ) kernelH , kernelW = k . shape assert inW >= 1 and inH >= 1 assert kernelW >= 1 and kernelH >= 1 assert isinstance ( upx , int ) and isinstance ( upy , int ) assert isinstance ( downx , int ) and isinstance ( downy , int ) assert isinstance ( padx0 , int ) and isinstance ( padx1 , int ) assert isinstance ( pady0 , int ) and isinstance ( pady1 , int ) outW = ( inW * upx + padx0 + padx1 - kernelW ) // downx + 1 outH = ( inH * upy + pady0 + pady1 - kernelH ) // downy + 1 assert outW >= 1 and outH >= 1 kc = tf . constant ( k , dtype = x . dtype ) gkc = tf . constant ( k [ : : - 1 , : : - 1 ] , dtype = x . dtype ) gpadx0 = kernelW - padx0 - 1 gpady0 = kernelH - pady0 - 1 gpadx1 = inW * upx - outW * downx + padx0 - upx + 1 gpady1 = inH * upy - outH * downy + pady0 - upy + 1 @ tf . custom_gradient def func ( x ) : y = _get_plugin ( ) . up_fir_dn2d ( x = x , k = kc , upx = upx , upy = upy , downx = downx , downy = downy , padx0 = padx0 , padx1 = padx1 , pady0 = pady0 , pady1 = pady1 ) y . set_shape ( [ majorDim , outH , outW , minorDim ] ) @ tf . custom_gradient def grad ( dy ) : dx = _get_plugin ( ) . up_fir_dn2d ( x = dy , k = gkc , upx = downx , upy = downy , downx = upx , downy = upy , padx0 = gpadx0 , padx1 = gpadx1 , pady0 = gpady0 , pady1 = gpady1 ) dx . set_shape ( [ majorDim , inH , inW , minorDim ] ) return dx , func return y , grad return func ( x )