mirror of
https://github.com/vladmandic/automatic
synced 2026-09-19 17:24:32 +02:00
Merge pull request #4637 from CalamitousFelicitousness/refactor/remove-face-restoration
Refactor/remove face restoration
This commit is contained in:
@@ -1,28 +0,0 @@
|
||||
from PIL import Image
|
||||
import numpy as np
|
||||
import gradio as gr
|
||||
from modules import scripts_postprocessing
|
||||
from modules.postprocess import codeformer_model
|
||||
|
||||
|
||||
class ScriptPostprocessingCodeFormer(scripts_postprocessing.ScriptPostprocessing):
|
||||
name = "CodeFormer"
|
||||
order = 3000
|
||||
|
||||
def ui(self):
|
||||
with gr.Accordion('Restore faces: CodeFormer', open = False, elem_id="postprocess_codeformer_accordion"):
|
||||
with gr.Row():
|
||||
codeformer_visibility = gr.Slider(minimum=0.0, maximum=1.0, step=0.01, label="Strength", value=0.0, elem_id="extras_codeformer_visibility")
|
||||
codeformer_weight = gr.Slider(minimum=0.0, maximum=1.0, step=0.01, label="Weight", value=0.2, elem_id="extras_codeformer_weight")
|
||||
return { "codeformer_visibility": codeformer_visibility, "codeformer_weight": codeformer_weight }
|
||||
|
||||
def process(self, pp: scripts_postprocessing.PostprocessedImage, codeformer_visibility, codeformer_weight): # pylint: disable=arguments-differ
|
||||
if codeformer_visibility == 0:
|
||||
return
|
||||
restored_img = codeformer_model.codeformer.restore(np.array(pp.image, dtype=np.uint8), w=codeformer_weight)
|
||||
res = Image.fromarray(restored_img)
|
||||
if codeformer_visibility < 1.0:
|
||||
res = Image.blend(pp.image, res, codeformer_visibility)
|
||||
pp.image = res
|
||||
pp.info["CodeFormer visibility"] = round(codeformer_visibility, 3)
|
||||
pp.info["CodeFormer weight"] = round(codeformer_weight, 3)
|
||||
@@ -1,29 +0,0 @@
|
||||
from PIL import Image
|
||||
import numpy as np
|
||||
import gradio as gr
|
||||
from modules import scripts_postprocessing
|
||||
|
||||
|
||||
class ScriptPostprocessingGfpGan(scripts_postprocessing.ScriptPostprocessing):
|
||||
name = "GFPGAN"
|
||||
order = 2000
|
||||
|
||||
def ui(self):
|
||||
with gr.Accordion('Restore faces: GFPGan', open = False, elem_id="postprocess_gfpgan_accordion"):
|
||||
with gr.Row():
|
||||
gfpgan_visibility = gr.Slider(minimum=0.0, maximum=1.0, step=0.001, label="Strength", value=0, elem_id="extras_gfpgan_visibility")
|
||||
return { "gfpgan_visibility": gfpgan_visibility }
|
||||
|
||||
def process(self, pp: scripts_postprocessing.PostprocessedImage, gfpgan_visibility): # pylint: disable=arguments-differ
|
||||
from installer import install
|
||||
install("facexlib")
|
||||
install("gfpgan")
|
||||
if gfpgan_visibility == 0:
|
||||
return
|
||||
from modules.postprocess import gfpgan_model
|
||||
restored_img = gfpgan_model.gfpgan_fix_faces(np.array(pp.image, dtype=np.uint8))
|
||||
res = Image.fromarray(restored_img)
|
||||
if gfpgan_visibility < 1.0:
|
||||
res = Image.blend(pp.image, res, gfpgan_visibility)
|
||||
pp.image = res
|
||||
pp.info["GFPGAN visibility"] = round(gfpgan_visibility, 3)
|
||||
@@ -246,7 +246,7 @@ axis_options = [
|
||||
AxisOption("[Refine] Refiner steps", float, apply_field("refiner_steps")),
|
||||
AxisOption("[Postprocess] Upscaler", str, apply_upscaler, cost=0.4, choices=lambda: [x.name for x in shared.sd_upscalers]),
|
||||
AxisOption("[Postprocess] Context", str, apply_context, choices=lambda: ["Add with forward", "Remove with forward", "Add with backward", "Remove with backward"]),
|
||||
AxisOption("[Postprocess] Detailer", str, apply_detailer, fmt=format_value_add_label),
|
||||
AxisOption("[Postprocess] Detailer", bool, apply_detailer, fmt=format_bool, choices=lambda: [False, True]),
|
||||
AxisOption("[Postprocess] Detailer strength", str, apply_field("detailer_strength")),
|
||||
AxisOption("[Quant] SDNQ quant mode", str, apply_sdnq_quant, cost=0.9, fmt=format_value_add_label, choices=lambda: ['none'] + sorted(shared.sdnq_quant_modes)),
|
||||
AxisOption("[Quant] SDNQ quant mode TE", str, apply_sdnq_quant_te, cost=0.9, fmt=format_value_add_label, choices=lambda: ['none'] + sorted(shared.sdnq_quant_modes)),
|
||||
|
||||
@@ -284,17 +284,8 @@ def apply_context(p: processing.StableDiffusionProcessingTxt2Img, opt, x):
|
||||
|
||||
|
||||
def apply_detailer(p, opt, x):
|
||||
opt = opt.lower()
|
||||
if opt == 'codeformer':
|
||||
is_active = True
|
||||
p.detailer_model = 'CodeFormer'
|
||||
elif opt == 'gfpgan':
|
||||
is_active = True
|
||||
p.detailer_model = 'GFPGAN'
|
||||
else:
|
||||
is_active = opt in ('true', 'yes', 'y', '1')
|
||||
p.detailer_enabled = is_active
|
||||
shared.log.debug(f'XYZ grid apply face-restore: "{x}"')
|
||||
p.detailer_enabled = bool(opt)
|
||||
shared.log.debug(f'XYZ grid apply detailer: "{x}"')
|
||||
|
||||
|
||||
def apply_control(field):
|
||||
|
||||
@@ -452,7 +452,6 @@ class Script(scripts_manager.Script):
|
||||
|
||||
def process_images(self, p, *args): # pylint: disable=W0221, W0613
|
||||
if xyz_results_cache is not None and len(xyz_results_cache.images) > 0:
|
||||
p.restore_faces = False
|
||||
p.detailer_enabled = False
|
||||
p.color_corrections = None
|
||||
# p.scripts = None
|
||||
|
||||
Reference in New Issue
Block a user