(path)
| 269 | |
| 270 | |
| 271 | def load_img(path): |
| 272 | image = Image.open(path).convert("RGB") |
| 273 | w, h = image.size |
| 274 | print(f"loaded input image of size ({w}, {h}) from {path}") |
| 275 | w, h = map(lambda x: x - x % 32, (w, h)) # resize to integer multiple of 32 |
| 276 | image = image.resize((w, h), resample=PIL.Image.LANCZOS) |
| 277 | image = np.array(image).astype(np.float32) / 255.0 |
| 278 | image = image[None].transpose(0, 3, 1, 2) |
| 279 | image = torch.from_numpy(image) |
| 280 | return 2.0 * image - 1.0 |