"vscode:/vscode.git/clone" did not exist on "b662d9fd8cc858ab359577d4df773ce02011a8b3"
run_inference.py 628 Bytes
Newer Older
Patrick von Platen's avatar
up  
Patrick von Platen committed
1
2
#!/usr/bin/env python3
# !pip install diffusers
3
from modeling_ddim import DDIM
Patrick von Platen's avatar
up  
Patrick von Platen committed
4
5
6
7
8
9
10
import PIL.Image
import numpy as np

model_id = "fusing/ddpm-cifar10"
model_id = "fusing/ddpm-lsun-bedroom"

# load model and scheduler
11
ddpm = DDIM.from_pretrained(model_id)
Patrick von Platen's avatar
up  
Patrick von Platen committed
12
13
14
15
16
17
18
19
20
21
22
23

# run pipeline in inference (sample random noise and denoise)
image = ddpm()

# process image to PIL
image_processed = image.cpu().permute(0, 2, 3, 1)
image_processed = (image_processed + 1.0) * 127.5
image_processed = image_processed.numpy().astype(np.uint8)
image_pil = PIL.Image.fromarray(image_processed[0])

# save image
image_pil.save("/home/patrick/images/show.png")