(image)
| 1336 | |
| 1337 | |
| 1338 | def preprocess_image(image): |
| 1339 | w, h = image.size |
| 1340 | w, h = map(lambda x: x - x % 32, (w, h)) # resize to integer multiple of 32 |
| 1341 | image = image.resize((w, h), resample=PIL.Image.LANCZOS) |
| 1342 | image = np.array(image).astype(np.float32) / 255.0 |
| 1343 | image = image[None].transpose(0, 3, 1, 2) |
| 1344 | image = torch.from_numpy(image) |
| 1345 | return 2.0 * image - 1.0 |
| 1346 | |
| 1347 | |
| 1348 | def preprocess_mask(mask): |