forked from william-murray1204/stable-diffusion-cpp-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_upscale.py
More file actions
31 lines (20 loc) · 803 Bytes
/
test_upscale.py
File metadata and controls
31 lines (20 loc) · 803 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
30
31
import os
import traceback
from stable_diffusion_cpp import StableDiffusion
UPSCALER_MODEL_PATH = "C:\\stable-diffusion\\RealESRGAN_x4plus.pth"
input_images = ["assets\\input.png"]
stable_diffusion = StableDiffusion(upscaler_path=UPSCALER_MODEL_PATH)
def callback(step: int, steps: int, time: float):
print("Completed step: {} of {}".format(step, steps))
try:
# Upscale images
images = stable_diffusion.upscale(images=input_images, upscale_factor=2, progress_callback=callback)
OUTPUT_DIR = "tests/outputs"
if not os.path.exists(OUTPUT_DIR):
os.makedirs(OUTPUT_DIR)
# Save images
for i, image in enumerate(images):
image.save(f"{OUTPUT_DIR}/upscale_{i}.png")
except Exception as e:
traceback.print_exc()
print("Test - upscale failed: ", e)