Realesrgam is slow on cpu we do not use it #397

Open
opened 2026-01-29 21:47:30 +00:00 by claunia · 5 comments
Owner

Originally created by @CrazyWolf13 on GitHub (Sep 26, 2023).

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.

Originally created by @CrazyWolf13 on GitHub (Sep 26, 2023). 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.
Author
Owner

@vootox commented on GitHub (Oct 8, 2023):

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 commented on GitHub (Oct 8, 2023): 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
Author
Owner

@CrazyWolf13 commented on GitHub (Oct 15, 2023):

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 commented on GitHub (Oct 15, 2023): > 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.
Author
Owner

@PedCoelho commented on GitHub (Dec 20, 2023):

@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 commented on GitHub (Dec 20, 2023): @CrazyWolf13 I think it should be a simple change in `inference_gfpgan.py` from : ```python 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 ```python 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
Author
Owner

@CrazyWolf13 commented on GitHub (Dec 20, 2023):

@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 commented on GitHub (Dec 20, 2023): > @CrazyWolf13 I think it should be a simple change in `inference_gfpgan.py` from : > ```python > 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 > > ```python > 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...
Author
Owner

@DNucX commented on GitHub (Feb 24, 2024):

@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 commented on GitHub (Feb 24, 2024): @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 ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: TencentARC/GFPGAN#397