(image: PIL.Image, batch_size: int)
| 398 | |
| 399 | |
| 400 | def preprocess_image(image: PIL.Image, batch_size: int): |
| 401 | w, h = image.size |
| 402 | w, h = (x - x % 8 for x in (w, h)) # resize to integer multiple of 8 |
| 403 | image = image.resize((w, h), resample=PIL.Image.LANCZOS) |
| 404 | image = np.array(image).astype(np.float32) / 255.0 |
| 405 | image = np.vstack([image[None].transpose(0, 3, 1, 2)] * batch_size) |
| 406 | image = torch.from_numpy(image) |
| 407 | return 2.0 * image - 1.0 |
| 408 | |
| 409 | |
| 410 | def export_to_gif(image: List[PIL.Image.Image], output_gif_path: str = None) -> str: |