MCPcopy Create free account
hub / github.com/Chen-Yang-Liu/Text2Earth / numpy_to_pt

Method numpy_to_pt

src/diffusers/image_processor.py:132–140  ·  view source on GitHub ↗

Convert a NumPy image to a PyTorch tensor.

(images: np.ndarray)

Source from the content-addressed store, hash-verified

130
131 @staticmethod
132 def numpy_to_pt(images: np.ndarray) -> torch.Tensor:
133 """
134 Convert a NumPy image to a PyTorch tensor.
135 """
136 if images.ndim == 3:
137 images = images[..., None]
138
139 images = torch.from_numpy(images.transpose(0, 3, 1, 2))
140 return images
141
142 @staticmethod
143 def pt_to_numpy(images: torch.Tensor) -> np.ndarray:

Callers 4

resizeMethod · 0.95
preprocessMethod · 0.95
preprocessMethod · 0.45
convert_to_ptMethod · 0.45

Calls

no outgoing calls

Tested by 1

convert_to_ptMethod · 0.36