2023-03-03 06:02:00 +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
|
|
|
|
2023-03-03 06:02:00 +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:
|
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
|
2022-12-19 16:36:39 +00:00
|
|
|
|
2022-09-13 17:17:14 +00:00
|
|
|
# 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
|
2022-12-19 16:36:39 +00:00
|
|
|
|
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):
|
2023-03-03 05:02:15 +00:00
|
|
|
from .gfpgan import GFPGAN
|
2023-03-03 06:02:00 +00:00
|
|
|
|
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):
|
2023-03-03 05:02:15 +00:00
|
|
|
from .codeformer import CodeFormerRestoration
|
2023-03-03 06:02:00 +00:00
|
|
|
|
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):
|
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
|