FlashReFocus / README.md
ming0531's picture
Card: fix author list in citation to match arXiv
858613b verified
|
Raw History Blame Contribute Delete
4.44 kB
---
license: cc-by-nc-4.0
pipeline_tag: image-to-image
tags:
- image-refocusing
- bokeh-rendering
- defocus-deblurring
- one-step-diffusion
base_model:
- sd2-community/stable-diffusion-2-1-base
---
# FlashReFocus: Interactive Image Refocusing in Seconds
[arXiv](https://arxiv.org/abs/2610.23297) 路 [Project page](https://ming053l.github.io/FlashReFocus/) 路 [Code](https://github.com/ming053l/FlashReFocus) 路 [Demo](https://huggingface.co/spaces/ming0531/FlashReFocus) 路 [3CReal benchmark](https://huggingface.co/datasets/ming0531/3CReal)
FlashReFocus changes the focal plane and depth of field of a single photograph after capture. A one-step latent diffusion model restores an all-in-focus (AiF) image **once**; a 1.3M-parameter renderer then produces **every** focal setting from a depth-derived defocus map, so each further edit takes about half a second at 1536脳1536.
## Files
| File | Size | Content |
|---|---|---|
| `stage1.pkl` | 83 MB | Stage I deblurrer: pixel LoRA, detail LoRA, VAE-encoder LoRA and input convolution for PiSA-SR on Stable Diffusion 2.1 (40K iterations) |
| `refiner.pt` | 292 MB | Optional input-guided decoder refiner (decoder + fusion modules; replaces the VAE decoder) |
| `renderer.pt` | 16 MB | Stage II bokeh renderer with defocus-bias attention |
`stage1.pkl` is a pickled dictionary of state dicts (load it with `torch.load`); only load it from this repository.
## Required base models
- Stable Diffusion 2.1 base: [`sd2-community/stable-diffusion-2-1-base`](https://huggingface.co/sd2-community/stable-diffusion-2-1-base) (Stage I)
- Stable Diffusion 1.5 VAE: [`stable-diffusion-v1-5/stable-diffusion-v1-5`](https://huggingface.co/stable-diffusion-v1-5/stable-diffusion-v1-5), subfolder `vae` (refiner architecture and encoder)
- Depth Anything V2 Large: [`depth-anything/Depth-Anything-V2-Large`](https://huggingface.co/depth-anything/Depth-Anything-V2-Large) (depth for the renderer)
## Usage
Code: https://github.com/ming053l/FlashReFocus
```python
from huggingface_hub import hf_hub_download
import fast_refocus as FR # pipeline/fast_refocus.py of the code repository
stage1 = hf_hub_download("ming0531/FlashReFocus", "stage1.pkl")
refiner = hf_hub_download("ming0531/FlashReFocus", "refiner.pt")
FR.setup_backend(True)
s1 = FR.FastStageI(stage1, refiner, lambda_sem=1.25) # omega = 1.25, as in the paper
s1("input.png", "aif.png") # restore once per image
rd = FR.FastRenderer() # renderer.pt; bf16 autocast
rd.set_image("aif.png") # depth is estimated once and cached
rd.render(focus_x, focus_y, 0.5, "refocused.png") # per edit; strength in [0, 1]
```
- `lambda_sem` (蠅) trades fidelity for restored detail: 0 uses the pixel LoRA only, 1.25 is the paper setting.
- The refiner raises fidelity (text, thin edges) at about twice the Stage-I cost; pass `None` to decode with the plain VAE.
- Depth can be edited before rendering for effects such as two focal planes or tilt-shift.
## Training data
Stage I: DPDD (350 pairs), filtered RealBokeh (4,179 pairs), LFDOF (11,261 pairs), and synthetic blur on 639 DIV2K images. Renderer: 59,543 synthetic Hypersim frames for pre-training and 20,554 RealBokeh pairs for adaptation.
## Limitations
- Heavily defocused foregrounds can be over-smoothed, and weakly textured regions may receive hallucinated texture; the renderer inherits such errors.
- The blur strength grows monotonically with the real aperture but is not linear in 1/N; mapping f-numbers to strengths needs a per-lens calibration.
- Rendering depends on monocular depth; depth errors at thin structures cause blur leakage.
## License
Released for **research and non-commercial use** (CC BY-NC 4.0). The weights derive from Stable Diffusion 2.1 (OpenRAIL++), PiSA-SR, and Bokehlicious, and the pipeline uses Depth Anything V2 Large (CC BY-NC 4.0); their licenses and the licenses of the training datasets also apply.
## Citation
```bibtex
@misc{cheng2026flashrefocus,
title = {{FlashReFocus}: Interactive Image Refocusing in Seconds},
author = {Cheng, Ching-Heng and Lee, Chia-Ming and Chang, Ming-Ching and
Li, Xin and Hsu, Chih-Chung},
year = {2026},
eprint = {2610.23297},
archivePrefix = {arXiv},
primaryClass = {cs.CV},
url = {https://arxiv.org/abs/2610.23297}
}
```