From 754acec92f0e8c3eb410474ab439cfa0ac8a24cd Mon Sep 17 00:00:00 2001 From: user1 Date: Fri, 12 May 2023 04:01:35 -0700 Subject: [PATCH] Added support for specifying which step iteration to start using each ControlNet, and which step to end using each controlnet (specified as fraction of total steps) --- .../controlnet_image_processors.py | 25 ++++++++++--------- invokeai/app/invocations/latent.py | 4 ++- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/invokeai/app/invocations/controlnet_image_processors.py b/invokeai/app/invocations/controlnet_image_processors.py index 169dfc96c4..6cb9a73976 100644 --- a/invokeai/app/invocations/controlnet_image_processors.py +++ b/invokeai/app/invocations/controlnet_image_processors.py @@ -33,16 +33,16 @@ from .image import ImageOutput, build_image_output, PILInvocationConfig class ControlField(BaseModel): image: ImageField = Field(default=None, description="processed image") - # width: Optional[int] = Field(default=None, description="The width of the image in pixels") - # height: Optional[int] = Field(default=None, description="The height of the image in pixels") - # mode: Optional[str] = Field(default=None, description="The mode of the image") control_model: Optional[str] = Field(default=None, description="control model used") control_weight: Optional[float] = Field(default=None, description="weight given to controlnet") + begin_step_percent: float = Field(default=0, ge=0, le=1, + description="% of total steps at which controlnet is first applied") + end_step_percent: float = Field(default=1, ge=0, le=1, + description="% of total steps at which controlnet is last applied") class Config: schema_extra = { - "required": ["image", "control_model", "control_weight"] - # "required": ["type", "image", "width", "height", "mode"] + "required": ["image", "control_model", "control_weight", "begin_step_percent", "end_step_percent"] } @@ -62,12 +62,11 @@ class ControlNetInvocation(BaseInvocation): image: ImageField = Field(default=None, description="image to process") control_model: str = Field(default=None, description="control model to use") control_weight: float = Field(default=0.5, ge=0, le=1, description="weight given to controlnet") - # TODO: support additional ControlNet parameters (mostly just passthroughs to other nodes with ControlField inputs) - # begin_step_percent: float = Field(default=0, ge=0, le=1, - # description="% of total steps at which controlnet is first applied") - # end_step_percent: float = Field(default=1, ge=0, le=1, - # description="% of total steps at which controlnet is last applied") - # guess_mode: bool = Field(default=False, description="use guess mode (controlnet ignores prompt)") + # TODO: add support in backend core for begin_step_percent, end_step_percent, guess_mode + begin_step_percent: float = Field(default=0, ge=0, le=1, + description="% of total steps at which controlnet is first applied") + end_step_percent: float = Field(default=1, ge=0, le=1, + description="% of total steps at which controlnet is last applied") # fmt: on @@ -77,7 +76,9 @@ class ControlNetInvocation(BaseInvocation): control=ControlField( image=self.image, control_model=self.control_model, - control_weight=self.control_weight + control_weight=self.control_weight, + begin_step_percent=self.begin_step_percent, + end_step_percent=self.end_step_percent, ), ) diff --git a/invokeai/app/invocations/latent.py b/invokeai/app/invocations/latent.py index 94775e9a44..ad4adc6fbb 100644 --- a/invokeai/app/invocations/latent.py +++ b/invokeai/app/invocations/latent.py @@ -312,7 +312,9 @@ class TextToLatentsInvocation(BaseInvocation): ) control_item = ControlNetData(model=control_model, image_tensor=control_image, - weight=control_info.control_weight) + weight=control_info.control_weight, + begin_step_percent=control_info.begin_step_percent, + end_step_percent=control_info.end_step_percent) control_data.append(control_item) # multi_control = MultiControlNetModel(control_models) # model.control_model = multi_control