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))
| 9 | |
| 10 | |
| 11 | def 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 | |
| 33 | def get_tensor_clip(normalize: bool = True, to_tensor: bool = True, resize: bool = True, image_size: Tuple[int, int] = (224, 224)): |