Fix resize mode enum values for deforum (#2861)

pull/2865/head
Chenlei Hu 2024-05-07 08:04:12 -04:00 committed by GitHub
parent 4cb22867c2
commit 084dd0107b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 1 deletions

View File

@ -95,6 +95,20 @@ class ControlNetUnit(BaseModel):
image: Optional[Any] = None
resize_mode: ResizeMode = ResizeMode.INNER_FIT
@validator("resize_mode", always=True, pre=True)
def check_resize_mode(cls, value) -> ResizeMode:
resize_mode_aliases = {
"Inner Fit (Scale to Fit)": "Crop and Resize",
"Outer Fit (Shrink to Fit)": "Resize and Fill",
"Scale to Fit (Inner Fit)": "Crop and Resize",
"Envelope (Outer Fit)": "Resize and Fill",
}
if isinstance(value, str):
return ResizeMode(resize_mode_aliases.get(value, value))
assert isinstance(value, ResizeMode)
return value
low_vram: bool = False
processor_res: int = -1
threshold_a: float = -1
@ -378,7 +392,9 @@ class ControlNetUnit(BaseModel):
np_image = self.parse_image(image)
np_mask = self.parse_image(mask) if mask is not None else None
np_images.append(self.combine_image_and_mask(np_image, np_mask)) # [H, W, 4]
np_images.append(
self.combine_image_and_mask(np_image, np_mask)
) # [H, W, 4]
return np_images

View File

@ -151,6 +151,9 @@ def test_mask_alias_conflict():
def test_resize_mode():
ControlNetUnit(resize_mode="Just Resize")
# Alias should also work. For deforum
# See https://github.com/deforum-art/sd-webui-deforum/blob/322426851408ebca2cd49492bfeb1ec86e1dc869/scripts/deforum_helpers/deforum_controlnet.py#L150
ControlNetUnit(resize_mode="Inner Fit (Scale to Fit)")
def test_weight():