MCPcopy Create free account
hub / github.com/modelscope/DiffSynth-Studio / preprocess_image

Method preprocess_image

diffsynth/utils/__init__.py:61–67  ·  view source on GitHub ↗
(self, image, torch_dtype=None, device=None, pattern="B C H W", min_value=-1, max_value=1)

Source from the content-addressed store, hash-verified

59
60
61 def preprocess_image(self, image, torch_dtype=None, device=None, pattern="B C H W", min_value=-1, max_value=1):
62 # Transform a PIL.Image to torch.Tensor
63 image = torch.Tensor(np.array(image, dtype=np.float32))
64 image = image.to(dtype=torch_dtype or self.torch_dtype, device=device or self.device)
65 image = image * ((max_value - min_value) / 255) + min_value
66 image = repeat(image, f"H W C -> {pattern}", **({"B": 1} if "B" in pattern else {}))
67 return image
68
69
70 def preprocess_video(self, video, torch_dtype=None, device=None, pattern="B C T H W", min_value=-1, max_value=1):

Callers 1

preprocess_videoMethod · 0.95

Calls 1

toMethod · 0.45

Tested by

no test coverage detected