The Vision: Open Alternative to Proprietary Generators
While proprietary models like Midjourney and DALL-E deliver high fidelity, they operate inside walled gardens with closed APIs and costly inference tiers. We explored whether open-source diffusion models could produce high-artistry Ghibli-style aesthetic conversions with strict adherence to input pose and structural composition.
The resulting pipeline utilizes Latent Diffusion Models (LDM) augmented with ControlNet edge-conditioning to preserve semantic contours while repainting textures in hand-drawn anime aesthetic.
Conditioning & Latent Inversion
Direct image-to-image prompts often suffer from loss of fine identity contours or over-smoothing. To solve this, our pipeline deploys a multi-conditioning stack:
- Canny Edge & Depth Conditioning: Extracts line art boundaries and depth maps to anchor geometry and spatial relationships.
- LoRA Weight Merging: Dynamically loads low-rank adaptation weights trained specifically on classical animation film stills.
- Classifier-Free Guidance (CFG): Balances prompt alignment against structural adherence to avoid hallucinated artifacts.
Inference Pipeline Code Sample
Here is an overview of the core diffusers pipeline invocation configured with ControlNet conditioning:
from diffusers import StableDiffusionControlNetPipeline, ControlNetModel
import torch
from PIL import Image
# Load ControlNet conditioned on canny edge contours
controlnet = ControlNetModel.from_pretrained(
"lllyasviel/sd-controlnet-canny",
torch_dtype=torch.float16
)
pipeline = StableDiffusionControlNetPipeline.from_pretrained(
"runwayml/stable-diffusion-v1-5",
controlnet=controlnet,
torch_dtype=torch.float16
).to("cuda")
# Enable memory-efficient attention
pipeline.enable_xformers_memory_efficient_attention()
def generate_ghibli_style(image: Image.Image, prompt: str):
output = pipeline(
prompt=f"{prompt}, studio ghibli anime aesthetic, masterpiece, high detail",
negative_prompt="blurry, photographic, low quality, distorted",
image=image,
num_inference_steps=28,
guidance_scale=8.0
).images[0]
return outputResults and Latency Benchmarks
With FlashAttention and TensorRT optimization, 512x512 image generation times were reduced to approximately 1.4 seconds on an NVIDIA RTX 4090. The open-source model achieved remarkable tonal accuracy, capturing the pastel warmth characteristic of classical Japanese animation.
