run_inference.py 630 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
25
#!/usr/bin/env python3
# !pip install diffusers
import numpy as np

import PIL.Image
from modeling_ddim import DDIM


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

# load model and scheduler
ddpm = DDIM.from_pretrained(model_id)

# 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")