InvokeAI/invokeai/backend/restoration/base.py

44 lines
1.2 KiB
Python
Raw Normal View History

2023-03-03 06:02:00 +00:00
class Restoration:
2022-09-23 07:40:31 +00:00
def __init__(self) -> None:
pass
2023-03-03 06:02:00 +00:00
def load_face_restore_models(
self, gfpgan_model_path="./models/gfpgan/GFPGANv1.4.pth"
):
# Load GFPGAN
gfpgan = self.load_gfpgan(gfpgan_model_path)
if gfpgan.gfpgan_model_exists:
2023-03-03 06:02:00 +00:00
print(">> GFPGAN Initialized")
2022-09-23 07:40:31 +00:00
else:
2023-03-03 06:02:00 +00:00
print(">> GFPGAN Disabled")
2022-09-23 07:40:31 +00:00
gfpgan = None
# Load CodeFormer
codeformer = self.load_codeformer()
if codeformer.codeformer_model_exists:
2023-03-03 06:02:00 +00:00
print(">> CodeFormer Initialized")
2022-09-23 07:40:31 +00:00
else:
2023-03-03 06:02:00 +00:00
print(">> CodeFormer Disabled")
2022-09-23 07:40:31 +00:00
codeformer = None
return gfpgan, codeformer
# Face Restore Models
def load_gfpgan(self, gfpgan_model_path):
2023-03-03 05:02:15 +00:00
from .gfpgan import GFPGAN
2023-03-03 06:02:00 +00:00
return GFPGAN(gfpgan_model_path)
def load_codeformer(self):
2023-03-03 05:02:15 +00:00
from .codeformer import CodeFormerRestoration
2023-03-03 06:02:00 +00:00
return CodeFormerRestoration()
# Upscale Models
2022-09-23 07:40:31 +00:00
def load_esrgan(self, esrgan_bg_tile=400):
2023-03-03 05:02:15 +00:00
from .realesrgan import ESRGAN
2023-03-03 06:02:00 +00:00
2022-09-23 07:40:31 +00:00
esrgan = ESRGAN(esrgan_bg_tile)
2023-03-03 06:02:00 +00:00
print(">> ESRGAN Initialized")
return esrgan