Convert a PIL image or a list of PIL images to NumPy arrays.
(images: Union[List[PIL.Image.Image], PIL.Image.Image])
| 100 | |
| 101 | @staticmethod |
| 102 | def pil_to_numpy(images: Union[List[PIL.Image.Image], PIL.Image.Image]) -> np.ndarray: |
| 103 | """ |
| 104 | Convert a PIL image or a list of PIL images to NumPy arrays. |
| 105 | """ |
| 106 | if not isinstance(images, list): |
| 107 | images = [images] |
| 108 | images = [np.array(image).astype(np.float32) / 255.0 for image in images] |
| 109 | images = np.stack(images, axis=0) |
| 110 | |
| 111 | return images |
| 112 | |
| 113 | @staticmethod |
| 114 | def numpy_to_pt(images: np.ndarray) -> torch.FloatTensor: |
no outgoing calls