MCPcopy
hub / github.com/huggingface/diffusers / pt_to_numpy

Method pt_to_numpy

src/diffusers/image_processor.py:191–204  ·  view source on GitHub ↗

r""" Convert a PyTorch tensor to a NumPy image. Args: images (`torch.Tensor`): The PyTorch tensor to convert to NumPy format. Returns: `np.ndarray`: A NumPy array representation of the images.

(images: torch.Tensor)

Source from the content-addressed store, hash-verified

189
190 @staticmethod
191 def pt_to_numpy(images: torch.Tensor) -> np.ndarray:
192 r"""
193 Convert a PyTorch tensor to a NumPy image.
194
195 Args:
196 images (`torch.Tensor`):
197 The PyTorch tensor to convert to NumPy format.
198
199 Returns:
200 `np.ndarray`:
201 A NumPy array representation of the images.
202 """
203 images = images.cpu().permute(0, 2, 3, 1).float().numpy()
204 return images
205
206 @staticmethod
207 def normalize(images: np.ndarray | torch.Tensor) -> np.ndarray | torch.Tensor:

Callers 5

resizeMethod · 0.95
postprocessMethod · 0.95
postprocessMethod · 0.45
convert_pt_to_typeMethod · 0.45
log_validationFunction · 0.45

Calls 1

floatMethod · 0.80

Tested by 1

convert_pt_to_typeMethod · 0.36