0

I am using the github ESRGAN of https://github.com/peteryuX/esrgan-tf2/blob/master/train_esrgan.py in tensorflow, and my inputs and outputs have the same size. I already have low_resolution and high_resolution images.

However, when using the code, the generator multiplies by 4 the image, which I want it to be the exact same size. So I can't re insert the generated image in the discriminator.

For example my batch if of size (8, 128,128, 1), and when passing in the generator, it output (16, 512, 512, 1). The discriminator takes a size of (None, 128, 128,1).

I would like that it doesn't upsample, but I feel that it is only what it does ...

The generator is :

def RRDB_Model(size, channels, cfg_net, gc=32, wd=0., name='RRDB_model'):
    """Residual-in-Residual Dense Block based Model """
    nf, nb = cfg_net['nf'], cfg_net['nb']
    lrelu_f = functools.partial(LeakyReLU, alpha=0.2)
    rrdb_f = functools.partial(ResInResDenseBlock, nf=nf, gc=gc, wd=wd)
    conv_f = functools.partial(Conv2D, kernel_size=3, padding='same',
                               bias_initializer='zeros',
                               kernel_initializer=_kernel_init(),
                               kernel_regularizer=_regularizer(wd))
    rrdb_truck_f = tf.keras.Sequential(
        [rrdb_f(name="RRDB_{}".format(i)) for i in range(nb)],
        name='RRDB_trunk')

    # extraction
    x = inputs = Input([size, size, channels], name='input_image')
    fea = conv_f(filters=nf, name='conv_first')(x)
    fea_rrdb = rrdb_truck_f(fea)
    trunck = conv_f(filters=nf, name='conv_trunk')(fea_rrdb)
    fea = fea + trunck

    # upsampling
    size_fea_h = tf.shape(fea)[1] if size is None else size
    size_fea_w = tf.shape(fea)[2] if size is None else size
    fea_resize = tf.image.resize(fea, [size_fea_h * 2, size_fea_w * 2],
                                 method='nearest', name='upsample_nn_1')
    fea = conv_f(filters=nf, activation=lrelu_f(), name='upconv_1')(fea_resize)
    fea_resize = tf.image.resize(fea, [size_fea_h * 4, size_fea_w * 4],
                                 method='nearest', name='upsample_nn_2')
    fea = conv_f(filters=nf, activation=lrelu_f(), name='upconv_2')(fea_resize)
    fea = conv_f(filters=nf, activation=lrelu_f(), name='conv_hr')(fea)
    out = conv_f(filters=channels, name='conv_last')(fea)

    return Model(inputs, out, name=name)

EDIT :

I deleted these lines :

fea_resize = tf.image.resize(fea, [size_fea_h * 2, size_fea_w * 2], method='nearest', name='upsample_nn_1')
fea_resize = tf.image.resize(fea, [size_fea_h * 4, size_fea_w * 4],method='nearest',name='upsample_nn_2')

and kept the convolutions layers "fea"

It worked !

4
  • If I understand correctly, you can just average and downsample right? Commented Nov 19, 2023 at 20:36
  • Yes, but I would be afraid that it changes all the final result and purpose of the network Commented Nov 19, 2023 at 20:49
  • you can use a linear or convolutional layer to downsample, so that the network learns to downsample without destroying information Commented Nov 19, 2023 at 20:50
  • By deleting the "fea_resize" layers, for example ? As result, only the convolutions are left ? Commented Nov 19, 2023 at 20:58

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.