ming0531 commited on
Commit
4b8e782
·
verified ·
1 Parent(s): 8e99946

FlashReFocus weights (Stage I, refiner, renderer) and model card

Browse files
Files changed (4) hide show
  1. README.md +69 -0
  2. refiner.pt +3 -0
  3. renderer.pt +3 -0
  4. stage1.pkl +3 -0
README.md ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: cc-by-nc-4.0
3
+ pipeline_tag: image-to-image
4
+ tags:
5
+ - image-refocusing
6
+ - bokeh-rendering
7
+ - defocus-deblurring
8
+ - one-step-diffusion
9
+ base_model:
10
+ - sd2-community/stable-diffusion-2-1-base
11
+ ---
12
+
13
+ # FlashReFocus: Interactive Image Refocusing in Seconds
14
+
15
+ 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.
16
+
17
+ ## Files
18
+
19
+ | File | Size | Content |
20
+ |---|---|---|
21
+ | `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) |
22
+ | `refiner.pt` | 292 MB | Optional input-guided decoder refiner (decoder + fusion modules; replaces the VAE decoder) |
23
+ | `renderer.pt` | 16 MB | Stage II bokeh renderer with defocus-bias attention |
24
+
25
+ `stage1.pkl` is a pickled dictionary of state dicts (load it with `torch.load`); only load it from this repository.
26
+
27
+ ## Required base models
28
+
29
+ - Stable Diffusion 2.1 base: [`sd2-community/stable-diffusion-2-1-base`](https://huggingface.co/sd2-community/stable-diffusion-2-1-base) (Stage I)
30
+ - 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)
31
+ - Depth Anything V2 Large: [`depth-anything/Depth-Anything-V2-Large`](https://huggingface.co/depth-anything/Depth-Anything-V2-Large) (depth for the renderer)
32
+
33
+ ## Usage
34
+
35
+ Code: https://github.com/ming053l/FlashFocus
36
+
37
+ ```python
38
+ from huggingface_hub import hf_hub_download
39
+ import fast_refocus as FR # pipeline/fast_refocus.py of the code repository
40
+
41
+ stage1 = hf_hub_download("ming0531/FlashReFocus", "stage1.pkl")
42
+ refiner = hf_hub_download("ming0531/FlashReFocus", "refiner.pt")
43
+
44
+ FR.setup_backend(True)
45
+ s1 = FR.FastStageI(stage1, refiner, lambda_sem=1.25) # omega = 1.25, as in the paper
46
+ s1("input.png", "aif.png") # restore once per image
47
+
48
+ rd = FR.FastRenderer() # renderer.pt; bf16 autocast
49
+ rd.set_image("aif.png") # depth is estimated once and cached
50
+ rd.render(focus_x, focus_y, 0.5, "refocused.png") # per edit; strength in [0, 1]
51
+ ```
52
+
53
+ - `lambda_sem` (ω) trades fidelity for restored detail: 0 uses the pixel LoRA only, 1.25 is the paper setting.
54
+ - The refiner raises fidelity (text, thin edges) at about twice the Stage-I cost; pass `None` to decode with the plain VAE.
55
+ - Depth can be edited before rendering for effects such as two focal planes or tilt-shift.
56
+
57
+ ## Training data
58
+
59
+ 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.
60
+
61
+ ## Limitations
62
+
63
+ - Heavily defocused foregrounds can be over-smoothed, and weakly textured regions may receive hallucinated texture; the renderer inherits such errors.
64
+ - 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.
65
+ - Rendering depends on monocular depth; depth errors at thin structures cause blur leakage.
66
+
67
+ ## License
68
+
69
+ 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.
refiner.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5555f7ec901a40b1debbc5284e78fc6a3b823f383f404be704158011b2efef60
3
+ size 291772403
renderer.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:430a07f48c6fdf1955f18a6b0fbdad146361bbbb6857ed6f9addf72475efc361
3
+ size 16067650
stage1.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:358247a6dea5e51817d6be701dac64cbbef460dd0446332e38d69a33cd033aef
3
+ size 83087431