run_glide.py 571 Bytes
Newer Older
Patrick von Platen's avatar
Patrick von Platen committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import torch

import PIL.Image
from diffusers import DiffusionPipeline


generator = torch.Generator()
generator = generator.manual_seed(0)

model_id = "fusing/glide-base"

# load model and scheduler
pipeline = DiffusionPipeline.from_pretrained(model_id)

# run inference (text-conditioned denoising + upscaling)
img = pipeline("a crayon drawing of a corgi", generator)

# process image to PIL
img = img.squeeze(0)
img = ((img + 1) * 127.5).round().clamp(0, 255).to(torch.uint8).cpu().numpy()
image_pil = PIL.Image.fromarray(img)

# save image
image_pil.save("test.png")