-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_model_ckpt.py
34 lines (25 loc) · 1.05 KB
/
test_model_ckpt.py
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
32
33
import torch
from diffusers import StableDiffusionPipeline
# Define paths
model_ckpt_path = "./finetune-lora-dreambooth-output/dreambooth-model.ckpt"
output_dir = "./ckpt-dreambooth-output"
# Set seed for reproducibility
seed = 1337
torch.manual_seed(seed)
# Load the model checkpoint
checkpoint = torch.load(model_ckpt_path, map_location="cuda")
# Load the base model
pipe = StableDiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-2-1", torch_dtype=torch.float32)
# Load the state dict into the model
pipe.load_state_dict(checkpoint['state_dict'])
# Move the pipeline to the GPU (if available)
pipe = pipe.to("cuda")
# Define the prompt
prompt = "generate a realistic interior room design"
# Generate images
generator = torch.Generator("cuda").manual_seed(seed)
for steps in [100]:
with torch.autocast("cuda"):
image = pipe(prompt, num_inference_steps=steps, guidance_scale=7.5, generator=generator).images[0]
image.save(f"{output_dir}/generated_{steps}.png")
print("Image saved to", f"{output_dir}/generated_{steps}.png")