Skip to content

Commit

Permalink
fix adetailer
Browse files Browse the repository at this point in the history
Signed-off-by: Vladimir Mandic <mandic00@live.com>
  • Loading branch information
vladmandic committed Oct 10, 2024
1 parent bc47e49 commit 69d3a95
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 14 deletions.
23 changes: 15 additions & 8 deletions modules/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,30 +354,37 @@ def process_images_inner(p: StableDiffusionProcessing) -> Processed:
else:
sample = validate_sample(sample)
image = Image.fromarray(sample)
sample = face_restoration.restore_faces(sample, p)
if p.restore_faces:
p.ops.append('restore')
if not p.do_not_save_samples and shared.opts.save_images_before_detailer:
info = create_infotext(p, p.prompts, p.seeds, p.subseeds, index=i)
images.save_image(Image.fromarray(sample), path=p.outpath_samples, basename="", seed=p.seeds[i], prompt=p.prompts[i], extension=shared.opts.samples_format, info=info, p=p, suffix="-before-restore")
sample = face_restoration.restore_faces(sample, p)
if sample is not None:
image = Image.fromarray(sample)
if p.detailer:
p.ops.append('detailer')
if not p.do_not_save_samples and shared.opts.save_images_before_detailer:
info = create_infotext(p, p.prompts, p.seeds, p.subseeds, index=i)
images.save_image(Image.fromarray(sample), path=p.outpath_samples, basename="", seed=p.seeds[i], prompt=p.prompts[i], extension=shared.opts.samples_format, info=info, p=p, suffix="-before-detailer")
p.ops.append('detailer')
sample = detailer.detail(sample, p)
if sample is not None:
image = Image.fromarray(sample)
if p.scripts is not None and isinstance(p.scripts, scripts.ScriptRunner):
pp = scripts.PostprocessImageArgs(image)
p.scripts.postprocess_image(p, pp)
if pp.image is not None:
image = pp.image
if p.color_corrections is not None and i < len(p.color_corrections):
p.ops.append('color')
if not p.do_not_save_samples and shared.opts.save_images_before_color_correction:
orig = p.color_corrections
p.color_corrections = None
p.color_corrections = orig
image_without_cc = apply_overlay(image, p.paste_to, i, p.overlay_images)
info = create_infotext(p, p.prompts, p.seeds, p.subseeds, index=i)
images.save_image(image_without_cc, path=p.outpath_samples, basename="", seed=p.seeds[i], prompt=p.prompts[i], extension=shared.opts.samples_format, info=info, p=p, suffix="-before-color-correct")
p.ops.append('color')
image = apply_color_correction(p.color_corrections[i], image)
if p.scripts is not None and isinstance(p.scripts, scripts.ScriptRunner):
pp = scripts.PostprocessImageArgs(image)
p.scripts.postprocess_image(p, pp)
if pp.image is not None:
image = pp.image
if shared.opts.mask_apply_overlay:
image = apply_overlay(image, p.paste_to, i, p.overlay_images)

Expand Down
84 changes: 82 additions & 2 deletions modules/processing_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,68 @@ class StableDiffusionProcessing:
"""
The first set of paramaters: sd_models -> do_not_reload_embeddings represent the minimum required to create a StableDiffusionProcessing
"""
def __init__(self, sd_model=None, outpath_samples=None, outpath_grids=None, prompt: str = "", styles: List[str] = None, seed: int = -1, subseed: int = -1, subseed_strength: float = 0, seed_resize_from_h: int = -1, seed_resize_from_w: int = -1, seed_enable_extras: bool = True, sampler_name: str = None, hr_sampler_name: str = None, batch_size: int = 1, n_iter: int = 1, steps: int = 50, cfg_scale: float = 7.0, image_cfg_scale: float = None, clip_skip: int = 1, width: int = 512, height: int = 512, full_quality: bool = True, detailer: bool = False, tiling: bool = False, hidiffusion: bool = False, do_not_save_samples: bool = False, do_not_save_grid: bool = False, extra_generation_params: Dict[Any, Any] = None, overlay_images: Any = None, negative_prompt: str = None, eta: float = None, do_not_reload_embeddings: bool = False, denoising_strength: float = 0, diffusers_guidance_rescale: float = 0.7, pag_scale: float = 0.0, pag_adaptive: float = 0.5, cfg_end: float = 1, resize_mode: int = 0, resize_name: str = 'None', resize_context: str = 'None', scale_by: float = 0, selected_scale_tab: int = 0, hdr_mode: int = 0, hdr_brightness: float = 0, hdr_color: float = 0, hdr_sharpen: float = 0, hdr_clamp: bool = False, hdr_boundary: float = 4.0, hdr_threshold: float = 0.95, hdr_maximize: bool = False, hdr_max_center: float = 0.6, hdr_max_boundry: float = 1.0, hdr_color_picker: str = None, hdr_tint_ratio: float = 0, override_settings: Dict[str, Any] = None, override_settings_restore_afterwards: bool = True, sampler_index: int = None, script_args: list = None): # pylint: disable=unused-argument
def __init__(self,
sd_model=None,
outpath_samples=None,
outpath_grids=None,
prompt: str = "",
styles: List[str] = None,
seed: int = -1,
subseed: int = -1,
subseed_strength: float = 0,
seed_resize_from_h: int = -1,
seed_resize_from_w: int = -1,
seed_enable_extras: bool = True,
sampler_name: str = None,
hr_sampler_name: str = None,
batch_size: int = 1,
n_iter: int = 1,
steps: int = 50,
cfg_scale: float = 7.0,
image_cfg_scale: float = None,
clip_skip: int = 1,
width: int = 512,
height: int = 512,
full_quality: bool = True,
detailer: bool = False,
restore_faces: bool = False,
tiling: bool = False,
hidiffusion: bool = False,
do_not_save_samples: bool = False,
do_not_save_grid: bool = False,
extra_generation_params: Dict[Any, Any] = None,
overlay_images: Any = None,
negative_prompt: str = None,
eta: float = None,
do_not_reload_embeddings: bool = False,
denoising_strength: float = 0,
diffusers_guidance_rescale: float = 0.7,
pag_scale: float = 0.0,
pag_adaptive: float = 0.5,
cfg_end: float = 1,
resize_mode: int = 0,
resize_name: str = 'None',
resize_context: str = 'None',
scale_by: float = 0,
selected_scale_tab: int = 0,
hdr_mode: int = 0,
hdr_brightness: float = 0,
hdr_color: float = 0,
hdr_sharpen: float = 0,
hdr_clamp: bool = False,
hdr_boundary: float = 4.0,
hdr_threshold: float = 0.95,
hdr_maximize: bool = False,
hdr_max_center: float = 0.6,
hdr_max_boundry: float = 1.0,
hdr_color_picker: str = None,
hdr_tint_ratio: float = 0,
override_settings: Dict[str, Any] = None,
override_settings_restore_afterwards: bool = True,
sampler_index: int = None,
script_args: list = None
): # pylint: disable=unused-argument

self.state: str = ''
self.skip = []
self.outpath_samples: str = outpath_samples
Expand Down Expand Up @@ -51,6 +112,7 @@ def __init__(self, sd_model=None, outpath_samples=None, outpath_grids=None, prom
self.height: int = height
self.full_quality: bool = full_quality
self.detailer: bool = detailer
self.restore_faces: bool = restore_faces
self.tiling: bool = tiling
self.hidiffusion: bool = hidiffusion
self.do_not_save_samples: bool = do_not_save_samples
Expand Down Expand Up @@ -191,7 +253,25 @@ def close(self):

class StableDiffusionProcessingTxt2Img(StableDiffusionProcessing):

def __init__(self, enable_hr: bool = False, denoising_strength: float = 0.75, firstphase_width: int = 0, firstphase_height: int = 0, hr_scale: float = 2.0, hr_force: bool = False, hr_resize_mode: int = 0, hr_resize_context: str = 'None', hr_upscaler: str = None, hr_second_pass_steps: int = 0, hr_resize_x: int = 0, hr_resize_y: int = 0, refiner_steps: int = 5, refiner_start: float = 0, refiner_prompt: str = '', refiner_negative: str = '', **kwargs):
def __init__(self,
enable_hr: bool = False,
denoising_strength: float = 0.75,
firstphase_width: int = 0,
firstphase_height: int = 0,
hr_scale: float = 2.0,
hr_force: bool = False,
hr_resize_mode: int = 0,
hr_resize_context: str = 'None',
hr_upscaler: str = None,
hr_second_pass_steps: int = 0,
hr_resize_x: int = 0,
hr_resize_y: int = 0,
refiner_steps: int = 5,
refiner_start: float = 0,
refiner_prompt: str = '',
refiner_negative: str = '',
**kwargs
):

super().__init__(**kwargs)
self.reprocess = {}
Expand Down
8 changes: 4 additions & 4 deletions modules/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,9 +474,9 @@ def get_default_modes():
"cuda_compile_errors": OptionInfo(True, "Model compile suppress errors"),
"deep_cache_interval": OptionInfo(3, "DeepCache cache interval", gr.Slider, {"minimum": 1, "maximum": 10, "step": 1}),

"quant_sep": OptionInfo("<h2>Model Quantization</h2>", "", gr.HTML),
"quant_shuffle_weights": OptionInfo(False, "Shuffle the weights between GPU and CPU when quantizing"),
"diffusers_quantization": OptionInfo(False, "Dynamic quantization with TorchAO"),
"quant_sep": OptionInfo("<h2>Model Quantization</h2>", "", gr.HTML, {"visible": native}),
"quant_shuffle_weights": OptionInfo(False, "Shuffle the weights between GPU and CPU when quantizing", gr.Checkbox, {"visible": native}),
"diffusers_quantization": OptionInfo(False, "Dynamic quantization with TorchAO", gr.Checkbox, {"visible": native}),
"nncf_compress_weights": OptionInfo([], "Compress Model weights with NNCF INT8", gr.CheckboxGroup, {"choices": ["Model", "VAE", "Text Encoder", "ControlNet"], "visible": native}),
"optimum_quanto_weights": OptionInfo([], "Quantize Model weights with Optimum Quanto", gr.CheckboxGroup, {"choices": ["Model", "VAE", "Text Encoder", "ControlNet"], "visible": native}),
"optimum_quanto_weights_type": OptionInfo("qint8", "Weights type for Optimum Quanto", gr.Radio, {"choices": ['qint8', 'qfloat8_e4m3fn', 'qfloat8_e5m2', 'qint4', 'qint2'], "visible": native}),
Expand Down Expand Up @@ -543,7 +543,7 @@ def get_default_modes():
"batch_frame_mode": OptionInfo(False, "Parallel process images in batch"),
"inference_other_sep": OptionInfo("<h2>Other</h2>", "", gr.HTML),
"inference_mode": OptionInfo("no-grad", "Torch inference mode", gr.Radio, {"choices": ["no-grad", "inference-mode", "none"]}),
"sd_vae_sliced_encode": OptionInfo(False, "VAE sliced encode"),
"sd_vae_sliced_encode": OptionInfo(False, "VAE sliced encode", gr.Checkbox, {"visible": not native}),
}))

options_templates.update(options_section(('diffusers', "Diffusers Settings"), {
Expand Down

0 comments on commit 69d3a95

Please sign in to comment.