2022-09-13 17:17:14 +00:00
|
|
|
class Restoration():
|
2022-09-23 07:40:31 +00:00
|
|
|
def __init__(self) -> None:
|
|
|
|
pass
|
2022-09-13 17:17:14 +00:00
|
|
|
|
2022-11-10 22:55:03 +00:00
|
|
|
def load_face_restore_models(self, gfpgan_model_path='./models/gfpgan/GFPGANv1.4.pth'):
|
2022-09-13 17:17:14 +00:00
|
|
|
# Load GFPGAN
|
2022-11-10 22:55:03 +00:00
|
|
|
gfpgan = self.load_gfpgan(gfpgan_model_path)
|
2022-09-13 17:17:14 +00:00
|
|
|
if gfpgan.gfpgan_model_exists:
|
|
|
|
print('>> GFPGAN Initialized')
|
2022-09-23 07:40:31 +00:00
|
|
|
else:
|
|
|
|
print('>> GFPGAN Disabled')
|
|
|
|
gfpgan = None
|
2022-09-13 17:17:14 +00:00
|
|
|
|
|
|
|
# Load CodeFormer
|
|
|
|
codeformer = self.load_codeformer()
|
|
|
|
if codeformer.codeformer_model_exists:
|
|
|
|
print('>> CodeFormer Initialized')
|
2022-09-23 07:40:31 +00:00
|
|
|
else:
|
|
|
|
print('>> CodeFormer Disabled')
|
|
|
|
codeformer = None
|
2022-09-13 17:17:14 +00:00
|
|
|
|
|
|
|
return gfpgan, codeformer
|
|
|
|
|
|
|
|
# Face Restore Models
|
2022-11-10 22:55:03 +00:00
|
|
|
def load_gfpgan(self, gfpgan_model_path):
|
2022-10-08 15:37:23 +00:00
|
|
|
from ldm.invoke.restoration.gfpgan import GFPGAN
|
2022-11-10 22:55:03 +00:00
|
|
|
return GFPGAN(gfpgan_model_path)
|
2022-09-13 17:17:14 +00:00
|
|
|
|
|
|
|
def load_codeformer(self):
|
2022-10-08 15:37:23 +00:00
|
|
|
from ldm.invoke.restoration.codeformer import CodeFormerRestoration
|
2022-09-13 17:17:14 +00:00
|
|
|
return CodeFormerRestoration()
|
|
|
|
|
|
|
|
# Upscale Models
|
2022-09-23 07:40:31 +00:00
|
|
|
def load_esrgan(self, esrgan_bg_tile=400):
|
2022-10-08 15:37:23 +00:00
|
|
|
from ldm.invoke.restoration.realesrgan import ESRGAN
|
2022-09-23 07:40:31 +00:00
|
|
|
esrgan = ESRGAN(esrgan_bg_tile)
|
2022-09-13 17:17:14 +00:00
|
|
|
print('>> ESRGAN Initialized')
|
2022-09-19 17:59:43 +00:00
|
|
|
return esrgan;
|