(image)
| 49 | |
| 50 | |
| 51 | def preprocess(image): |
| 52 | w, h = image.size |
| 53 | w, h = (x - x % 32 for x in (w, h)) # resize to integer multiple of 32 |
| 54 | image = image.resize((w, h), resample=PIL_INTERPOLATION["lanczos"]) |
| 55 | image = np.array(image).astype(np.float32) / 255.0 |
| 56 | image = image[None].transpose(0, 3, 1, 2) |
| 57 | image = torch.from_numpy(image) |
| 58 | return 2.0 * image - 1.0 |
| 59 | |
| 60 | |
| 61 | class ImagicStableDiffusionPipeline(DiffusionPipeline, StableDiffusionMixin): |