MCPcopy Index your code
hub / github.com/huggingface/diffusers / is_valid_image_imagelist

Function is_valid_image_imagelist

src/diffusers/image_processor.py:54–79  ·  view source on GitHub ↗

r""" Checks if the input is a valid image or list of images. The input can be one of the following formats: - A 4D tensor or numpy array (batch of images). - A valid single image: `PIL.Image.Image`, 2D `np.ndarray` or `torch.Tensor` (grayscale image), 3D `np.ndarray` or `torch

(images)

Source from the content-addressed store, hash-verified

52
53
54def is_valid_image_imagelist(images):
55 r"""
56 Checks if the input is a valid image or list of images.
57
58 The input can be one of the following formats:
59 - A 4D tensor or numpy array (batch of images).
60 - A valid single image: `PIL.Image.Image`, 2D `np.ndarray` or `torch.Tensor` (grayscale image), 3D `np.ndarray` or
61 `torch.Tensor`.
62 - A list of valid images.
63
64 Args:
65 images (`np.ndarray | torch.Tensor | PIL.Image.Image | list`):
66 The image(s) to check. Can be a batch of images (4D tensor/array), a single image, or a list of valid
67 images.
68
69 Returns:
70 `bool`:
71 `True` if the input is valid, `False` otherwise.
72 """
73 if isinstance(images, (np.ndarray, torch.Tensor)) and images.ndim == 4:
74 return True
75 elif is_valid_image(images):
76 return True
77 elif isinstance(images, list):
78 return all(is_valid_image(image) for image in images)
79 return False
80
81
82class VaeImageProcessor(ConfigMixin):

Callers 6

preprocess_videoMethod · 0.85
preprocessMethod · 0.85
__call__Method · 0.85
__call__Method · 0.85
__call__Method · 0.85
__call__Method · 0.85

Calls 1

is_valid_imageFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…