File size: 2,894 Bytes
79c7c5d
 
 
 
 
 
 
 
 
 
 
 
 
 
012cfdc
79c7c5d
012cfdc
79c7c5d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
---
license: apache-2.0
pipeline_tag: image-to-image
---

# Generative Refocusing: Flexible Defocus Control from a Single Image

This model, **Generative Refocusing**, presented in the paper [Generative Refocusing: Flexible Defocus Control from a Single Image](https://huggingface.co/papers/2512.16923), offers a novel two-step process for depth-of-field control from a single image. It uses DeblurNet to recover all-in-focus images from various inputs and BokehNet for creating controllable bokeh. The method leverages semi-supervised training, combining synthetic paired data with unpaired real bokeh images, and achieves state-of-the-art performance in defocus deblurring, bokeh synthesis, and refocusing benchmarks, allowing text-guided adjustments and custom aperture shapes.

-   [Paper (Hugging Face)](https://huggingface.co/papers/2512.16923)
-   [Project Page](https://generative-refocusing.github.io/)
-   [GitHub Repository](https://github.com/rayray9999/Genfocus)
-   [Hugging Face Demo](https://huggingface.co/spaces/nycu-cplab/Genfocus-Demo)
-   [YouTube Tutorial](https://youtu.be/CMh_jGDl-RE)
  
<div align="center">
  <img src="https://github.com/rayray9999/Genfocus/raw/main/assets/demo_vid.gif" width="50%" alt="Demo Video">
</div>

---

## ⚡ Quick Start

Follow the steps below to set up the environment and run the inference demo.

### 1. Installation

Clone the repository:

```bash
git clone git@github.com:rayray9999/Genfocus.git
cd Genfocus
````

Environment setup:

```bash
conda create -n Genfocus python=3.12
conda activate Genfocus
```

Install requirements:

```bash
pip install -r requirements.txt
```

### 2. Download Weights

You can download the pre-trained models using the following commands. Ensure you are in the `Genfocus` root directory.

```bash
# 1. Download main models to the root directory
wget https://huggingface.co/nycu-cplab/Genfocus-Model/resolve/main/bokehNet.safetensors
wget https://huggingface.co/nycu-cplab/Genfocus-Model/resolve/main/deblurNet.safetensors

# 2. Setup checkpoints directory and download auxiliary model
mkdir -p checkpoints
cd checkpoints
wget https://huggingface.co/nycu-cplab/Genfocus-Model/resolve/main/checkpoints/depth_pro.pt
cd ..
```
### 3. Run Gradio Demo

Launch the interactive web interface locally:
> **Note:** The project uses [FLUX.1-dev](https://huggingface.co/black-forest-labs/FLUX.1-dev). You must request access and authenticate locally before running the demo.

```bash
python demo.py
```

The demo will be accessible at `http://127.0.0.1:7860` in your browser.

-----

## Citation

If you find this project useful for your research, please consider citing:

```bibtex
@article{Genfocus2025,
  title={Generative Refocusing: Flexible Defocus Control from a Single Image},
  author={Tuan Mu, Chun-Wei and Huang, Jia-Bin and Liu, Yu-Lun},
  journal={arXiv preprint arXiv:2512.16923},
  year={2025}
}
```