transformers>=4.49.0 huggingface_hub>=0.23.1 pillow bitsandbytes
This repository provides a custom ComfyUI node for running object detection with the Qwen 2.5 VL model. The node downloads the selected model on demand, runs a detection prompt and outputs bounding boxes that can be used with segmentation nodes such as SAM2.
DownloadAndLoadQwenModelDownloads a chosen Qwen 2.5-VL model into models/Qwen and returns the loaded model and processor. You can choose which device to load the model onto (e.g. cuda:1 if you have multiple GPUs), the precision for the checkpoint (INT4, INT8, BF16, FP16 or FP32) and whether to use FlashAttention or SDPA. FlashAttention is automatically replaced with SDPA when FP32 precision is selected because FlashAttention does not support it.
QwenVLDetectionRuns a detection prompt on an input image using the loaded model. The node outputs a JSON list of bounding boxes of the form {"bbox_2d": [x1, y1, x2, y2], "label": "object"} and a separate list of coordinates. Boxes are sorted by confidence and you can specify which ones to return using the bbox_selection parameter:
all – return all boxes (default)0, 1,2 or 0,2 – return only the selected boxes, sorted by detection confidencemerge_boxes – when enabled, merge the selected boxes into a single bounding boxscore_threshold – drop boxes with a confidence score below this value when availableThe bounding boxes are converted to absolute pixel coordinates so they can be passed to SAM2 nodes.
BBoxesToSAM2Wraps a list of bounding boxes into the BBOXES batch format expected by
and compatible nodes such as
ComfyUI/custom_nodes directory.cuda:1) where it should be loaded. The snapshot download will resume automatically if a previous attempt was interrupted. FlashAttention is replaced with SDPA automatically when used with FP32 precision.cat). Optionally set score_threshold to filter out low-confidence boxes, use bbox_selection to choose specific ones (e.g. 0,2) and enable merge_boxes if you want them merged. The node will automatically build the detection prompt and return the selected boxes in JSON.