diff options
Diffstat (limited to 'modules/processing.py')
-rw-r--r-- | modules/processing.py | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/modules/processing.py b/modules/processing.py index 5abdfd7c..798313ee 100644 --- a/modules/processing.py +++ b/modules/processing.py @@ -12,7 +12,7 @@ import cv2 from skimage import exposure
import modules.sd_hijack
-from modules import devices
+from modules import devices, prompt_parser
from modules.sd_hijack import model_hijack
from modules.sd_samplers import samplers, samplers_for_img2img
from modules.shared import opts, cmd_opts, state
@@ -46,14 +46,14 @@ def apply_color_correction(correction, image): class StableDiffusionProcessing:
- def __init__(self, sd_model=None, outpath_samples=None, outpath_grids=None, prompt="", prompt_style="None", seed=-1, subseed=-1, subseed_strength=0, seed_resize_from_h=-1, seed_resize_from_w=-1, sampler_index=0, batch_size=1, n_iter=1, steps=50, cfg_scale=7.0, width=512, height=512, restore_faces=False, tiling=False, do_not_save_samples=False, do_not_save_grid=False, extra_generation_params=None, overlay_images=None, negative_prompt=None):
+ def __init__(self, sd_model=None, outpath_samples=None, outpath_grids=None, prompt="", styles=None, seed=-1, subseed=-1, subseed_strength=0, seed_resize_from_h=-1, seed_resize_from_w=-1, sampler_index=0, batch_size=1, n_iter=1, steps=50, cfg_scale=7.0, width=512, height=512, restore_faces=False, tiling=False, do_not_save_samples=False, do_not_save_grid=False, extra_generation_params=None, overlay_images=None, negative_prompt=None):
self.sd_model = sd_model
self.outpath_samples: str = outpath_samples
self.outpath_grids: str = outpath_grids
self.prompt: str = prompt
self.prompt_for_display: str = None
self.negative_prompt: str = (negative_prompt or "")
- self.prompt_style: str = prompt_style
+ self.styles: str = styles
self.seed: int = seed
self.subseed: int = subseed
self.subseed_strength: float = subseed_strength
@@ -194,9 +194,9 @@ def process_images(p: StableDiffusionProcessing) -> Processed: modules.sd_hijack.model_hijack.apply_circular(p.tiling)
- comments = []
+ comments = {}
- modules.styles.apply_style(p, shared.prompt_styles[p.prompt_style])
+ shared.prompt_styles.apply_styles(p)
if type(p.prompt) == list:
all_prompts = p.prompt
@@ -261,11 +261,14 @@ def process_images(p: StableDiffusionProcessing) -> Processed: seeds = all_seeds[n * p.batch_size:(n + 1) * p.batch_size]
subseeds = all_subseeds[n * p.batch_size:(n + 1) * p.batch_size]
- uc = p.sd_model.get_learned_conditioning(len(prompts) * [p.negative_prompt])
- c = p.sd_model.get_learned_conditioning(prompts)
+ #uc = p.sd_model.get_learned_conditioning(len(prompts) * [p.negative_prompt])
+ #c = p.sd_model.get_learned_conditioning(prompts)
+ uc = prompt_parser.get_learned_conditioning(len(prompts) * [p.negative_prompt], p.steps)
+ c = prompt_parser.get_learned_conditioning(prompts, p.steps)
if len(model_hijack.comments) > 0:
- comments += model_hijack.comments
+ for comment in model_hijack.comments:
+ comments[comment] = 1
# we manually generate all input noises because each one should have a specific seed
x = create_random_tensors([opt_C, p.height // opt_f, p.width // opt_f], seeds=seeds, subseeds=subseeds, subseed_strength=p.subseed_strength, seed_resize_from_h=p.seed_resize_from_h, seed_resize_from_w=p.seed_resize_from_w, p=p)
@@ -326,12 +329,10 @@ def process_images(p: StableDiffusionProcessing) -> Processed: state.nextjob()
unwanted_grid_because_of_img_count = len(output_images) < 2 and opts.grid_only_if_multiple
- if not p.do_not_save_grid and not unwanted_grid_because_of_img_count:
- return_grid = opts.return_grid
-
+ if (opts.return_grid or opts.grid_save) and not p.do_not_save_grid and not unwanted_grid_because_of_img_count:
grid = images.image_grid(output_images, p.batch_size)
- if return_grid:
+ if opts.return_grid:
output_images.insert(0, grid)
if opts.grid_save:
@@ -458,7 +459,9 @@ class StableDiffusionProcessingImg2Img(StableDiffusionProcessing): latent_mask = self.latent_mask if self.latent_mask is not None else self.image_mask
- self.color_corrections = []
+ add_color_corrections = opts.img2img_color_correction and self.color_corrections is None
+ if add_color_corrections:
+ self.color_corrections = []
imgs = []
for img in self.init_images:
image = img.convert("RGB")
@@ -480,7 +483,7 @@ class StableDiffusionProcessingImg2Img(StableDiffusionProcessing): if self.inpainting_fill != 1:
image = fill(image, latent_mask)
- if opts.img2img_color_correction:
+ if add_color_corrections:
self.color_corrections.append(setup_color_correction(image))
image = np.array(image).astype(np.float32) / 255.0
|