FlashReFocus: Interactive Image Refocusing in Seconds

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

Usage

Code: https://github.com/ming053l/FlashReFocus

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.

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Model tree for ming0531/FlashReFocus

Finetuned
(3)
this model

Spaces using ming0531/FlashReFocus 2