Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix resize mode enum values for deforum #2861

Merged
merged 1 commit into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading