xinntao / Real-ESRGAN

Real-ESRGAN aims at developing Practical Algorithms for General Image/Video Restoration.
BSD 3-Clause "New" or "Revised" License
28.45k stars 3.57k forks source link

How to modified the proposed SR to train with y_only input ? #796

Open vincentweisen1357 opened 6 months ago

vincentweisen1357 commented 6 months ago

Hi all,

In BasicSR, we can add the 'color: y' option to the .YAML file to train with y_only grayscale image. For instance:

datasets: train: name: DIV2K type: PairedImageDataset color: y

However, RealESRGANDataset do not provide this option, so that I tried to modify myself in RealESRGANDataset like this before function return:

    **img_gt = bgr2ycbcr(img_gt, y_only=True)[..., None]**
    img_gt = img2tensor([img_gt], bgr2rgb=True, float32=True)[0]
    kernel = torch.FloatTensor(kernel)
    kernel2 = torch.FloatTensor(kernel2)

But still report an error in realesrnet_model.py

line102 : "Input image tensor permitted channel values are [3], but found 1" out = random_add_poisson_noise_pt( out, scale_range=self.opt['poisson_scale_range'], gray_prob=gray_noise_prob, clip=True, rounds=False)

Anyone can help please?