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 @@ -989,7 +989,12 @@ def __init__(
resample: str = "lanczos",
do_normalize: bool = True,
):
super().__init__()
super().__init__(
do_resize=do_resize,
vae_scale_factor=vae_scale_factor,
resample=resample,
do_normalize=do_normalize,
)

@staticmethod
def numpy_to_pil(images: np.ndarray) -> list[PIL.Image.Image]:
Expand Down Expand Up @@ -1214,7 +1219,7 @@ def preprocess(
if self.config.do_resize:
rgb = self.resize(rgb, height, width)

depth = np.concatenate(depth, axis=0) if rgb[0].ndim == 4 else np.stack(depth, axis=0)
depth = np.concatenate(depth, axis=0) if depth[0].ndim == 4 else np.stack(depth, axis=0)
depth = self.numpy_to_pt(depth)
height, width = self.get_default_height_width(depth, height, width)
if self.config.do_resize:
Expand Down
25 changes: 24 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 VaeImageProcessor, VaeImageProcessorLDM3D


class TestImageProcessor:
Expand Down Expand Up @@ -306,3 +306,26 @@ 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_vae_image_processor_ldm3d_config(self):
image_processor = VaeImageProcessorLDM3D(
do_resize=False,
vae_scale_factor=4,
resample="nearest",
do_normalize=False,
)

assert image_processor.config.do_resize is False
assert image_processor.config.vae_scale_factor == 4
assert image_processor.config.resample == "nearest"
assert image_processor.config.do_normalize is False

def test_vae_image_processor_ldm3d_np_batch(self):
image_processor = VaeImageProcessorLDM3D(do_resize=False, do_normalize=False)
rgb = np.zeros((2, 8, 8, 3), dtype=np.float32)
depth = np.zeros((2, 8, 8, 1), dtype=np.float32)

processed_rgb, processed_depth = image_processor.preprocess(rgb, depth)

assert processed_rgb.shape == (2, 3, 8, 8)
assert processed_depth.shape == (2, 1, 8, 8)
Loading