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

Method numpy_to_pt

src/diffusers/image_processor.py:114–122  ·  view source on GitHub ↗

Convert a NumPy image to a PyTorch tensor.

(images: np.ndarray)

Source from the content-addressed store, hash-verified

112
113 @staticmethod
114 def numpy_to_pt(images: np.ndarray) -> torch.FloatTensor:
115 """
116 Convert a NumPy image to a PyTorch tensor.
117 """
118 if images.ndim == 3:
119 images = images[..., None]
120
121 images = torch.from_numpy(images.transpose(0, 3, 1, 2))
122 return images
123
124 @staticmethod
125 def pt_to_numpy(images: torch.FloatTensor) -> np.ndarray:

Callers 4

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

Calls 1

transposeMethod · 0.80

Tested by 1

convert_to_ptMethod · 0.36