Upload README.md with huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: other
|
| 3 |
+
license_name: krea-2-community-license
|
| 4 |
+
license_link: https://www.krea.ai/krea-2-licensing
|
| 5 |
+
base_model: krea/Krea-2-Raw
|
| 6 |
+
pipeline_tag: image-to-image
|
| 7 |
+
tags:
|
| 8 |
+
- controlnet
|
| 9 |
+
- lora
|
| 10 |
+
- depth
|
| 11 |
+
- krea-2
|
| 12 |
+
- flow-matching
|
| 13 |
+
---
|
| 14 |
+
|
| 15 |
+
# Krea-2 Depth ControlNet-LoRA
|
| 16 |
+
|
| 17 |
+
Depth-conditioned generation for [Krea-2](https://github.com/krea-ai/krea-2). Give it any image and a prompt β it extracts the depth map with Depth-Anything-V2 and generates a new image with the **same 3D structure** and composition, but whatever content and style you ask for.
|
| 18 |
+
|
| 19 |
+
- Trained on **Krea-2-Raw**, works on both **Raw** and **Krea-2-Turbo** (8-step)
|
| 20 |
+
- Single 862MB LoRA file (rank 64 + expanded input projection), base stays frozen
|
| 21 |
+
- Depth consistency (Pearson corr. of input depth vs. depth of generated image): **0.98** with no prompt, **0.99** with prompts
|
| 22 |
+
|
| 23 |
+
| turbo (8 steps) | raw (28 steps, cfg 3.5) |
|
| 24 |
+
|---|---|
|
| 25 |
+
|  |  |
|
| 26 |
+
|
| 27 |
+
*Each strip: init image β extracted depth β generated output.*
|
| 28 |
+
|
| 29 |
+
## Checkpoint
|
| 30 |
+
|
| 31 |
+
| file | base trained on | size |
|
| 32 |
+
|---|---|---|
|
| 33 |
+
| [`depth-control-lora.safetensors`](https://huggingface.co/Patil/Krea-2-controlnet/blob/main/depth-control-lora.safetensors) | krea/Krea-2-Raw | 862MB |
|
| 34 |
+
|
| 35 |
+
## Setup
|
| 36 |
+
|
| 37 |
+
```bash
|
| 38 |
+
git clone https://github.com/Tanmaypatil123/Krea-2-controlnet.git
|
| 39 |
+
cd Krea-2-controlnet
|
| 40 |
+
pip install -r requirements.txt
|
| 41 |
+
|
| 42 |
+
hf download Patil/Krea-2-controlnet depth-control-lora.safetensors --local-dir .
|
| 43 |
+
```
|
| 44 |
+
|
| 45 |
+
Requires one GPU with **β₯48GB VRAM** (A100-80 / H100 / B200): 13B DiT in bf16 (26GB) + Qwen3-VL-4B text encoder (8GB) + VAE + Depth-Anything-V2. The Krea-2 base checkpoint (26GB) and auxiliary models download automatically from HF on first run.
|
| 46 |
+
|
| 47 |
+
## Inference
|
| 48 |
+
|
| 49 |
+
```bash
|
| 50 |
+
# Turbo base β fast, recommended (8 steps, no CFG)
|
| 51 |
+
python inference.py photo.jpg -p "a futuristic spaceship interior, cinematic lighting" \
|
| 52 |
+
--lora depth-control-lora.safetensors
|
| 53 |
+
|
| 54 |
+
# Raw base β undistilled (28-52 steps, CFG 3.5)
|
| 55 |
+
python inference.py photo.jpg -p "..." --lora depth-control-lora.safetensors \
|
| 56 |
+
--base raw
|
| 57 |
+
|
| 58 |
+
# No prompt: the depth map is the only signal
|
| 59 |
+
python inference.py photo.jpg --lora depth-control-lora.safetensors --save-strip
|
| 60 |
+
|
| 61 |
+
# Weaker structure adherence (more creative freedom)
|
| 62 |
+
python inference.py photo.jpg -p "..." --lora depth-control-lora.safetensors --lora-scale 0.6
|
| 63 |
+
```
|
| 64 |
+
|
| 65 |
+
| flag | default | notes |
|
| 66 |
+
|---|---|---|
|
| 67 |
+
| `-p / --prompt` | `""` | empty = depth-only generation |
|
| 68 |
+
| `--base` | `turbo` | `turbo` or `raw` |
|
| 69 |
+
| `--steps` | 8 turbo / 28 raw | |
|
| 70 |
+
| `--cfg` | 0 turbo / 3.5 raw | classifier-free guidance |
|
| 71 |
+
| `--mu` | 1.15 turbo / auto raw | timestep shift |
|
| 72 |
+
| `--lora-scale` | 1.0 | control-strength dial |
|
| 73 |
+
| `--seed` | 0 | |
|
| 74 |
+
| `--save-strip` | off | also saves input\|depth\|output comparison |
|
| 75 |
+
|
| 76 |
+
### Python API
|
| 77 |
+
|
| 78 |
+
```python
|
| 79 |
+
from PIL import Image
|
| 80 |
+
from huggingface_hub import hf_hub_download
|
| 81 |
+
from pipeline import DepthLoRAPipeline
|
| 82 |
+
|
| 83 |
+
base = hf_hub_download("krea/Krea-2-Turbo", "turbo.safetensors")
|
| 84 |
+
pipe = DepthLoRAPipeline(base, "depth-control-lora.safetensors")
|
| 85 |
+
|
| 86 |
+
out, depth = pipe(Image.open("photo.jpg"),
|
| 87 |
+
prompt="a cozy cabin interior at dusk",
|
| 88 |
+
steps=8, cfg=0.0, mu=1.15, seed=0)
|
| 89 |
+
out.save("output.png")
|
| 90 |
+
```
|
| 91 |
+
|
| 92 |
+
## How it works (inference path)
|
| 93 |
+
|
| 94 |
+
1. The init image is resized to the nearest ~1MP aspect bucket and run through **Depth-Anything-V2-Large** β inverse depth map (near = white).
|
| 95 |
+
2. The depth map is encoded with the same **Qwen-Image VAE** the model uses for images, so control lives in latent space.
|
| 96 |
+
3. At every denoising step, the depth latent is **concatenated channel-wise** to the noisy latent (each DiT token: 64 β 128 dims). The expanded input projection + rank-64 LoRA on all 28 blocks (both included in the checkpoint) steer generation to follow the depth structure.
|
| 97 |
+
4. Standard Krea-2 flow-matching Euler sampling otherwise β same recipe as BFL's Flux.1-Depth-dev-lora.
|
| 98 |
+
|
| 99 |
+
## Tips & limitations
|
| 100 |
+
|
| 101 |
+
- **Best inputs**: photos / renders with real perspective. Flat 2D illustrations produce nearly-uniform depth maps, so control will be weak (garbage in, garbage out).
|
| 102 |
+
- Empty-prompt generation works (0.98 depth consistency) β useful for testing how much structure the control alone carries.
|
| 103 |
+
- `--lora-scale` below 1.0 relaxes structure adherence; above 1.0 tightens it at some quality cost.
|
| 104 |
+
- Krea-2-Raw generates up to ~1K resolution; outputs are capped at the ~1MP buckets.
|
| 105 |
+
|
| 106 |
+
## Files
|
| 107 |
+
|
| 108 |
+
- `inference.py` β CLI
|
| 109 |
+
- `pipeline.py` β full pipeline: LoRA surgery, Qwen3-VL conditioner, VAE, depth estimator, flow sampler with control injection
|
| 110 |
+
- `mmdit.py` β unmodified DiT definition from the [krea-2 repo](https://github.com/krea-ai/krea-2)
|
| 111 |
+
|
| 112 |
+
Model weights are subject to the [Krea 2 community license](https://www.krea.ai/krea-2-licensing). Training code will be released separately.
|