diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c2c04d61..edceb23e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,10 +3,12 @@ ## Update for 2023-12-30 - **Fixes**: - - img2img clip and blip interrogate - - guard against invalid sampler index - - reset default cfg scale to 6.0 - - processing tab display metadata + - control: fix input image size + - control: fix correct image mode + - img2img: clip and blip interrogate + - guard against invalid sampler index + - reset default cfg scale to 6.0 + - processing: correct display metadata ## Update for 2023-12-29 diff --git a/modules/control/proc/canny.py b/modules/control/proc/canny.py index 1f450b9f6..e68673d88 100644 --- a/modules/control/proc/canny.py +++ b/modules/control/proc/canny.py @@ -31,6 +31,5 @@ class CannyDetector: if output_type == "pil": detected_map = Image.fromarray(detected_map) - detected_map = detected_map.convert('L') return detected_map diff --git a/modules/control/proc/edge.py b/modules/control/proc/edge.py index 73481129f..d068383c1 100644 --- a/modules/control/proc/edge.py +++ b/modules/control/proc/edge.py @@ -59,6 +59,5 @@ class EdgeDetector: if output_type == "pil": edge_map = Image.fromarray(edge_map) - edge_map = edge_map.convert('L') return edge_map diff --git a/modules/control/processors.py b/modules/control/processors.py index a52356da2..a34e14117 100644 --- a/modules/control/processors.py +++ b/modules/control/processors.py @@ -1,9 +1,9 @@ import os import time -import torch from PIL import Image from modules.shared import log from modules.errors import display +from modules import devices from modules.control.proc.hed import HEDdetector from modules.control.proc.canny import CannyDetector @@ -184,7 +184,7 @@ class Processor(): display(e, 'Control processor load') return f'Processor load filed: {processor_id}' - def __call__(self, image_input: Image): + def __call__(self, image_input: Image, mode: str = 'RGB'): if self.override is not None: image_input = self.override image_process = image_input @@ -203,19 +203,20 @@ class Processor(): t0 = time.time() kwargs = config.get(self.processor_id, {}).get('params', None) if self.resize: - orig_size = image_input.size image_resized = image_input.resize((512, 512)) else: image_resized = image_input - with torch.no_grad(): + with devices.inference_context(): image_process = self.model(image_resized, **kwargs) - if self.resize: - image_process = image_process.resize(orig_size, Image.Resampling.LANCZOS) + if self.resize and image_process.size != image_input.size: + image_process = image_process.resize(image_input.size, Image.Resampling.LANCZOS) t1 = time.time() - log.debug(f'Control processor: id="{self.processor_id}" args={kwargs} time={t1-t0:.2f}') + log.debug(f'Control processor: id="{self.processor_id}" mode={mode} args={kwargs} time={t1-t0:.2f}') except Exception as e: log.error(f'Control processor failed: id="{self.processor_id}" error={e}') display(e, 'Control processor') + if mode != 'RGB': + image_process = image_process.convert(mode) return image_process def preview(self, image_input: Image): diff --git a/modules/control/run.py b/modules/control/run.py index 7e499e956..3e11ba4c5 100644 --- a/modules/control/run.py +++ b/modules/control/run.py @@ -340,6 +340,9 @@ def control_run(units: List[unit.Unit], inputs, inits, unit_type: str, is_genera if p.resize_mode != 0 and input_image is not None and resize_time == 'Before': debug(f'Control resize: image={input_image} width={width} height={height} mode={p.resize_mode} name={resize_name} sequence={resize_time}') input_image = images.resize_image(p.resize_mode, input_image, width, height, resize_name) + p.width = input_image.width + p.height = input_image.height + debug(f'Control: input image={input_image}') # process if input_image is None: @@ -357,7 +360,8 @@ def control_run(units: List[unit.Unit], inputs, inits, unit_type: str, is_genera return msg processed_image = p.ref_image elif len(active_process) == 1: - p.image = active_process[0](input_image) + image_mode = 'L' if unit_type == 'adapter' and len(active_model) > 0 and ('Canny' in active_model[0].model_id or 'Sketch' in active_model[0].model_id) else 'RGB' + p.image = active_process[0](input_image, image_mode) p.task_args['image'] = p.image p.extra_generation_params["Control process"] = active_process[0].processor_id debug(f'Control: process={active_process[0].processor_id} image={p.image}') @@ -369,7 +373,10 @@ def control_run(units: List[unit.Unit], inputs, inits, unit_type: str, is_genera processed_image = p.image else: if len(active_process) > 0: - p.image = [p(input_image) for p in active_process] # list[image] + p.image = [] + for i, process in enumerate(active_process): # list[image] + image_mode = 'L' if unit_type == 'adapter' and len(active_model) > i and ('Canny' in active_model[i].model_id or 'Sketch' in active_model[i].model_id) else 'RGB' + p.image.append(process(input_image, image_mode)) else: p.image = [input_image] p.task_args['image'] = p.image diff --git a/modules/processing_diffusers.py b/modules/processing_diffusers.py index f8d0e635a..d7ee7b9b3 100644 --- a/modules/processing_diffusers.py +++ b/modules/processing_diffusers.py @@ -139,6 +139,8 @@ def process_diffusers(p: StableDiffusionProcessing): def task_specific_kwargs(model): task_args = {} is_img2img_model = bool('Zero123' in shared.sd_model.__class__.__name__) + if len(getattr(p, 'init_images' ,[])) > 0: + p.init_images = [p.convert('RGB') for p in p.init_images] if sd_models.get_diffusers_task(model) == sd_models.DiffusersTaskType.TEXT_2_IMAGE and not is_img2img_model: p.ops.append('txt2img') if hasattr(p, 'width') and hasattr(p, 'height'):