Object Detection
Drop a DETR model into your graph
- image
- annotated_image
- detections_json
Most ComfyUI workflows are a one-way trip: prompt in, image out. This node is the opposite kind of block - it looks at the image you just made and tells you what's in it. It runs a Hugging Face object-detection model (DETR by default), draws a red bounding box around every object it finds, and hands you both the annotated image and a JSON dump of the detections. If you've ever wanted your own "workflow sanity check" that can answer "did it actually draw a cat this time," this is the tool.
It comes from kadirnar/ComfyUI-Transformers, a pack that wraps Hugging Face's transformers.pipeline() as one node per task. kadirnar is a prolific open-source ML dev with a pile of YOLO-ecosystem repos and a public ComfyUI demo Space, so the code is clean and idiomatic - but the whole pack is niche, and it shows in the polish. More on that below.
How it works
The node is a thin wrapper around pipeline("object-detection", model=model_name, trust_remote_code=True). On first run it downloads the model from the Hugging Face Hub into ~/.cache/huggingface (DETR-ResNet-50 is about 160 MB), then runs inference on the first frame of whatever IMAGE tensor you feed it, draws the boxes with PIL, and converts the result back to a ComfyUI IMAGE. The detections_json output is the raw pipeline result - every box's xmin/ymin/xmax/ymax plus label and confidence - formatted as pretty JSON.
Two things worth knowing before you wire it up:
- It only looks at frame
image[0]. If you feed it a batch, the rest is ignored. The annotated output is a single image. - There's no pipeline cache. The pack ships a cached loader in
utils.py, but these nodes don't use it - every execution rebuilds the pipeline. The weights only download once, but each run re-loads them into memory, so expect a multi-second stall per run. Annoying, not fatal.
Inputs and outputs that matter
You really only touch one input: threshold (default 0.5, range 0–1). It's the confidence cutoff - raise it to 0.7 and you'll get fewer, surer boxes; drop it toward 0.2 and the model starts hallucinating objects everywhere. model_name defaults to facebook/detr-resnet-50, and since it's a free-text string, you can drop in any HF object-detection model - a YOLOS, a Faster R-CNN, whatever fits your VRAM.
Outputs are annotated_image (an IMAGE you wire straight into a Preview/Save node) and detections_json (a STRING that needs a Show Text node to read). If you want to act on the boxes rather than just look at them, you'll be parsing that JSON.
Installing it
ComfyUI Manager works - search "ComfyUI-Transformers" and install. Or the manual route:
cd ComfyUI/custom_nodes
git clone https://github.com/kadirnar/ComfyUI-Transformers
cd ComfyUI-Transformers
pip install -r requirements.txt
Then restart ComfyUI. Two gotchas: the README's own install command says cd custom/nodes - that's a typo, and the README is otherwise nearly empty. And the requirements pull in the whole heavy stack (torch, transformers>=4.42, accelerate, opencv, pandas). transformers is one of the most conflict-prone dependencies in the shared ComfyUI Python environment - if another custom node breaks after this install, that's usually the culprit.
Common issues
- First run hangs / looks frozen. It's downloading. Watch the console for Hub progress.
- No boxes at default threshold. DETR is conservative; try 0.3–0.4.
- Model errors on
trust_remote_codewith some models - that flag is hardcoded, and a handful of Hub repos run into it.
The honest take: for a detection-first workflow (masking, cropping, re-diffusing a region), the dedicated detection packs in the ecosystem are deeper. This node is for when you want HF's model zoo without leaving your graph - and for that, it's the simplest thing on the menu.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| model_name | STRING | facebook/detr-resnet-50 | — |
| threshold | FLOAT | 0.500–1 | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| annotated_image | IMAGE | — |
| detections_json | STRING | — |