ComfyUI Extension: ComfyUI-D-DFFNet

Authored by MoRanYue

Created

Updated

0 stars

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.

Looking for a different extension?

Custom Nodes (1)

README

ComfyUI-D-DFFNet

License PyTorch

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

  1. Navigate to your ComfyUI custom_nodes directory:

    cd ComfyUI/custom_nodes/
    
  2. Clone this repository:

    git clone https://github.com/your-username/ComfyUI-D-DFFNet.git
    
  3. 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 |

  4. 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

  1. Add Load ImageD-DFFNet Defocus Blur DetectionPreview Mask
  2. Select your pretrained model in the model_name dropdown
  3. Adjust threshold if needed (default: 0.5)
  4. 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-side8 warnings 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

License

This project is licensed under the MIT License. The original D-DFFNet model code is from yuxinjin-whu/D-DFFNet.

Acknowledgements

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.

Learn more