mirror of
https://github.com/TencentARC/GFPGAN.git
synced 2026-02-04 00:04:34 +00:00
Trying to get ESRGAN BG Upscaling to work with CPU #158
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @zarc70 on GitHub (Feb 15, 2022).
TL;DR How do I make ESRGAN Background Upscaling work using CPU
Hi, love the new model and it works great (As did the old ones)! I know that the warning on the ESRGAN Background Upscaling with CPU gives the warning that it is slow and it is set not to occur when the model is running on CPU. On the old utils, When I edit the code to ignore the warning (i.e.
if args.bg_upsampler == 'realesrgan':
if not torch.cuda.is_available(): # CPU
import warnings
warnings.warn('The unoptimized RealESRGAN is very slow on CPU. We do not use it. '
'If you really want to use it, please modify the corresponding codes.')
bg_upsampler = 'none' CHANGE NONE TO realesrgan
I get this error message:
***\GFPGAN\gfpgan\utils.py", line 106, in enhance
bg_img = self.bg_upsampler.enhance(img, outscale=self.upscale)[0]
AttributeError: 'str' object has no attribute 'enhance'
Is this due to not having torch no grad on CPU, or something of that nature, (as the enhance is defined above in utils as:
def enhance(self, img, has_aligned=False, only_center_face=False, paste_back=True):
self.face_helper.clean_all()
Perhaps this was corrected in the updated utils and inference.py, but I'm still having significant trouble with it.
@xinntao commented on GitHub (Feb 15, 2022):
Thanks for reporting the issue, I will fix it later~
@zarc70 commented on GitHub (Feb 18, 2022):
Thank you!!!
@toto4c19 commented on GitHub (Mar 25, 2022):
Hi. I have tried with CPU BG Upscaling and also have the same problem. May I know when will it be fixed? I teasted with using CPU for running real-ESRGAN with no issue.
@pipeob0 commented on GitHub (Apr 10, 2022):
Change
# ------------------------ set up background upsampler ------------------------ 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 = Nonewith
# ------------------------ set up background upsampler ------------------------ 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 = Noneworked for me