|
from diffusers import DiffusionPipeline |
|
import torch |
|
from PIL import Image |
|
|
|
|
|
def test_lora(lcm_speedup=False): |
|
pipe = DiffusionPipeline.from_pretrained("/mnt/workspace/Project/VideoGen/ckpt/stable-diffusion-v1-5", torch_dtype=torch.float16, safety_checker = None, requires_safety_checker=False) |
|
pipe.to("cuda") |
|
|
|
lora_path = "/mnt/workspace/Project/VideoGen/TrainT2V/diffusers/examples/text_to_image/results" |
|
pipe.load_lora_weights(pretrained_model_name_or_path_or_dict=lora_path, weight_name="artifacts_100epoch_lora.safetensors", adapter_name="pattern") |
|
if lcm_speedup: |
|
pipe.load_lora_weights(pretrained_model_name_or_path_or_dict=lora_path, weight_name="lcm_lora.safetensors", adapter_name="lcm") |
|
pipe.set_adapters(["artifacts", "lcm"], adapter_weights=[1.0, 1.0]) |
|
|
|
prompts = [ |
|
|
|
|
|
"A captivating intricately patterned ceramic vessel illuminated by a soft inner light, showcasing an elegant array of flowing curves and organic shapes. Crafted from delicate porcelain, its minimalist yet complex design evokes a sense of serenity. The interplay of light and shadow accentuates its textures and fine lines, symbolizing traditional artistry merged with modern aesthetics. This artifact, although not explicitly marked with age, exudes a timeless elegance reflective of master craftsmanship.", |
|
"Ancient Bronze Sword Guard: This intricately carved sword guard is a masterpiece of Chinese craftsmanship from the Western Zhou period, dating back to around 900 BCE. The green patina of oxidized bronze is a testament to its age. The guard is adorned with delicate spiral and interlocking patterns, symbolizing both beauty and power. The ornate design not only protects the blade but also showcases the artistry of its time, reflecting the society's high regard for elegance and strength. Today, it stands as a historical relic, silently narrating tales of a bygone era." |
|
] |
|
|
|
|
|
if lcm_speedup: |
|
num_inference_steps = 8 |
|
guidance_scale = 2 |
|
else: |
|
num_inference_steps = 30 |
|
guidance_scale = 7.5 |
|
|
|
num_samples_per_prompt = 3 |
|
|
|
|
|
all_images = [] |
|
|
|
|
|
for prompt in prompts: |
|
images = pipe(prompt, num_inference_steps=num_inference_steps, guidance_scale=guidance_scale, num_images_per_prompt=num_samples_per_prompt).images |
|
all_images.extend(images) |
|
|
|
|
|
grid_image = Image.new('RGB', (3 * 512, 2 * 512)) |
|
for idx, img in enumerate(all_images): |
|
x = (idx % 3) * 512 |
|
y = (idx // 3) * 512 |
|
grid_image.paste(img, (x, y)) |
|
|
|
|
|
n = 4 if lcm_speedup else 30 |
|
grid_image.save(f"test_lora_grid_{n}_steps.png") |
|
|
|
|
|
if __name__ == "__main__": |
|
test_lora() |