GFPGAN icon indicating copy to clipboard operation
GFPGAN copied to clipboard

Realesrgam is slow on cpu we do not use it

Open CrazyWolf13 opened this issue 1 year ago • 5 comments

UserWarning: The unoptimized RealESRGAN is slow on CPU. We do not use it. If you really want to use it, please modify the corresponding codes. warnings.warn('The unoptimized RealESRGAN is slow on CPU. We do not use it.

Appears always, I have CUDA installed.

CrazyWolf13 avatar Sep 26 '23 20:09 CrazyWolf13

I had the same issue but working now. But why is the correct version not installed automatically? this error happens to me so often with CUDA. For my version, I had to do: pip uninstall torch pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121

vootox avatar Oct 08 '23 02:10 vootox

I had the same issue but working now. But why is the correct version not installed automatically? this error happens to me so often with CUDA. For my version, I had to do: pip uninstall torch pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121

Yeah I got it working on my main PC but I'd like to use the whole GFPGAN project on a pc without a GPU only internal IGPU is there a way to allow realesrgam to work? Because I only get this error message, It even states modify the code to still allow realesrgam but I don't know where.

CrazyWolf13 avatar Oct 15 '23 09:10 CrazyWolf13

@CrazyWolf13 I think it should be a simple change in inference_gfpgan.py from :

    if args.bg_upsampler == 'realesrgan':
        if not torch.cuda.is_available():  # CPU
            import warnings
            warnings.warn('The unoptimized RealESRGAN is slow on CPU. We do not use it. '
                          'If you really want to use it, please modify the corresponding codes.')
            bg_upsampler = None
        else:
            from basicsr.archs.rrdbnet_arch import RRDBNet
            from realesrgan import RealESRGANer
            model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32, scale=2)
            bg_upsampler = RealESRGANer(
                scale=2,
                model_path='https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.1/RealESRGAN_x2plus.pth',
                model=model,
                tile=args.bg_tile,
                tile_pad=10,
                pre_pad=0,
                half=True)  # need to set False in CPU mode
    else:
        bg_upsampler = None

to

    if args.bg_upsampler == 'realesrgan':
            from basicsr.archs.rrdbnet_arch import RRDBNet
            from realesrgan import RealESRGANer
            model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32, scale=2)
            bg_upsampler = RealESRGANer(
                scale=2,
                model_path='https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.1/RealESRGAN_x2plus.pth',
                model=model,
                tile=args.bg_tile,
                tile_pad=10,
                pre_pad=0,
                half=False)  # need to set False in CPU mode
    else:
        bg_upsampler = None

let me know if that works out for you

PedCoelho avatar Dec 20 '23 19:12 PedCoelho

@CrazyWolf13 I think it should be a simple change in inference_gfpgan.py from :

    if args.bg_upsampler == 'realesrgan':
        if not torch.cuda.is_available():  # CPU
            import warnings
            warnings.warn('The unoptimized RealESRGAN is slow on CPU. We do not use it. '
                          'If you really want to use it, please modify the corresponding codes.')
            bg_upsampler = None
        else:
            from basicsr.archs.rrdbnet_arch import RRDBNet
            from realesrgan import RealESRGANer
            model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32, scale=2)
            bg_upsampler = RealESRGANer(
                scale=2,
                model_path='https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.1/RealESRGAN_x2plus.pth',
                model=model,
                tile=args.bg_tile,
                tile_pad=10,
                pre_pad=0,
                half=True)  # need to set False in CPU mode
    else:
        bg_upsampler = None

to

    if args.bg_upsampler == 'realesrgan':
            from basicsr.archs.rrdbnet_arch import RRDBNet
            from realesrgan import RealESRGANer
            model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32, scale=2)
            bg_upsampler = RealESRGANer(
                scale=2,
                model_path='https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.1/RealESRGAN_x2plus.pth',
                model=model,
                tile=args.bg_tile,
                tile_pad=10,
                pre_pad=0,
                half=False)  # need to set False in CPU mode
    else:
        bg_upsampler = None

let me know if that works out for you

Thanks for the answer, but sadly that didn't work out, I have also already had this idea, but it still didn't work. I guess there must be more deep down the python files...

CrazyWolf13 avatar Dec 20 '23 21:12 CrazyWolf13

@CrazyWolf13

Try this, worked for me:

    if args.bg_upsampler == 'realesrgan':
        if False:  # CPU
            import warnings
            warnings.warn('The unoptimized RealESRGAN is slow on CPU. We do not use it. '
                          'If you really want to use it, please modify the corresponding codes.')
            bg_upsampler = None
        else:
            from basicsr.archs.rrdbnet_arch import RRDBNet
            from realesrgan import RealESRGANer
            model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32, scale=2)
            bg_upsampler = RealESRGANer(
                scale=2,
                model_path='https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.1/RealESRGAN_x2plus.pth',
                model=model,
                tile=args.bg_tile,
                tile_pad=10,
                pre_pad=0,
                half=False)  # need to set False in CPU mode
    else:
        bg_upsampler = None

DNucX avatar Feb 24 '24 02:02 DNucX