(image: PIL.Image, batch_size: int)
| 942 | |
| 943 | |
| 944 | def preprocess_image(image: PIL.Image, batch_size: int): |
| 945 | w, h = image.size |
| 946 | w, h = (x - x % 8 for x in (w, h)) # resize to integer multiple of 8 |
| 947 | image = image.resize((w, h), resample=PIL.Image.LANCZOS) |
| 948 | image = np.array(image).astype(np.float32) / 255.0 |
| 949 | image = np.vstack([image[None].transpose(0, 3, 1, 2)] * batch_size) |
| 950 | image = torch.from_numpy(image) |
| 951 | return 2.0 * image - 1.0 |
| 952 | |
| 953 | |
| 954 | def export_to_gif(image: list[PIL.Image.Image], output_gif_path: str = None) -> str: |