Skip to content
Open
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
9 changes: 7 additions & 2 deletions src/diffusers/image_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ def preprocess(
height: int | None = None,
width: int | None = None,
padding_mask_crop: int | None = None,
) -> tuple[torch.Tensor, torch.Tensor]:
) -> tuple[torch.Tensor, torch.Tensor | None, dict]:
"""
Preprocess the image and mask.
"""
Expand All @@ -894,7 +894,12 @@ def preprocess(

# if mask is None, same behavior as regular image processor
if mask is None:
return self._image_processor.preprocess(image, height=height, width=width)
processed_image = self._image_processor.preprocess(image, height=height, width=width)
return processed_image, None, {
"crops_coords": None,
"original_image": None,
"original_mask": None,
}

if padding_mask_crop is not None:
crops_coords = self._image_processor.get_crop_region(mask, width, height, pad=padding_mask_crop)
Expand Down
16 changes: 15 additions & 1 deletion tests/others/test_image_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import PIL.Image
import torch

from diffusers.image_processor import VaeImageProcessor
from diffusers.image_processor import InpaintProcessor, VaeImageProcessor


class TestImageProcessor:
Expand Down Expand Up @@ -306,3 +306,17 @@ def test_vae_image_processor_resize_np(self):
assert out_np.shape == exp_np_shape, (
f"resized image output shape '{out_np.shape}' didn't match expected shape '{exp_np_shape}'."
)

def test_inpaint_processor_without_mask_returns_three_values(self):
processor = InpaintProcessor(do_resize=False)
image = PIL.Image.fromarray(np.zeros((8, 8, 3), dtype=np.uint8))

processed_image, processed_mask, postprocessing_kwargs = processor.preprocess(image)

assert processed_image.shape == (1, 3, 8, 8)
assert processed_mask is None
assert postprocessing_kwargs == {
"crops_coords": None,
"original_image": None,
"original_mask": None,
}
Loading