ComfyUI-Grounding
ComfyUI custom nodes for open-vocabulary object detection using state-of-the-art grounding models.
Features
- GroundingDINO: Open-vocabulary object detection with natural language prompts
- YOLO-World: Real-time open-vocabulary detection
- Batch Processing: Process multiple images at once for improved efficiency
- Referring Expression Comprehension (REC): Use full text as label when no separators present
- Flexible Architecture: Support for both local and HuggingFace implementations
- Utility Nodes: Bounding box visualization and mask conversion
Supported Models
GroundingDINO (Original)
- GroundingDINO-T (SwinT backbone, 694MB)
- GroundingDINO-B (SwinB backbone, 938MB)
MM-GroundingDINO (Multimodal)
Tiny Models (Swin-T backbone):
- MM-GroundingDINO-Tiny (O365+GoldG, 50.4 mAP)
- MM-GroundingDINO-Tiny (O365+GoldG+GRIT, 50.5 mAP)
- MM-GroundingDINO-Tiny (O365+GoldG+V3Det, 50.6 mAP)
- MM-GroundingDINO-Tiny (O365+GoldG+GRIT+V3Det, 50.4 mAP)
Base Models (Swin-B backbone):
- MM-GroundingDINO-Base (O365+GoldG+V3Det, 52.5 mAP)
- MM-GroundingDINO-Base (All datasets, 59.5 mAP) ⭐ Recommended
Large Models (Swin-L backbone):
- MM-GroundingDINO-Large (O365v2+OIv6+GoldG, 53.0 mAP)
- MM-GroundingDINO-Large (All datasets, 60.3 mAP) ⭐ Best accuracy
YOLO-World
- YOLOv8s-World (small)
- YOLOv8m-World (medium)
- YOLOv8l-World (large)
- YOLOv8x-World (extra large)
Installation
- Navigate to your ComfyUI custom nodes directory:
cd ComfyUI/custom_nodes/
- Clone or copy this repository:
git clone <repository-url> ComfyUI-Grounding
- Install dependencies:
cd ComfyUI-Grounding
pip install -r requirements.txt
Nodes
1. GroundingDINOModelLoader
Loads a GroundingDINO or MM-GroundingDINO model for object detection.
Inputs:
model_name: Select from available GroundingDINO/MM-GroundingDINO modelskeep_in_memory: Cache model in memory for faster reuse (default: True)
Outputs:
model: Loaded GroundingDINO model
Features:
- ✅ Model caching - loads instantly on second use
- ✅ Local model storage in
ComfyUI-Grounding/Models/ - ✅ Supports both original and MM-GroundingDINO variants
2. GroundingDINODetector
Detects objects in images using text prompts.
Inputs:
model: GroundingDINO model (from loader)image: Input image (supports batches)prompt: Text description of objects to detect (e.g., "person . car . dog .")box_threshold: Confidence threshold for bounding boxes (0.0-1.0)text_threshold: Confidence threshold for text matching (0.0-1.0)single_box_mode: (Optional) Return only highest-scoring detection for RECoutput_format: (Optional) "list_only" (default, SAM2-compatible) or "dict_with_data"
Outputs:
bboxes: Detected bounding boxes (format depends on output_format setting)list_only: List of numpy arrays[[boxes_img0], [boxes_img1], ...]- SAM2-compatibledict_with_data: Dict{"boxes": [...], "labels": [...], "scores": [...]}
annotated_image: Image with drawn bounding boxes (batched)labels: String with detected object labels
Features:
- ✅ Batch processing - process multiple images at once
- ✅ Automatic REC mode - when prompt has no separators (. or ,), uses full text as label
- ✅ Single box mode - returns only highest-scoring detection for referring expressions
- ✅ Flexible output format - choose between SAM2-compatible list or full dict with metadata
3. YOLOWorldModelLoader
Loads a YOLO-World model for real-time detection.
Inputs:
model_name: Select from available YOLO-World modelskeep_in_memory: Cache model in memory for faster reuse (default: True)
Outputs:
model: Loaded YOLO-World model
Features:
- ✅ Model caching - loads instantly on second use
- ✅ Local model storage in
ComfyUI-Grounding/Models/ - ✅ Auto-downloads models on first use
4. YOLOWorldDetector
Detects objects using YOLO-World with custom classes.
Inputs:
model: YOLO-World model (from loader)image: Input image (supports batches)classes: Comma-separated list of classes (e.g., "person, car, dog")confidence_threshold: Minimum confidence for detections (0.0-1.0)single_box_mode: (Optional) Return only highest-scoring detection for RECoutput_format: (Optional) "list_only" (default, SAM2-compatible) or "dict_with_data"
Outputs:
bboxes: Detected bounding boxes (format depends on output_format setting)list_only: List of numpy arrays[[boxes_img0], [boxes_img1], ...]- SAM2-compatibledict_with_data: Dict{"boxes": [...], "labels": [...], "scores": [...]}
annotated_image: Image with drawn bounding boxes (batched)labels: String with detected object labels
Features:
- ✅ Batch processing - process multiple images at once
- ✅ Automatic REC mode - when classes has no comma, uses full text as label
- ✅ Single box mode - returns only highest-scoring detection for referring expressions
- ✅ Flexible output format - choose between SAM2-compatible list or full dict with metadata
5. BboxVisualizer
Draws bounding boxes on images.
Inputs:
image: Input imagebboxes: Bounding box dataline_width: Thickness of bounding box lines (optional)
Outputs:
annotated_image: Image with drawn bounding boxes
5. UnifiedDetector ⭐ NEW
Universal detector that works with BOTH GroundingDINO and YOLO-World models.
Inputs:
model: Any model (GroundingDINO or YOLO-World)image: Input imageprompt: Text prompt (supports both formats)- For GroundingDINO: "cat . dog . car ."
- For YOLO-World: "cat, dog, car"
threshold: Confidence threshold (0.0-1.0)text_threshold: Text matching threshold (optional, GroundingDINO only)
Outputs:
bboxes: Detected bounding boxes with labels and scoresannotated_image: Image with drawn bounding boxeslabels: String with detected object labels
Features:
- ✅ Auto-detects model type
- ✅ Single node for all detection models
- ✅ Simplified workflow
6. BboxToMask
Converts bounding boxes to binary masks.
Inputs:
image: Input image (for dimensions)bboxes: Bounding box datacombine_masks: Whether to combine all boxes into one mask (optional)
Outputs:
masks: Binary mask(s) for detected regions
Key Features
🚀 Model Caching
Models are cached in memory by default for instant reuse:
- First load: Downloads and initializes model
- Second load: Instant loading from cache
- Toggle
keep_in_memory=Falseto clear cache
📁 Local Model Storage
All models are downloaded to the plugin's local Models directory:
- Location:
ComfyUI/custom_nodes/ComfyUI-Grounding/Models/ - Auto-created on first use with a
models_go_here.txtplaceholder - GroundingDINO/MM-GroundingDINO: Stored in HuggingFace transformers cache format
- YOLO-World: Stored as
.ptfiles (yolov8s-world.pt, etc.)
🎯 UnifiedDetector
One detector for all models - automatically detects whether you're using GroundingDINO or YOLO-World and routes to the appropriate inference method.
📦 Batch Processing
All detector nodes support batch processing:
- Process multiple images in a single forward pass
- Input images as a batch tensor (B, H, W, C)
- Returns batched bounding boxes with lists of detections for each image
- Annotated images are returned as a single batch tensor
🎯 Referring Expression Comprehension (REC)
Automatic REC mode for natural language queries:
- GroundingDINO: If prompt has no periods (
.) or commas (,), uses full text as label- Example:
"main object in the center of the picture"→ all detections labeled with full text - With separators:
"person . car . dog ."→ uses standard noun phrase extraction
- Example:
- YOLO-World: If classes has no comma (
,), uses full text as label- Example:
"red car in the parking lot"→ all detections labeled with full text - With separators:
"person, car, dog"→ uses standard class mapping
- Example:
- Single Box Mode: Enable
single_box_modeto return only the highest-scoring detection (perfect for REC tasks)
📋 Output Formats
Detector nodes support two output formats for bounding boxes:
1. list_only (Default - SAM2 Compatible)
- Returns: List of numpy arrays, one per image in batch
- Format:
[[bbox1, bbox2], [bbox3], ...]where each bbox is[x1, y1, x2, y2] - Use when: Connecting to SAM2 segmentation nodes
- Example:
# For 2 images with 2 and 1 detections respectively [ array([[10, 20, 100, 200], [50, 60, 150, 250]]), # Image 0: 2 boxes array([[30, 40, 120, 180]]) # Image 1: 1 box ]
2. dict_with_data (Full Metadata)
- Returns: Dictionary with boxes, labels, and scores
- Format:
{"boxes": [...], "labels": [...], "scores": [...]} - Use when: Need label and confidence information for downstream processing
- NOT compatible with SAM2 (dict iteration gives keys, not values)
- Example:
{ "boxes": [array([...]), array([...])], # Boxes per image "labels": [["cat", "dog"], ["bird"]], # Labels per image "scores": [array([0.9, 0.8]), array([0.7])] # Scores per image }
Recommendation: Use list_only (default) unless you specifically need label/score metadata for your workflow.
Usage Examples
Example 1: Basic Object Detection with GroundingDINO
- Add
GroundingDINOModelLoadernode - Select model (e.g., "GroundingDINO_SwinT_OGC (694MB)")
- Add
GroundingDINODetectornode - Connect model output to detector
- Load an image and connect to detector
- Set prompt: "person . car . bicycle ."
- Adjust thresholds as needed
- View annotated image output
Example 2: YOLO-World Detection
- Add
YOLOWorldModelLoadernode - Select model (e.g., "yolov8s-world")
- Add
YOLOWorldDetectornode - Connect model and image
- Set classes: "cat, dog, bird, horse"
- Adjust confidence threshold
- View results
Example 3: Using UnifiedDetector (Recommended)
- Add any model loader (GroundingDINO or YOLO-World)
- Load your model
- Add
UnifiedDetectornode - Connect model and image
- Set prompt (works with both formats!)
- The node automatically detects model type and uses the right inference
Example 4: MM-GroundingDINO for High Accuracy
- Add
GroundingDINOModelLoadernode - Select "MM-GroundingDINO-Base (All datasets, 59.5 mAP)"
- Enable
keep_in_memory=True(default) - Add
GroundingDINODetectororUnifiedDetector - Set prompt: "specific object . another object ."
- Enjoy state-of-the-art detection accuracy!
Example 5: Convert Detections to Masks
- Use any detector node (GroundingDINO or YOLO-World)
- Add
BboxToMasknode - Connect image and bboxes outputs
- Choose whether to combine masks
- Use masks for segmentation, inpainting, etc.
Model Downloads
Models will be automatically downloaded on first use:
- All models: Stored in
ComfyUI/custom_nodes/ComfyUI-Grounding/Models/ - GroundingDINO/MM-GroundingDINO: HuggingFace transformers cache format
- YOLO-World: Direct
.ptfiles (e.g., yolov8s-world.pt)
Tips
- GroundingDINO prompts: End each object with a period (e.g., "cat . dog . car .")
- YOLO-World classes: Use comma-separated values (e.g., "cat, dog, car")
- Threshold tuning: Start with 0.3 and adjust based on results
- Lower threshold = more detections (including false positives)
- Higher threshold = fewer, more confident detections
- Performance: YOLO-World is faster but GroundingDINO may be more accurate
Integration with SAM2
These nodes work seamlessly with SAM2 for instance segmentation:
- Use GroundingDINO or YOLO-World to detect objects
- Convert bboxes to masks using
BboxToMask - Use masks with SAM2 for precise segmentation
Troubleshooting
ImportError: transformers not found
pip install transformers timm
ImportError: ultralytics not found
pip install ultralytics
Models not downloading
Check your internet connection and ensure you have write permissions to the ComfyUI models directory.
CUDA out of memory
Try using a smaller model variant (e.g., GroundingDINO-T instead of -B, or yolov8s instead of yolov8x).
License
MIT License - See LICENSE file for details
Credits
- GroundingDINO: IDEA-Research
- YOLO-World: Ultralytics
- Transformers: HuggingFace
Support
For issues and feature requests, please visit the GitHub repository.