ComfyUI Extension: ComfyUI-D-DFFNet
Run ComfyUI workflows without the setup
No installs, no CUDA version roulette, no GPU sitting idle on your bill. Bring a workflow and run it in the browser.
Defocus Blur Detection Custom Node for ComfyUI wrapping D-DFFNet model detecting out-of-focus areas.
README
ComfyUI-D-DFFNet
Defocus Blur Detection Custom Node for ComfyUI.
This node wraps the D-DFFNet model from the paper "Depth and DOF Cues Make A Better Defocus Blur Detector" (ICME 2023) by Jin et al. It detects defocus blur regions (out-of-focus areas) in images.
D-DFFNet leverages depth prior knowledge learned via knowledge distillation from MiDaS, achieving state-of-the-art performance on DUT, CUHK, and CTCUG benchmarks.
Features
- D-DFFNet - Full model with depth-aware features
- DFFNet-compatible - Also supports the base DFFNet weights (without depth side outputs)
- PyTorch 2.x - Fully compatible with PyTorch 2.0+
- GPU/CPU - Automatic device selection via ComfyUI's model management
- Batch support - Process multiple images simultaneously
Installation
-
Navigate to your ComfyUI
custom_nodesdirectory:cd ComfyUI/custom_nodes/ -
Clone this repository:
git clone https://github.com/your-username/ComfyUI-D-DFFNet.git -
Download the pretrained model weights and place them in
ComfyUI/models/dffnet/:mkdir -p ComfyUI/models/dffnet/| Model | Training Data | Download Link | |-------|---------------|---------------| | D-DFFNet | CUHK-TR-2 & DUT-TR | Link | | D-DFFNet | CUHK-TR-1 & DUT-TR | Link | | D-DFFNet | CUHK-TR-1 | Link | | DFFNet | CUHK-TR-2 & DUT-TR | Link | | DFFNet | CUHK-TR-1 & DUT-TR | Link | | DFFNet | CUHK-TR-1 | Link |
-
Restart ComfyUI. The node will appear in the node menu under
D-DFFNet.
Usage
Node: D-DFFNet Defocus Blur Detection
| Input | Type | Description |
|-------|------|-------------|
| image | IMAGE | Input image batch (BHWC, float32, [0,1]) |
| model_name | Combo | Select from available .pth files in models/dffnet/ |
| threshold | FLOAT | (Optional) Binarization threshold. 0 = raw probability output |
| Output | Type | Description |
|--------|------|-------------|
| mask | MASK | Defocus blur detection mask (BHW, float32, [0,1]) |
Workflow Example
- Add
Load Image→D-DFFNet Defocus Blur Detection→Preview Mask - Select your pretrained model in the
model_namedropdown - Adjust
thresholdif needed (default: 0.5) - Queue the workflow
Model Notes
- D-DFFNet weights (recommended): Contain depth side outputs from knowledge distillation
- DFFNet weights: Compatible but will show
Missing keys: agg1.side5-side8warnings in console — these are harmless and do not affect inference quality - All models accept 320×320 input (automatically resized) and output at original resolution
Architecture
Input Image (RGB)
│
▼
ResNeSt-101 Backbone
│
├── layer1 (256ch, 1/4 scale)
├── layer2 (512ch, 1/8 scale)
├── layer3_1 (1024ch, 1/16 scale)
└── layer4_1 (2048ch, 1/32 scale)
│
▼
RFB Modules (×4) ── Multi-scale feature extraction
│
▼
Aggregation Module ── 4-level fusion + Spatial Attention
│
▼
1×1 Conv → Sigmoid → Output Mask
Requirements
- ComfyUI
- PyTorch ≥ 2.0
- numpy
License
This project is licensed under the MIT License. The original D-DFFNet model code is from yuxinjin-whu/D-DFFNet.
Acknowledgements
- Original D-DFFNet implementation: yuxinjin-whu/D-DFFNet
- MiDaS depth estimation: isl-org/MiDaS
- ResNeSt backbone: zhanghang1989/ResNeSt
Run ComfyUI workflows without the setup
No installs, no CUDA version roulette, no GPU sitting idle on your bill. Bring a workflow and run it in the browser.