batch support

This commit is contained in:
lllyasviel
2024-02-04 22:04:20 -08:00
parent c6f7fa82ff
commit a8c43f7af0

View File

@@ -251,8 +251,12 @@ class ControlNetForForgeOfficial(scripts.Script):
preprocessor = global_state.get_preprocessor(unit.module)
input_list, resize_mode = self.get_input_data(p, unit, preprocessor)
preprocessor_outputs = []
preprocessor_output_is_image = False
input_image, input_mask = input_list[0]
preprocessor_output = None
for input_image, input_mask in input_list:
# p.extra_result_images.append(input_image)
if unit.pixel_perfect:
@@ -276,17 +280,31 @@ class ControlNetForForgeOfficial(scripts.Script):
slider_2=unit.threshold_b,
)
preprocessor_outputs.append(preprocessor_output)
preprocessor_output_is_image = judge_image_type(preprocessor_output)
if len(input_list) > 1 and not preprocessor_output_is_image:
logger.info('Batch wise input only support controlnet, control-lora, and t2i adapters!')
break
if preprocessor_output_is_image:
params.control_cond = crop_and_resize_image(preprocessor_output, resize_mode, h, w)
p.extra_result_images.append(external_code.visualize_inpaint_mask(params.control_cond))
params.control_cond = numpy_to_pytorch(params.control_cond).movedim(-1, 1)
params.control_cond = []
params.control_cond_for_hr_fix = []
for preprocessor_output in preprocessor_outputs:
control_cond = crop_and_resize_image(preprocessor_output, resize_mode, h, w)
p.extra_result_images.append(external_code.visualize_inpaint_mask(control_cond))
params.control_cond.append(numpy_to_pytorch(control_cond).movedim(-1, 1))
params.control_cond = torch.cat(params.control_cond, dim=0)
if has_high_res_fix:
params.control_cond_for_hr_fix = crop_and_resize_image(preprocessor_output, resize_mode, hr_y, hr_x)
p.extra_result_images.append(external_code.visualize_inpaint_mask(params.control_cond_for_hr_fix))
params.control_cond_for_hr_fix = numpy_to_pytorch(params.control_cond_for_hr_fix).movedim(-1, 1)
for preprocessor_output in preprocessor_outputs:
control_cond_for_hr_fix = crop_and_resize_image(preprocessor_output, resize_mode, hr_y, hr_x)
p.extra_result_images.append(external_code.visualize_inpaint_mask(control_cond_for_hr_fix))
params.control_cond_for_hr_fix.append(numpy_to_pytorch(control_cond_for_hr_fix).movedim(-1, 1))
params.control_cond_for_hr_fix = torch.cat(params.control_cond_for_hr_fix, dim=0)
else:
params.control_cond_for_hr_fix = params.control_cond
else: