(image, batch_size)
| 404 | |
| 405 | |
| 406 | def preprocess_image(image, batch_size): |
| 407 | w, h = image.size |
| 408 | w, h = (x - x % 8 for x in (w, h)) # resize to integer multiple of 8 |
| 409 | image = image.resize((w, h), resample=PIL_INTERPOLATION["lanczos"]) |
| 410 | image = np.array(image).astype(np.float32) / 255.0 |
| 411 | image = np.vstack([image[None].transpose(0, 3, 1, 2)] * batch_size) |
| 412 | image = torch.from_numpy(image) |
| 413 | return 2.0 * image - 1.0 |
| 414 | |
| 415 | |
| 416 | def preprocess_mask(mask, batch_size, scale_factor=8): |