control fix input size and image mode

This commit is contained in:
Vladimir Mandic
2023-12-30 09:42:44 -05:00
parent 01e6da2df0
commit 4c4429c5b4
6 changed files with 25 additions and 15 deletions
+6 -4
View File
@@ -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
-1
View File
@@ -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
-1
View File
@@ -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
+8 -7
View File
@@ -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):
+9 -2
View File
@@ -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
+2
View File
@@ -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'):