From dd5566814acb9623b201c441b458d0d6a7014f2f Mon Sep 17 00:00:00 2001 From: d8ahazard Date: Tue, 20 Sep 2022 20:11:53 -0500 Subject: Add new models, fix shared opts issues Add General x4x3, GeneralWDN x4x3, and AnimeVideo models from newer ESRGAN releases. Fix issues caused by renaming ESRGAN_tille values to GAN_tile without using an IDE... --- modules/realesrgan_model.py | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) (limited to 'modules/realesrgan_model.py') diff --git a/modules/realesrgan_model.py b/modules/realesrgan_model.py index e2cef0c8..1f1af0c3 100644 --- a/modules/realesrgan_model.py +++ b/modules/realesrgan_model.py @@ -2,7 +2,11 @@ import sys import traceback from collections import namedtuple import numpy as np +import torch from PIL import Image +from basicsr.archs.rrdbnet_arch import RRDBNet +from realesrgan import RealESRGANer +from realesrgan.archs.srvgg_arch import SRVGGNetCompact import modules.images from modules.shared import cmd_opts, opts @@ -35,9 +39,27 @@ def setup_realesrgan(): from realesrgan.archs.srvgg_arch import SRVGGNetCompact realesrgan_models = [ + RealesrganModelInfo( + name="Real-ESRGAN General x4x3", + location="https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-general-x4v3.pth", + netscale=4, + model=lambda: SRVGGNetCompact(num_in_ch=3, num_out_ch=3, num_feat=64, num_conv=32, upscale=4, act_type='prelu') + ), + RealesrganModelInfo( + name="Real-ESRGAN General WDN x4x3", + location="https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-general-wdn-x4v3.pth", + netscale=4, + model=lambda: SRVGGNetCompact(num_in_ch=3, num_out_ch=3, num_feat=64, num_conv=32, upscale=4, act_type='prelu') + ), + RealesrganModelInfo( + name="Real-ESRGAN AnimeVideo", + location="https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-animevideov3.pth", + netscale=4, + model=lambda: SRVGGNetCompact(num_in_ch=3, num_out_ch=3, num_feat=64, num_conv=16, upscale=4, act_type='prelu') + ), RealesrganModelInfo( name="Real-ESRGAN 4x plus", - location="https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth", + location="https://github.com/xinntao/Real-ESRGA N/releases/download/v0.1.0/RealESRGAN_x4plus.pth", netscale=4, model=lambda: RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32, scale=4) ), RealesrganModelInfo( @@ -64,21 +86,20 @@ def setup_realesrgan(): realesrgan_models = [RealesrganModelInfo('None', '', 0, None)] have_realesrgan = False - def upscale_with_realesrgan(image, RealESRGAN_upscaling, RealESRGAN_model_index): - if not have_realesrgan or RealESRGANer_constructor is None: + if not have_realesrgan: return image info = realesrgan_models[RealESRGAN_model_index] model = info.model() - upsampler = RealESRGANer_constructor( + upsampler = RealESRGANer( scale=info.netscale, model_path=info.location, model=model, half=not cmd_opts.no_half, - tile=opts.ESRGAN_tile, - tile_pad=opts.ESRGAN_tile_overlap, + tile=opts.GAN_tile, + tile_pad=opts.GAN_tile_overlap, ) upsampled = upsampler.enhance(np.array(image), outscale=RealESRGAN_upscaling)[0] -- cgit v1.2.1 From 3cc68300cb81a12c574a0cb67bd6a27198b88310 Mon Sep 17 00:00:00 2001 From: d8ahazard Date: Wed, 21 Sep 2022 07:32:50 -0500 Subject: Typo Fix --- modules/realesrgan_model.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules/realesrgan_model.py') diff --git a/modules/realesrgan_model.py b/modules/realesrgan_model.py index 1f1af0c3..7220feb7 100644 --- a/modules/realesrgan_model.py +++ b/modules/realesrgan_model.py @@ -59,7 +59,7 @@ def setup_realesrgan(): ), RealesrganModelInfo( name="Real-ESRGAN 4x plus", - location="https://github.com/xinntao/Real-ESRGA N/releases/download/v0.1.0/RealESRGAN_x4plus.pth", + location="https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth", netscale=4, model=lambda: RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32, scale=4) ), RealesrganModelInfo( -- cgit v1.2.1 From 9a93a82b8255f3049f1b1d30d0c06c3085e4410a Mon Sep 17 00:00:00 2001 From: d8ahazard Date: Wed, 21 Sep 2022 07:37:54 -0500 Subject: Cleanup Imports --- modules/realesrgan_model.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'modules/realesrgan_model.py') diff --git a/modules/realesrgan_model.py b/modules/realesrgan_model.py index 7220feb7..b24cffeb 100644 --- a/modules/realesrgan_model.py +++ b/modules/realesrgan_model.py @@ -1,12 +1,10 @@ import sys import traceback from collections import namedtuple + import numpy as np -import torch from PIL import Image -from basicsr.archs.rrdbnet_arch import RRDBNet from realesrgan import RealESRGANer -from realesrgan.archs.srvgg_arch import SRVGGNetCompact import modules.images from modules.shared import cmd_opts, opts -- cgit v1.2.1 From 4f434c8aea3007cbf8038aec0c2a73c452ec9eca Mon Sep 17 00:00:00 2001 From: d8ahazard Date: Wed, 21 Sep 2022 08:38:38 -0500 Subject: Fix/Revert opts name from GAN to ESRGAN --- modules/realesrgan_model.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'modules/realesrgan_model.py') diff --git a/modules/realesrgan_model.py b/modules/realesrgan_model.py index b24cffeb..a3917773 100644 --- a/modules/realesrgan_model.py +++ b/modules/realesrgan_model.py @@ -96,8 +96,8 @@ def upscale_with_realesrgan(image, RealESRGAN_upscaling, RealESRGAN_model_index) model_path=info.location, model=model, half=not cmd_opts.no_half, - tile=opts.GAN_tile, - tile_pad=opts.GAN_tile_overlap, + tile=opts.ESRGAN_tile, + tile_pad=opts.ESRGAN_tile_overlap, ) upsampled = upsampler.enhance(np.array(image), outscale=RealESRGAN_upscaling)[0] -- cgit v1.2.1 From c214c428bcb28b8b32cbf42dc56eaf5e4cb17f06 Mon Sep 17 00:00:00 2001 From: d8ahazard Date: Wed, 21 Sep 2022 17:23:38 -0500 Subject: Basic settings for realesrgan model selection. I don't like that you have to restart the app, but it works. --- modules/realesrgan_model.py | 42 +++++------------------------------------- 1 file changed, 5 insertions(+), 37 deletions(-) (limited to 'modules/realesrgan_model.py') diff --git a/modules/realesrgan_model.py b/modules/realesrgan_model.py index a3917773..fc8623de 100644 --- a/modules/realesrgan_model.py +++ b/modules/realesrgan_model.py @@ -7,10 +7,10 @@ from PIL import Image from realesrgan import RealESRGANer import modules.images +from modules import realesrgan_model_loader from modules.shared import cmd_opts, opts RealesrganModelInfo = namedtuple("RealesrganModelInfo", ["name", "location", "model", "netscale"]) - realesrgan_models = [] have_realesrgan = False RealESRGANer_constructor = None @@ -36,46 +36,13 @@ def setup_realesrgan(): from realesrgan import RealESRGANer from realesrgan.archs.srvgg_arch import SRVGGNetCompact - realesrgan_models = [ - RealesrganModelInfo( - name="Real-ESRGAN General x4x3", - location="https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-general-x4v3.pth", - netscale=4, - model=lambda: SRVGGNetCompact(num_in_ch=3, num_out_ch=3, num_feat=64, num_conv=32, upscale=4, act_type='prelu') - ), - RealesrganModelInfo( - name="Real-ESRGAN General WDN x4x3", - location="https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-general-wdn-x4v3.pth", - netscale=4, - model=lambda: SRVGGNetCompact(num_in_ch=3, num_out_ch=3, num_feat=64, num_conv=32, upscale=4, act_type='prelu') - ), - RealesrganModelInfo( - name="Real-ESRGAN AnimeVideo", - location="https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-animevideov3.pth", - netscale=4, - model=lambda: SRVGGNetCompact(num_in_ch=3, num_out_ch=3, num_feat=64, num_conv=16, upscale=4, act_type='prelu') - ), - RealesrganModelInfo( - name="Real-ESRGAN 4x plus", - location="https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth", - netscale=4, model=lambda: RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32, scale=4) - ), - RealesrganModelInfo( - name="Real-ESRGAN 4x plus anime 6B", - location="https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth", - netscale=4, model=lambda: RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=6, num_grow_ch=32, scale=4) - ), - RealesrganModelInfo( - name="Real-ESRGAN 2x plus", - location="https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.1/RealESRGAN_x2plus.pth", - netscale=2, model=lambda: RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32, scale=2) - ), - ] + realesrgan_models = realesrgan_model_loader.get_realesrgan_models() have_realesrgan = True RealESRGANer_constructor = RealESRGANer for i, model in enumerate(realesrgan_models): - modules.shared.sd_upscalers.append(UpscalerRealESRGAN(model.netscale, i)) + if model.name in opts.realesrgan_enabled_models: + modules.shared.sd_upscalers.append(UpscalerRealESRGAN(model.netscale, i)) except Exception: print("Error importing Real-ESRGAN:", file=sys.stderr) @@ -84,6 +51,7 @@ def setup_realesrgan(): realesrgan_models = [RealesrganModelInfo('None', '', 0, None)] have_realesrgan = False + def upscale_with_realesrgan(image, RealESRGAN_upscaling, RealESRGAN_model_index): if not have_realesrgan: return image -- cgit v1.2.1 From 3eaae8ae655346c8c510b677bd48021b86842561 Mon Sep 17 00:00:00 2001 From: AUTOMATIC <16777216c@gmail.com> Date: Thu, 22 Sep 2022 07:59:27 +0300 Subject: reworking #775 --- modules/realesrgan_model.py | 55 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 50 insertions(+), 5 deletions(-) (limited to 'modules/realesrgan_model.py') diff --git a/modules/realesrgan_model.py b/modules/realesrgan_model.py index fc8623de..c32d6c4c 100644 --- a/modules/realesrgan_model.py +++ b/modules/realesrgan_model.py @@ -7,13 +7,60 @@ from PIL import Image from realesrgan import RealESRGANer import modules.images -from modules import realesrgan_model_loader from modules.shared import cmd_opts, opts RealesrganModelInfo = namedtuple("RealesrganModelInfo", ["name", "location", "model", "netscale"]) realesrgan_models = [] have_realesrgan = False -RealESRGANer_constructor = None + + +def get_realesrgan_models(): + try: + from basicsr.archs.rrdbnet_arch import RRDBNet + from realesrgan import RealESRGANer + from realesrgan.archs.srvgg_arch import SRVGGNetCompact + models = [ + RealesrganModelInfo( + name="Real-ESRGAN General x4x3", + location="https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-general-x4v3.pth", + netscale=4, + model=lambda: SRVGGNetCompact(num_in_ch=3, num_out_ch=3, num_feat=64, num_conv=32, upscale=4, act_type='prelu') + ), + RealesrganModelInfo( + name="Real-ESRGAN General WDN x4x3", + location="https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-general-wdn-x4v3.pth", + netscale=4, + model=lambda: SRVGGNetCompact(num_in_ch=3, num_out_ch=3, num_feat=64, num_conv=32, upscale=4, act_type='prelu') + ), + RealesrganModelInfo( + name="Real-ESRGAN AnimeVideo", + location="https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-animevideov3.pth", + netscale=4, + model=lambda: SRVGGNetCompact(num_in_ch=3, num_out_ch=3, num_feat=64, num_conv=16, upscale=4, act_type='prelu') + ), + RealesrganModelInfo( + name="Real-ESRGAN 4x plus", + location="https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth", + netscale=4, + model=lambda: RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32, scale=4) + ), + RealesrganModelInfo( + name="Real-ESRGAN 4x plus anime 6B", + location="https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth", + netscale=4, + model=lambda: RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=6, num_grow_ch=32, scale=4) + ), + RealesrganModelInfo( + name="Real-ESRGAN 2x plus", + location="https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.1/RealESRGAN_x2plus.pth", + netscale=2, + model=lambda: RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32, scale=2) + ), + ] + return models + except Exception as e: + print("Error makeing Real-ESRGAN midels list:", file=sys.stderr) + print(traceback.format_exc(), file=sys.stderr) class UpscalerRealESRGAN(modules.images.Upscaler): @@ -29,16 +76,14 @@ class UpscalerRealESRGAN(modules.images.Upscaler): def setup_realesrgan(): global realesrgan_models global have_realesrgan - global RealESRGANer_constructor try: from basicsr.archs.rrdbnet_arch import RRDBNet from realesrgan import RealESRGANer from realesrgan.archs.srvgg_arch import SRVGGNetCompact - realesrgan_models = realesrgan_model_loader.get_realesrgan_models() + realesrgan_models = get_realesrgan_models() have_realesrgan = True - RealESRGANer_constructor = RealESRGANer for i, model in enumerate(realesrgan_models): if model.name in opts.realesrgan_enabled_models: -- cgit v1.2.1