Views
No views yet
| Metric | Value | Note |
|---|---|---|
| Speed | ~1.3 sec/image | 6 steps, T4 GPU, float16 |
| Speedup | 3.1x faster | vs v1.5 (20 steps) |
| Quality | Equivalent | Same aesthetic quality |
| Steps | 6 (LCM) | vs 20 standard |
pip install diffusers transformers torch peft1from diffusers import StableDiffusionPipeline
2from peft import PeftModel
3import torch
4
5# Load base model
6base_model_id = "runwayml/stable-diffusion-v1-5"
7adapter_id = "Shion1124/anime-character-lcm-lora"
8
9pipe = StableDiffusionPipeline.from_pretrained(
10 base_model_id,
11 torch_dtype=torch.float16,
12 device_map="auto"
13)
14
15# Load LCM-LoRA adapter
16pipe.unet = PeftModel.from_pretrained(
17 pipe.unet,
18 adapter_id,
19 adapter_name="lcm"
20)
21
22# Enable LCMScheduler for fast inference
23from diffusers import LCMScheduler
24pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config)
25
26# Generate
27prompt = "anime girl, beautiful face, masterpiece, best quality"
28image = pipe(
29 prompt=prompt,
30 num_inference_steps=6, # LCM: 4-8 steps recommended
31 guidance_scale=1.5, # LCM optimal value
32 height=512,
33 width=512
34).images[0]
35
36image.save("output.png")1# (See: https://github.com/Shion1124/anime-character-generator)
2from prompt_optimizer_v2 import RobustPromptGenerator
3
4optimizer = RobustPromptGenerator(use_google_api=True)
5robust_prompt = optimizer.optimize_prompt(
6 request="happy anime girl with long hair",
7 mode="lcm_controlnet"
8)
9
10image = pipe(
11 prompt=robust_prompt['prompt_variants'][0],
12 num_inference_steps=6,
13 guidance_scale=1.5
14).images[0]1from diffusers import (
2 StableDiffusionControlNetPipeline,
3 ControlNetModel, LCMScheduler
4)
5
6controlnet = ControlNetModel.from_pretrained(
7 "lllyasviel/sd-controlnet-lineart"
8)
9
10pipe = StableDiffusionControlNetPipeline.from_pretrained(
11 "runwayml/stable-diffusion-v1-5",
12 controlnet=controlnet,
13 torch_dtype=torch.float16,
14 device_map="auto"
15)
16
17# Load LCM + anime LoRA
18pipe.load_lora_weights(adapter_id)
19pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config)
20
21# Generate from sketch
22image = pipe(
23 prompt="anime girl, masterpiece",
24 image=sketch_image,
25 num_inference_steps=6,
26 guidance_scale=1.5,
27 controlnet_conditioning_scale=0.8
28).images[0]Input Prompt (Text)
↓
[Layer 1: CLIP Text Encoder]
↓
[Layer 2: SD v1.5 UNet + Anime LoRA]
↓
[Layer 3: LCM-LoRA Scheduler]
↓
Output Image (512×512)1@article{luo2023lcm,
2 title={LCM-LoRA: A Universal Stable-Diffusion Acceleration Module},
3 author={Luo, Simian and Sun, Yiqin and Kang, Longxiang and ...},
4 journal={arXiv preprint arXiv:2311.05556},
5 year={2023}
6}
7
8@article{gao2024robustness,
9 title={Evaluating Robustness of Text-to-Image Models},
10 author={Gao, Yiming and Chen, ...},
11 journal={arXiv preprint arXiv:2306.13103},
12 year={2024}
13}set_adapters()pip install diffusersnum_inference_steps (4-8)