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)
| 52 | |
| 53 | |
| 54 | def 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 | |
| 82 | class VaeImageProcessor(ConfigMixin): |
no test coverage detected
searching dependent graphs…