-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathupscale.py
More file actions
29 lines (22 loc) · 675 Bytes
/
upscale.py
File metadata and controls
29 lines (22 loc) · 675 Bytes
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
26
27
28
29
import torch
from torch import autocast
from tqdm.auto import tqdm
from diffusers import StableDiffusionUpscalePipeline
from PIL import Image
import util
device = "cuda"
model_path = "stabilityai/stable-diffusion-x4-upscaler"
prompt = "A cat"
pipe = StableDiffusionUpscalePipeline.from_pretrained(
model_path,
revision="fp16",
torch_dtype=torch.float16
)
pipe = pipe.to(device)
# pipe.enable_attention_slicing()
init_img = Image.open('./yellow_cat_on_park_bench.png').convert("RGB")
init_img = init_img.resize((128, 128))
init_img.save('temp.png')
# with autocast("cuda"):
image = pipe(prompt=prompt, image=init_img).images[0]
image.save('./upscaled.png')