MCPcopy Create free account
hub / github.com/TencentARC/BrushNet / pil_to_numpy

Method pil_to_numpy

src/diffusers/image_processor.py:102–111  ·  view source on GitHub ↗

Convert a PIL image or a list of PIL images to NumPy arrays.

(images: Union[List[PIL.Image.Image], PIL.Image.Image])

Source from the content-addressed store, hash-verified

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:

Callers 14

preprocessMethod · 0.95
test_kandinskyV3Method · 0.95
preprocessMethod · 0.80
_encode_imageMethod · 0.80
_encode_imageMethod · 0.80
test_sdxl_lcm_loraMethod · 0.80
test_sdv1_5_lcm_loraMethod · 0.80
convert_to_ptMethod · 0.80

Calls

no outgoing calls

Tested by 10

test_kandinskyV3Method · 0.76
test_sdxl_lcm_loraMethod · 0.64
test_sdv1_5_lcm_loraMethod · 0.64
convert_to_ptMethod · 0.64