Flux 1 In Context Learning

Source Code

Project Overview

This project adapts FLUX.1 to generate retro pixel-art characters with clean silhouettes and limited palettes. The goal was a reusable LoRA workflow for game assets and fast prototyping.

Examples

Three local examples from the workflow:

FLUX pixel art example with red hair and gray armor
pixel art character, red hair, gray armor, no weapon, facing forward
FLUX pixel art example with red hair and brown armor
pixel art character, red hair, brown armor, no weapon, facing forward
FLUX pixel art example with brown hair and blue clothing
pixel art character, brown hair, blue clothing, no weapon, facing forward

Quickstart

This is the core Diffusers setup used to load the base FLUX model and the LoRA adapter:

import torch
from diffusers import FluxPipeline

pipe = FluxPipeline.from_pretrained(
    "black-forest-labs/FLUX.1-dev",
    torch_dtype=torch.float16
).to("cuda")

pipe.load_lora_weights("milliyin/pixel_art_characters_lora_flux_nf4")

prompt = "pixel art, rpg adventurer, green cloak, clean outline, limited palette, facing forward"
image = pipe(
    prompt=prompt,
    negative_prompt="blurry, low quality, distorted, ugly",
    height=512,
    width=512,
    guidance_scale=7.5,
    num_inference_steps=50,
).images[0]

image.save("sample.png")

Prompting Tips

Non-Technical Overview

Technical Details

Data Pipeline

Model & Adapters

Objective & Scheduler

Optimizer & Precision

Latent Caching

Encoded latents are cached once with the VAE, then the VAE is freed so the rest of training can reuse those latents without repeating expensive encoding work.

Key Hyperparameters

width=512, height=512
rank=4
learning_rate=1e-4
train_batch_size=1
gradient_accumulation_steps=4
max_train_steps=700
mixed_precision=fp16
checkpointing_steps=100
guidance_scale=1.0
device=NVIDIA A100

Evaluation & Results

The biggest win here was consistency. The model stayed much closer to the intended sprite style once the prompt stayed short and the LoRA handled the style specialization.

Limitations

Plain-English Walkthrough

  1. Start from FLUX, which is the base image model.
  2. Add a small LoRA adapter that learns pixel-art rules.
  3. Feed it many labeled pixel-art characters.
  4. Let the adapter learn the recurring style patterns.
  5. Load FLUX plus the adapter later and generate new characters from short prompts.

Why It Matters

This project turns style tuning into something practical and reusable. Instead of retraining a full model, it shows how a compact LoRA can produce a consistent visual style that is actually usable for game-art style outputs and quick creative iteration.

What I Learned

This project reinforced a few practical lessons: