diff --git a/src/diffusers/image_processor.py b/src/diffusers/image_processor.py index 4f6f4bd52b9c..42339a2baccf 100644 --- a/src/diffusers/image_processor.py +++ b/src/diffusers/image_processor.py @@ -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. """ @@ -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) diff --git a/tests/others/test_image_processor.py b/tests/others/test_image_processor.py index 0d358699f105..487c32299a79 100644 --- a/tests/others/test_image_processor.py +++ b/tests/others/test_image_processor.py @@ -17,7 +17,7 @@ import PIL.Image import torch -from diffusers.image_processor import VaeImageProcessor +from diffusers.image_processor import InpaintProcessor, VaeImageProcessor class TestImageProcessor: @@ -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, + }