MCPcopy Create free account
hub / github.com/bcmi/OSInsert-Image-Composition / get_tensor

Function get_tensor

libcom/os_insert/source/objectstitch_data.py:11–30  ·  view source on GitHub ↗

Basic image -> tensor transform used by ObjectStitch (Stable Diffusion style). This is a minimal copy of the preprocessing from ObjectStitch's `ldm.data.open_images.get_tensor`, without any dataset-specific logic.

(normalize: bool = True, to_tensor: bool = True, resize: bool = True, image_size: Tuple[int, int] = (512, 512))

Source from the content-addressed store, hash-verified

9
10
11def get_tensor(normalize: bool = True, to_tensor: bool = True, resize: bool = True, image_size: Tuple[int, int] = (512, 512)):
12 """Basic image -> tensor transform used by ObjectStitch (Stable Diffusion style).
13
14 This is a minimal copy of the preprocessing from ObjectStitch's
15 `ldm.data.open_images.get_tensor`, without any dataset-specific logic.
16 """
17
18 transform_list: List[torch.nn.Module] = []
19 if resize:
20 transform_list.append(torchvision.transforms.Resize(image_size))
21 if to_tensor:
22 transform_list.append(torchvision.transforms.ToTensor())
23 if normalize:
24 transform_list.append(
25 torchvision.transforms.Normalize(
26 (0.5, 0.5, 0.5),
27 (0.5, 0.5, 0.5),
28 )
29 )
30 return torchvision.transforms.Compose(transform_list)
31
32
33def get_tensor_clip(normalize: bool = True, to_tensor: bool = True, resize: bool = True, image_size: Tuple[int, int] = (224, 224)):

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected