InvokeAI/invokeai/app/services/generate_initializer.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

36 lines
1.1 KiB
Python
Raw Normal View History

import os
import sys
import torch
import traceback
2023-03-03 06:02:00 +00:00
from argparse import Namespace
from omegaconf import OmegaConf
2023-03-03 06:02:00 +00:00
import invokeai.version
from ...backend import Globals
2023-03-03 06:02:00 +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
restoration = Restoration()
if opt.restore:
2023-03-03 06:02:00 +00:00
gfpgan, codeformer = restoration.load_face_restore_models(
opt.gfpgan_model_path
)
else:
2023-03-03 06:02:00 +00:00
print(">> Face restoration disabled")
if opt.esrgan:
esrgan = restoration.load_esrgan(opt.esrgan_bg_tile)
else:
2023-03-03 06:02:00 +00:00
print(">> Upscaling disabled")
else:
2023-03-03 06:02:00 +00:00
print(">> Face restoration and upscaling disabled")
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