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

Function is_valid_image

src/diffusers/image_processor.py:35–51  ·  view source on GitHub ↗

r""" Checks if the input is a valid image. A valid image can be: - A `PIL.Image.Image`. - A 2D or 3D `np.ndarray` or `torch.Tensor` (grayscale or color image). Args: image (`PIL.Image.Image | np.ndarray | torch.Tensor`): The image to validate. It can be a PI

(image)

Source from the content-addressed store, hash-verified

33
34
35def is_valid_image(image) -> bool:
36 r"""
37 Checks if the input is a valid image.
38
39 A valid image can be:
40 - A `PIL.Image.Image`.
41 - A 2D or 3D `np.ndarray` or `torch.Tensor` (grayscale or color image).
42
43 Args:
44 image (`PIL.Image.Image | np.ndarray | torch.Tensor`):
45 The image to validate. It can be a PIL image, a NumPy array, or a torch tensor.
46
47 Returns:
48 `bool`:
49 `True` if the input is a valid image, `False` otherwise.
50 """
51 return isinstance(image, PIL.Image.Image) or isinstance(image, (np.ndarray, torch.Tensor)) and image.ndim in (2, 3)
52
53
54def is_valid_image_imagelist(images):

Callers 6

preprocess_videoMethod · 0.85
is_valid_image_imagelistFunction · 0.85
__call__Method · 0.85
__call__Method · 0.85
__call__Method · 0.85
__call__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…