Assign Anchor→BBox
The anchor-matching step behind object detection, exposed as a node
- ground_truth
- anchors
- anchors_bbox_map
CdlAssignAnchorToBbox is the "which anchor belongs to which object" step that every anchor-based detector - think SSD, YOLO, Faster R-CNN - has to solve before it can train, but that you almost never see because it's buried inside a training script. ComfyDL digs it out and gives it a node. If you're learning object detection the "Dive into Deep Learning" way (which is exactly what this pack is), this is the moment the theory turns into a tensor you can poke at.
What it's solving
Anchor boxes are a big grid of pre-placed boxes of different sizes and aspect ratios scattered over the image. The model predicts, for each anchor, whether there's an object in it and how to adjust it. But before you can train, you need to know the answer: which ground-truth box, if any, is each anchor responsible for? That's what this node computes.
It works in two passes, straight out of d2l's assign_anchor_to_bbox:
- It builds the IoU matrix between every anchor and every ground-truth box (IoU = intersection-over-union, the standard "how much do these boxes overlap" measure). Any anchor whose best IoU is at or above
iou_thresholdgets assigned to that ground-truth box. - Then it greedily makes sure every ground-truth box still gets at least one anchor - even if the IoU fell below threshold - by locking in each ground-truth box's single best anchor. That's what stops a small object with weak overlaps from having no anchor assigned to it at all.
Inputs and output
ground_truth- acdlTensorof[N, 4]boxes in(x1, y1, x2, y2)corner format. If yours are in center-width-height form, run them through CdlBoxCenterToCorner first.anchors- thecdlTensorof anchor boxes, also[N, 4]corner format.iou_threshold- default0.5. Lower it and more anchors get assigned (looser matching); raise it and assignments tighten.
The single output, anchors_bbox_map, is a cdlTensor with one entry per anchor: the index of the ground-truth box it was assigned to, or -1 if it matched nothing. That -1 population is the background class - most anchors in real images are background, which is why training data has that huge negative-class imbalance everyone warns you about.
Where it fits
This node doesn't stand alone; it's the middle step of the detection-labeling pipeline: generate anchors with CdlMultiboxPrior, assign them with this node, then build the actual training labels with CdlMultiboxTarget. The README frames the whole pack as educational, and this is squarely one of those "now I understand why the detector works" nodes.
Installing it
It's part of the ComfyDL pack - one install, 106 nodes:
cd ComfyUI/custom_nodes
git clone https://github.com/Cynthia-lxx/ComfyDL
pip install -r ./ComfyDL/requirements.txt
Restart ComfyUI, or install "ComfyDL" through ComfyUI Manager. Only matplotlib is added beyond what ComfyUI already has.
Gotchas
- This is the textbook single-scale version of anchor assignment. Real detectors use multi-scale anchor grids and more elaborate matching (like ignoring ambiguous anchors). Don't expect this node to plug into a production YOLO pipeline - it's for understanding the concept, and that's its whole job.
- The
iou_thresholdinteracts with the greedy step: a low threshold can give an anchor multiple candidate boxes, and the greedy pass keeps the strongest assignment. Read the output as "best assignment," not "every match." cdlTensorslots only connect to other ComfyDL nodes - you can't feed it a regular image or a list of boxes from elsewhere. ComfyDL'scdlBboxtype keeps everything in[N, 4]corner format for exactly this reason.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| ground_truth | TENSOR | — | |
| anchors | TENSOR | — | |
| iou_threshold | FLOAT | 0.500–1 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| anchors_bbox_map | TENSOR | — |