Skip to content

Commit

Permalink
fix xyz with detailer, sd35 img2img
Browse files Browse the repository at this point in the history
Signed-off-by: Vladimir Mandic <[email protected]>
  • Loading branch information
vladmandic committed Jan 2, 2025
1 parent 8dfbf6b commit 94a659e
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 18 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Change Log for SD.Next

## Update for 2025-01-01
## Update for 2025-01-02

- [Allegro Video](https://huggingface.co/rhymes-ai/Allegro)
- optimizations: full offload and quantization support
Expand All @@ -18,8 +18,11 @@
- **Fixes**:
- explict clear caches on model load
- lock adetailer commit: `#a89c01d`
- xyzgrid fix progress calculation
- xyzgrid progress calculation
- xyzgrid detailer
- vae tiling use default value if not set
- sd35 img2img
- samplers test for scale noise before using

## Update for 2024-12-31

Expand Down
24 changes: 11 additions & 13 deletions modules/postprocess/yolo.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import TYPE_CHECKING
import os
from copy import copy
import numpy as np
import gradio as gr
from PIL import Image, ImageDraw
Expand Down Expand Up @@ -259,23 +260,23 @@ def restore(self, np_image, p: processing.StableDiffusionProcessing = None):

report = [{'label': i.label, 'score': i.score, 'size': f'{i.width}x{i.height}' } for i in items]
shared.log.info(f'Detailer: model="{name}" items={report} args={items[0].args} denoise={p.denoising_strength} blur={p.mask_blur} width={p.width} height={p.height} padding={p.inpaint_full_res_padding}')
shared.log.debug(f'Detailer: prompt="{prompt}" negative="{negative}"')
# shared.log.debug(f'Detailer: prompt="{prompt}" negative="{negative}"')
models_used.append(name)

mask_all = []
p.state = ''
prev_state = shared.state.job
pc = copy(p)
for item in items:
if item.mask is None:
continue
p.init_images = [image]
p.image_mask = [item.mask]
# mask_all.append(item.mask)
p.recursion = True
pc.init_images = [image]
pc.image_mask = [item.mask]
pc.overlay_images = []
pc.recursion = True
shared.state.job = 'Detailer'
pp = processing.process_images_inner(p)
del p.recursion
p.overlay_images = None # skip applying overlay twice
pp = processing.process_images_inner(pc)
del pc.recursion
if pp is not None and pp.images is not None and len(pp.images) > 0:
image = pp.images[0] # update image to be reused for next item
if len(pp.images) > 1:
Expand All @@ -298,13 +299,10 @@ def restore(self, np_image, p: processing.StableDiffusionProcessing = None):
if len(mask_all) > 0 and shared.opts.include_mask:
from modules.control.util import blend
p.image_mask = blend([np.array(m) for m in mask_all])
# combined = blend([np_image, p.image_mask])
# combined = Image.fromarray(combined)
# combined.save('/tmp/item.png')
p.image_mask = Image.fromarray(p.image_mask)

if len(models_used) > 0:
shared.log.debug(f'Detailer processed: models={models_used}')
# if len(models_used) > 0:
# shared.log.debug(f'Detailer processed: models={models_used}')
return np_image

def ui(self, tab: str):
Expand Down
2 changes: 1 addition & 1 deletion modules/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ def process_images_inner(p: StableDiffusionProcessing) -> Processed:
ipadapter.unapply(shared.sd_model, unload=getattr(p, 'ip_adapter_unload', False))

if shared.opts.include_mask:
if shared.opts.mask_apply_overlay and p.overlay_images is not None and len(p.overlay_images):
if shared.opts.mask_apply_overlay and p.overlay_images is not None and len(p.overlay_images) > 0:
p.image_mask = create_binary_mask(p.overlay_images[0])
p.image_mask = ImageOps.invert(p.image_mask)
output_images.append(p.image_mask)
Expand Down
3 changes: 3 additions & 0 deletions modules/processing_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,9 @@ def set_pipeline_args(p, model, prompts:list, negative_prompts:list, prompts_2:t
if isinstance(args['image'], torch.Tensor) or isinstance(args['image'], np.ndarray):
args['width'] = 8 * args['image'].shape[-1]
args['height'] = 8 * args['image'].shape[-2]
elif isinstance(args['image'][0], torch.Tensor) or isinstance(args['image'][0], np.ndarray):
args['width'] = 8 * args['image'][0].shape[-1]
args['height'] = 8 * args['image'][0].shape[-2]
else:
args['width'] = 8 * math.ceil(args['image'][0].width / 8)
args['height'] = 8 * math.ceil(args['image'][0].height / 8)
Expand Down
2 changes: 1 addition & 1 deletion modules/processing_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ def init(self, all_prompts=None, all_seeds=None, all_subseeds=None):
image = images.resize_image(self.resize_mode, image, self.width, self.height, upscaler_name=self.resize_name, context=self.resize_context)
self.width = image.width
self.height = image.height
if self.image_mask is not None and shared.opts.mask_apply_overlay and not hasattr(self, 'xyz'):
if self.image_mask is not None and shared.opts.mask_apply_overlay:
image_masked = Image.new('RGBa', (image.width, image.height))
image_to_paste = image.convert("RGBA").convert("RGBa")
image_to_mask = ImageOps.invert(self.mask_for_overlay.convert('L')) if self.mask_for_overlay is not None else None
Expand Down
2 changes: 1 addition & 1 deletion modules/sd_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1288,7 +1288,7 @@ def set_diffuser_pipe(pipe, new_pipe_type):
new_pipe.image_encoder = image_encoder
if feature_extractor is not None:
new_pipe.feature_extractor = feature_extractor
if new_pipe.__class__.__name__ == 'FluxPipeline':
if new_pipe.__class__.__name__ in ['FluxPipeline', 'StableDiffusion3Pipeline']:
new_pipe.register_modules(image_encoder = image_encoder)
new_pipe.register_modules(feature_extractor = feature_extractor)
new_pipe.is_sdxl = getattr(pipe, 'is_sdxl', False) # a1111 compatibility item
Expand Down
5 changes: 5 additions & 0 deletions modules/sd_samplers_diffusers.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,11 +271,16 @@ def __init__(self, name, constructor, model, **kwargs):
sampler = constructor(**self.config)
accept_sigmas = "sigmas" in set(inspect.signature(sampler.set_timesteps).parameters.keys())
accepts_timesteps = "timesteps" in set(inspect.signature(sampler.set_timesteps).parameters.keys())
accept_scale_noise = hasattr(sampler, "scale_noise")
debug(f'Sampler: sampler="{name}" sigmas={accept_sigmas} timesteps={accepts_timesteps}')
if ('Flux' in model.__class__.__name__) and (not accept_sigmas):
shared.log.warning(f'Sampler: sampler="{name}" does not accept sigmas')
self.sampler = None
return
if ('StableDiffusion3' in model.__class__.__name__) and (not accept_scale_noise):
shared.log.warning(f'Sampler: sampler="{name}" does not implement scale noise')
self.sampler = None
return
self.sampler = sampler
if name == 'DC Solver':
if not hasattr(self.sampler, 'dc_ratios'):
Expand Down
2 changes: 2 additions & 0 deletions scripts/xyz_grid_on.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,12 +325,14 @@ def cell(x, y, z, ix, iy, iz):
x_opt.apply(pc, x, xs)
y_opt.apply(pc, y, ys)
z_opt.apply(pc, z, zs)

try:
processed = processing.process_images(pc)
except Exception as e:
shared.log.error(f"XYZ grid: Failed to process image: {e}")
errors.display(e, 'XYZ grid')
processed = None

if ix == 0 and iy == 0: # create subgrid info text
pc.extra_generation_params = copy(pc.extra_generation_params)
pc.extra_generation_params['Script'] = self.title()
Expand Down

0 comments on commit 94a659e

Please sign in to comment.