diff --git a/internal_controlnet/args.py b/internal_controlnet/args.py index a32ec5218..f36448ef1 100644 --- a/internal_controlnet/args.py +++ b/internal_controlnet/args.py @@ -95,6 +95,20 @@ def check_model(cls, value: str) -> str: 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 @@ def get_input_images_rgba(self) -> Optional[List[np.ndarray]]: 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 diff --git a/unit_tests/args_test.py b/unit_tests/args_test.py index af2529788..0c053f73f 100644 --- a/unit_tests/args_test.py +++ b/unit_tests/args_test.py @@ -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():