Model card and the original license
Browse files
NOTICE.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
The DiffuEraser weights are Apache-2.0. The pipeline also uses parts of Stable Diffusion 1.5 (its text encoder's output for the empty prompt, under the CreativeML OpenRAIL-M license) and expects a ProPainter prior (ProPainter is non-commercial, S-Lab License 1.0).
|
README.md
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
base_model: lixiaowen/diffuEraser
|
| 3 |
+
base_model_relation: quantized
|
| 4 |
+
license: apache-2.0
|
| 5 |
+
pipeline_tag: image-to-video
|
| 6 |
+
library_name: onnx
|
| 7 |
+
tags:
|
| 8 |
+
- onnx
|
| 9 |
+
- moonbox
|
| 10 |
+
- onnxruntime
|
| 11 |
+
- diffueraser
|
| 12 |
+
- video-inpainting
|
| 13 |
+
- object-removal
|
| 14 |
+
- brushnet
|
| 15 |
+
- stable-diffusion
|
| 16 |
+
---
|
| 17 |
+
|
| 18 |
+
# DiffuEraser ONNX
|
| 19 |
+
|
| 20 |
+
ONNX builds of [DiffuEraser](https://huggingface.co/lixiaowen/diffuEraser), made by Moonbox for on-device use with ONNX Runtime (CPU, CUDA, DirectML). Each
|
| 21 |
+
precision is one folder holding the graphs and a small Python `pipeline.py` that does the rest (image preprocessing,
|
| 22 |
+
the frame loop, mask handling); what the graphs take and return is under *How to run*.
|
| 23 |
+
|
| 24 |
+
## Files
|
| 25 |
+
|
| 26 |
+
The last column is the benchmark against the original PyTorch model (details under *How to run*): how closely each
|
| 27 |
+
output frame matches the original's on the same clips and masks.
|
| 28 |
+
|
| 29 |
+
| Precision | File | Size | sha256 | Benchmark |
|
| 30 |
+
|---|---|---|---|---|
|
| 31 |
+
| fp16 | [`fp16/brushnet.onnx`](https://huggingface.co/moonbox-dev/diffuEraser-ONNX/blob/main/fp16/brushnet.onnx) | 0.8 MB | `b097784e53a9` | inpainted-region PSNR vs the original: mean 57.0 / 55.0 dB, worst frame 52.4 dB; 67 / 73 s per clip (CUDA; original 44 / 47 s) |
|
| 32 |
+
| fp16 | [`fp16/brushnet.onnx.data`](https://huggingface.co/moonbox-dev/diffuEraser-ONNX/blob/main/fp16/brushnet.onnx.data) | 1.77 GB | `98ec3773cc7f` | inpainted-region PSNR vs the original: mean 57.0 / 55.0 dB, worst frame 52.4 dB; 67 / 73 s per clip (CUDA; original 44 / 47 s) |
|
| 33 |
+
| fp16 | [`fp16/pipeline.py`](https://huggingface.co/moonbox-dev/diffuEraser-ONNX/blob/main/fp16/pipeline.py) | 13.0 kB | `bae356dc2287` | inpainted-region PSNR vs the original: mean 57.0 / 55.0 dB, worst frame 52.4 dB; 67 / 73 s per clip (CUDA; original 44 / 47 s) |
|
| 34 |
+
| fp16 | [`fp16/text_embeds.npy`](https://huggingface.co/moonbox-dev/diffuEraser-ONNX/blob/main/fp16/text_embeds.npy) | 0.2 MB | `5aef4d79fd6b` | inpainted-region PSNR vs the original: mean 57.0 / 55.0 dB, worst frame 52.4 dB; 67 / 73 s per clip (CUDA; original 44 / 47 s) |
|
| 35 |
+
| fp16 | [`fp16/unet.onnx`](https://huggingface.co/moonbox-dev/diffuEraser-ONNX/blob/main/fp16/unet.onnx) | 1.8 MB | `8f36ecc2a258` | inpainted-region PSNR vs the original: mean 57.0 / 55.0 dB, worst frame 52.4 dB; 67 / 73 s per clip (CUDA; original 44 / 47 s) |
|
| 36 |
+
| fp16 | [`fp16/unet.onnx.data`](https://huggingface.co/moonbox-dev/diffuEraser-ONNX/blob/main/fp16/unet.onnx.data) | 2.63 GB | `5179ab239ca4` | inpainted-region PSNR vs the original: mean 57.0 / 55.0 dB, worst frame 52.4 dB; 67 / 73 s per clip (CUDA; original 44 / 47 s) |
|
| 37 |
+
| fp16 | [`fp16/vae_decoder.onnx`](https://huggingface.co/moonbox-dev/diffuEraser-ONNX/blob/main/fp16/vae_decoder.onnx) | 99.1 MB | `4c4e4582fc9c` | inpainted-region PSNR vs the original: mean 57.0 / 55.0 dB, worst frame 52.4 dB; 67 / 73 s per clip (CUDA; original 44 / 47 s) |
|
| 38 |
+
| fp16 | [`fp16/vae_encoder.onnx`](https://huggingface.co/moonbox-dev/diffuEraser-ONNX/blob/main/fp16/vae_encoder.onnx) | 68.4 MB | `58d65b351143` | inpainted-region PSNR vs the original: mean 57.0 / 55.0 dB, worst frame 52.4 dB; 67 / 73 s per clip (CUDA; original 44 / 47 s) |
|
| 39 |
+
|
| 40 |
+
## How to run
|
| 41 |
+
|
| 42 |
+
DiffuEraser (Alibaba Tongyi Lab: diffusion video inpainting and object removal from per-frame masks) as four ONNX graphs
|
| 43 |
+
plus `pipeline.py`, a numpy runtime that reproduces the repository's `DiffuEraser.forward` around them, with
|
| 44 |
+
`run_diffueraser.py`'s settings: the PCM 2-step LoRA, guidance 0, mask dilation 8.
|
| 45 |
+
|
| 46 |
+
DiffuEraser refines a prior: the video as a first-pass inpainter left it. The repository makes the prior with
|
| 47 |
+
ProPainter and passes it in, and so does this runtime. ProPainter's ONNX builds are at
|
| 48 |
+
[moonbox-dev/ProPainter-ONNX](https://huggingface.co/moonbox-dev/ProPainter-ONNX).
|
| 49 |
+
|
| 50 |
+
**Licences.**
|
| 51 |
+
- **DiffuEraser:** the weights are Apache-2.0.
|
| 52 |
+
- **ProPainter:** the prior model it expects is **non-commercial** (S-Lab License 1.0).
|
| 53 |
+
- **Stable Diffusion 1.5:** two parts of the pipeline come from it.
|
| 54 |
+
- `text_embeds.npy`: SD1.5's CLIP text encoder output for the empty prompt (the only prompt DiffuEraser uses), under
|
| 55 |
+
the CreativeML OpenRAIL-M license.
|
| 56 |
+
- The VAE: [sd-vae-ft-mse](https://huggingface.co/stabilityai/sd-vae-ft-mse), MIT.
|
| 57 |
+
- **PCM LoRA:** the 2-step LoRA merged into the UNet comes from
|
| 58 |
+
[wangfuyun/PCM_Weights](https://huggingface.co/wangfuyun/PCM_Weights). Its card states no licence; the PCM code
|
| 59 |
+
repository is Apache-2.0.
|
| 60 |
+
|
| 61 |
+
**The graphs.**
|
| 62 |
+
- `vae_encoder.onnx`: `image` [N, 3, H, W] in [-1, 1] -> `moments` [N, 8, H/8, W/8] (mean and log-variance;
|
| 63 |
+
`pipeline.py` samples the latent).
|
| 64 |
+
- `vae_decoder.onnx`: `latents` [N, 4, H/8, W/8], already divided by 0.18215 -> `image` [N, 3, H, W].
|
| 65 |
+
- `brushnet.onnx`: `sample` [F, 4, h, w], `timestep` [1], `text` [F, 77, 768], `cond` [F, 5, h, w] -> 28 residuals
|
| 66 |
+
(`down_0`..`down_11`, `mid`, `up_0`..`up_14`). `cond` is the masked frames' latents plus the mask.
|
| 67 |
+
- `unet.onnx`: the motion UNet with the PCM LoRA merged. It takes the same `sample`, `timestep` and `text` [1, 77, 768]
|
| 68 |
+
plus the residuals, and returns `noise` [22, 4, h, w]. It always runs on clips of 22 frames, the length the model
|
| 69 |
+
works at.
|
| 70 |
+
|
| 71 |
+
Frame sizes can be any multiple of 8.
|
| 72 |
+
|
| 73 |
+
`pipeline.py` reproduces the original's steps:
|
| 74 |
+
- **Frames:** resized so the long side is at most `max_size` (the script uses 960), both sides multiples of 8.
|
| 75 |
+
- **Masks:** eroded once, then dilated 8 times.
|
| 76 |
+
- **Priors:** the prior frames are VAE-encoded and noised.
|
| 77 |
+
- **Pre-inference:** videos over 44 frames first get a pass on 22 frames spread across them.
|
| 78 |
+
- **Denoising:** two TCD steps over windows of 22 frames that overlap by 5 (shifted windows on the second step), with
|
| 79 |
+
the original's overlap blending.
|
| 80 |
+
- **Output:** decoded and composited into the input frames through a blurred mask.
|
| 81 |
+
|
| 82 |
+
It needs numpy, scipy, onnxruntime-gpu and Pillow. OpenCV (optional) makes the mask blur match the original exactly.
|
| 83 |
+
|
| 84 |
+
```python
|
| 85 |
+
import sys
|
| 86 |
+
sys.path.insert(0, "fp16")
|
| 87 |
+
import pipeline
|
| 88 |
+
de = pipeline.DiffuEraser("fp16", "cuda")
|
| 89 |
+
# frames, masks, priors: lists of uint8 RGB arrays (masks white = remove; priors = the ProPainter output)
|
| 90 |
+
out = de(frames, masks, priors, max_size=960, seed=42)
|
| 91 |
+
```
|
| 92 |
+
|
| 93 |
+
Or from the command line: `python fp16/pipeline.py frames/ masks/ priors/ out/ --cuda`.
|
| 94 |
+
|
| 95 |
+
**Running it.**
|
| 96 |
+
- **Inputs:** at least 22 frames.
|
| 97 |
+
- **Memory:** at 640 x 352 the whole pipeline peaked at about 12.7 GB of system memory on Windows, where GPU
|
| 98 |
+
allocations count toward it. GPU memory use is in the same range.
|
| 99 |
+
- **Execution provider:** the attention runs as ONNX Runtime's `com.microsoft::MultiHeadAttention`, which uses
|
| 100 |
+
memory-efficient kernels on CUDA. Plain attention would hold 22 x 8 x (h x w)² scores per layer, 14 GB at 848 x 480.
|
| 101 |
+
CUDA is the tested path.
|
| 102 |
+
|
| 103 |
+
**Precisions.**
|
| 104 |
+
- `fp16/`: every graph fp16. BrushNet and the UNet were exported from the fp16 models, as the original runs them. The
|
| 105 |
+
VAE graphs do fp16 math with fp32 inputs / outputs.
|
| 106 |
+
- `int8/`: the BrushNet and UNet MatMuls 8-bit MatMulNBits (block 32), covering 27 % and 53 % of their weights. Their
|
| 107 |
+
convolutions stay fp16, and the VAE is as in `fp16/`.
|
| 108 |
+
- No int4: the inpainted region fell to 27 dB on one clip, against the 30 dB pass mark, to save 0.5 GB.
|
| 109 |
+
- No bf16: fp16 passes.
|
| 110 |
+
|
| 111 |
+
**Benchmark.**
|
| 112 |
+
- **Clips:** the repository's example clips 1 and 2 (70 and 80 frames, 854 x 480, 15 fps) with their masks, and the
|
| 113 |
+
prior the repository's ProPainter wrote for them.
|
| 114 |
+
- **Original:** `DiffuEraser.forward` in fp16 on CUDA, seed 42, at `max_img_size` 640 (640 x 352). The script's 960
|
| 115 |
+
needs more memory than the test machine allows.
|
| 116 |
+
- **Same draws:** every random number the original drew (initial noise, each VAE latent sample) was recorded and
|
| 117 |
+
replayed into the ONNX pipeline, so both sides see the same draws.
|
| 118 |
+
- **Score:** PSNR of every output frame against the original's, over the dilated mask, i.e. the inpainted pixels.
|
| 119 |
+
Mean over frames, and the worst frame.
|
| 120 |
+
- **Pass mark:** at least 30 dB on every frame.
|
| 121 |
+
- **Timing:** seconds per clip on an RTX 3080 Laptop GPU (16 GB), DiffuEraser only. The prior took about 20 s more.
|
| 122 |
+
|
| 123 |
+
| | inpainted region, clip 1: mean / worst | clip 2: mean / worst | seconds per clip |
|
| 124 |
+
|---|---|---|---|
|
| 125 |
+
| original (PyTorch fp16, CUDA) | - | - | 44 / 47 |
|
| 126 |
+
| `fp16/` (CUDA) | 57.0 / 52.4 dB | 55.0 / 54.1 dB | 67 / 73 |
|
| 127 |
+
| `int8/` (CUDA) | 53.9 / 48.6 dB | 49.0 / 48.0 dB | 67 / 73 |
|
| 128 |
+
|
| 129 |
+
Both builds remove the same objects as the original, and side by side their frames look the same. The ONNX runtime
|
| 130 |
+
is slower than the original on this GPU.
|
| 131 |
+
|
| 132 |
+
Before the benchmark, each graph was checked against its PyTorch module, at a frame size other than the one it was
|
| 133 |
+
exported at (848 x 480; largest absolute difference):
|
| 134 |
+
- VAE encoder: 7e-3 of 28 (float32).
|
| 135 |
+
- VAE decoder: 6e-5 of 0.57 (float32).
|
| 136 |
+
- BrushNet: 0.016 of 11.7 (fp16 against fp16).
|
| 137 |
+
- UNet: 0.009 of 5.1 (fp16 against fp16).
|
| 138 |
+
|
| 139 |
+
Running `pipeline.py`'s loop with the original PyTorch modules matches the original's frames to 58 / 56 dB.
|
| 140 |
+
|
| 141 |
+
## How these were made
|
| 142 |
+
|
| 143 |
+
From [DiffuEraser](https://huggingface.co/lixiaowen/diffuEraser) at revision `ad510dca07`. The graphs were exported from the original PyTorch modules with
|
| 144 |
+
torch.onnx (opset 17 / 18) and checked against them. Weight-only quantization: int8 is a per-output-channel int8
|
| 145 |
+
weight behind DequantizeLinear, int4 is ONNX Runtime's MatMulNBits (block 32). Each card above says which precision
|
| 146 |
+
every graph uses. Every precision was benchmarked against the original before upload (the pass mark is under *How to run*), and the
|
| 147 |
+
`sha256` column above is what the files must hash to.
|
| 148 |
+
|
| 149 |
+
## License
|
| 150 |
+
|
| 151 |
+
Apache-2.0. These files are a derivative of the original model and carry its license: it is copied in this
|
| 152 |
+
repository, and it governs your use of these files. The original model card follows unchanged.
|
| 153 |
+
|
| 154 |
+
---
|
| 155 |
+
|
| 156 |
+
# Original model card
|
| 157 |
+
|
| 158 |
+
# DiffuEraser: A Diffusion Model for Video Inpainting
|
| 159 |
+
|
| 160 |
+
DiffuEraser is a diffusion model for video inpainting, which outperforms state-of-the-art model Propainter in both content completeness and temporal consistency while maintaining acceptable efficiency.
|
| 161 |
+
|
| 162 |
+
## Model Sources
|
| 163 |
+
|
| 164 |
+
- **Project Page:** https://lixiaowen-xw.github.io/DiffuEraser-page
|
| 165 |
+
- **Repository:** https://github.com/lixiaowen-xw/DiffuEraser.git
|
| 166 |
+
- **Paper:** https://arxiv.org/abs/2501.10018
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
## Citation
|
| 170 |
+
|
| 171 |
+
**BibTeX:**
|
| 172 |
+
|
| 173 |
+
```bibtex
|
| 174 |
+
@misc{li2025diffueraserdiffusionmodelvideo,
|
| 175 |
+
title={DiffuEraser: A Diffusion Model for Video Inpainting},
|
| 176 |
+
author={Xiaowen Li and Haolan Xue and Peiran Ren and Liefeng Bo},
|
| 177 |
+
year={2025},
|
| 178 |
+
eprint={2501.10018},
|
| 179 |
+
archivePrefix={arXiv},
|
| 180 |
+
primaryClass={cs.CV},
|
| 181 |
+
url={https://arxiv.org/abs/2501.10018},
|
| 182 |
+
}
|
| 183 |
+
```
|
| 184 |
+
|
| 185 |
+
|
| 186 |
+
## Model Card Authors
|
| 187 |
+
|
| 188 |
+
Xiaowen Li / xwlxw@qq.com / lxw262398@alibaba-inc.com
|