Skip to content

Commit

Permalink
Fix resize mode enum values for deforum (#2861)
Browse files Browse the repository at this point in the history
  • Loading branch information
huchenlei authored May 7, 2024
1 parent 4cb2286 commit 084dd01
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
18 changes: 17 additions & 1 deletion internal_controlnet/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions unit_tests/args_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit 084dd01

Please sign in to comment.