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)
This commit is contained in:
user1 2023-05-12 04:01:35 -07:00 committed by Kent Keirsey
parent 11fc7e40a5
commit 754acec92f
2 changed files with 16 additions and 13 deletions

View File

@ -33,16 +33,16 @@ from .image import ImageOutput, build_image_output, PILInvocationConfig
class ControlField(BaseModel): class ControlField(BaseModel):
image: ImageField = Field(default=None, description="processed image") 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_model: Optional[str] = Field(default=None, description="control model used")
control_weight: Optional[float] = Field(default=None, description="weight given to controlnet") 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: class Config:
schema_extra = { schema_extra = {
"required": ["image", "control_model", "control_weight"] "required": ["image", "control_model", "control_weight", "begin_step_percent", "end_step_percent"]
# "required": ["type", "image", "width", "height", "mode"]
} }
@ -62,12 +62,11 @@ class ControlNetInvocation(BaseInvocation):
image: ImageField = Field(default=None, description="image to process") image: ImageField = Field(default=None, description="image to process")
control_model: str = Field(default=None, description="control model to use") 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") 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) # 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, begin_step_percent: float = Field(default=0, ge=0, le=1,
# description="% of total steps at which controlnet is first applied") description="% of total steps at which controlnet is first applied")
# end_step_percent: float = Field(default=1, ge=0, le=1, end_step_percent: float = Field(default=1, ge=0, le=1,
# description="% of total steps at which controlnet is last applied") description="% of total steps at which controlnet is last applied")
# guess_mode: bool = Field(default=False, description="use guess mode (controlnet ignores prompt)")
# fmt: on # fmt: on
@ -77,7 +76,9 @@ class ControlNetInvocation(BaseInvocation):
control=ControlField( control=ControlField(
image=self.image, image=self.image,
control_model=self.control_model, 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,
), ),
) )

View File

@ -312,7 +312,9 @@ class TextToLatentsInvocation(BaseInvocation):
) )
control_item = ControlNetData(model=control_model, control_item = ControlNetData(model=control_model,
image_tensor=control_image, 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) control_data.append(control_item)
# multi_control = MultiControlNetModel(control_models) # multi_control = MultiControlNetModel(control_models)
# model.control_model = multi_control # model.control_model = multi_control