run_glide.py 571 Bytes
Newer Older
anton-l's avatar
anton-l committed
1
import torch
Patrick von Platen's avatar
Patrick von Platen committed
2

anton-l's avatar
anton-l committed
3
import PIL.Image
Patrick von Platen's avatar
Patrick von Platen committed
4
5
from diffusers import DiffusionPipeline

anton-l's avatar
Style  
anton-l committed
6

anton-l's avatar
anton-l committed
7
8
9
generator = torch.Generator()
generator = generator.manual_seed(0)

anton-l's avatar
anton-l committed
10
11
12
13
14
15
model_id = "fusing/glide-base"

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

# run inference (text-conditioned denoising + upscaling)
anton-l's avatar
anton-l committed
16
img = pipeline("a crayon drawing of a corgi", generator)
anton-l's avatar
anton-l committed
17

anton-l's avatar
anton-l committed
18
# process image to PIL
anton-l's avatar
anton-l committed
19
img = img.squeeze(0)
Patrick von Platen's avatar
Patrick von Platen committed
20
img = ((img + 1) * 127.5).round().clamp(0, 255).to(torch.uint8).cpu().numpy()
anton-l's avatar
anton-l committed
21
image_pil = PIL.Image.fromarray(img)
anton-l's avatar
anton-l committed
22

anton-l's avatar
anton-l committed
23
# save image
Patrick von Platen's avatar
Patrick von Platen committed
24
image_pil.save("test.png")