| 289 | |
| 290 | |
| 291 | def preprocess_image(image: PIL.Image, batch_size: int): |
| 292 | w, h = image.size |
| 293 | w, h = (x - x % 8 for x in (w, h)) # resize to integer multiple of 8 |
| 294 | image = image.resize((w, h), resample=PIL.Image.LANCZOS) |
| 295 | image = np.array(image).astype(np.float32) / 255.0 |
| 296 | image = np.vstack([image[None].transpose(0, 3, 1, 2)] * batch_size) |
| 297 | image = torch.from_numpy(image) |
| 298 | return 2.0 * image - 1.0 |
| 299 | |
| 300 | |
| 301 | def export_to_video(video_frames: List[np.ndarray], output_video_path: str = None) -> str: |