2022-12-01 05:33:20 +00:00
|
|
|
import os
|
|
|
|
import sys
|
2023-03-09 05:18:29 +00:00
|
|
|
import torch
|
2022-12-01 05:33:20 +00:00
|
|
|
import traceback
|
2023-03-03 06:02:00 +00:00
|
|
|
from argparse import Namespace
|
2023-03-09 05:18:29 +00:00
|
|
|
from omegaconf import OmegaConf
|
2022-12-01 05:33:20 +00:00
|
|
|
|
2023-03-03 06:02:00 +00:00
|
|
|
import invokeai.version
|
2023-03-04 01:19:37 +00:00
|
|
|
from ...backend import Globals
|
2023-03-03 06:02:00 +00:00
|
|
|
|
2022-12-01 05:33:20 +00:00
|
|
|
def load_face_restoration(opt):
|
|
|
|
try:
|
|
|
|
gfpgan, codeformer, esrgan = None, None, None
|
|
|
|
if opt.restore or opt.esrgan:
|
2023-03-03 06:02:00 +00:00
|
|
|
from invokeai.backend.restoration import Restoration
|
|
|
|
|
2022-12-01 05:33:20 +00:00
|
|
|
restoration = Restoration()
|
|
|
|
if opt.restore:
|
2023-03-03 06:02:00 +00:00
|
|
|
gfpgan, codeformer = restoration.load_face_restore_models(
|
|
|
|
opt.gfpgan_model_path
|
|
|
|
)
|
2022-12-01 05:33:20 +00:00
|
|
|
else:
|
2023-03-03 06:02:00 +00:00
|
|
|
print(">> Face restoration disabled")
|
2022-12-01 05:33:20 +00:00
|
|
|
if opt.esrgan:
|
|
|
|
esrgan = restoration.load_esrgan(opt.esrgan_bg_tile)
|
|
|
|
else:
|
2023-03-03 06:02:00 +00:00
|
|
|
print(">> Upscaling disabled")
|
2022-12-01 05:33:20 +00:00
|
|
|
else:
|
2023-03-03 06:02:00 +00:00
|
|
|
print(">> Face restoration and upscaling disabled")
|
2022-12-01 05:33:20 +00:00
|
|
|
except (ModuleNotFoundError, ImportError):
|
|
|
|
print(traceback.format_exc(), file=sys.stderr)
|
2023-03-03 06:02:00 +00:00
|
|
|
print(">> You may need to install the ESRGAN and/or GFPGAN modules")
|
|
|
|
return gfpgan, codeformer, esrgan
|
2022-12-01 05:33:20 +00:00
|
|
|
|
|
|
|
|