Implementation:NVIDIA DALI Target Assigner
| Knowledge Sources | |
|---|---|
| Domains | Object_Detection, TensorFlow |
| Last Updated | 2026-02-08 16:00 GMT |
Overview
Assigns classification and regression targets to anchor boxes by matching them against ground truth detections using configurable similarity metrics and matching strategies.
Description
The `TargetAssigner` class is the core component responsible for creating training targets for anchor-based object detection models. It operates on a single image at a time and performs a four-step pipeline: (1) computing pairwise similarity between anchors and ground truth boxes using a provided `RegionSimilarityCalculator` (typically IoU-based), (2) determining anchor-to-ground-truth matching using a `Matcher` (e.g., bipartite or argmax matching with thresholds), (3) computing regression targets by encoding matched ground truth boxes relative to their assigned anchors using a `BoxCoder`, and (4) assigning classification targets based on the match results and ground truth labels.
Unmatched anchors receive a configurable default classification target (default: [0] for background). The class computes per-anchor weights for both classification and regression losses, where unmatched anchors receive a configurable negative class weight (default: 1.0) and matched anchors inherit the weight of their matched ground truth box. Ignored anchors (those matching to neither positive nor negative) receive zero weight.
The module also provides a `batch_assign_targets` function that applies the target assigner across a batch of images, returning batched classification targets, classification weights, regression targets, regression weights, and match results.
Usage
Use this class within the EfficientDet anchor labeling pipeline to convert ground truth annotations and anchor boxes into per-anchor classification and regression targets suitable for loss computation during training.
Code Reference
Source Location
- Repository: NVIDIA_DALI
- File: docs/examples/use_cases/tensorflow/efficientdet/pipeline/anchors_utils/target_assigner.py
- Lines: 1-328
Signature
class TargetAssigner(object):
def __init__(self, similarity_calc, matcher, box_coder,
negative_class_weight=1.0, unmatched_cls_target=None): ...
@property
def box_coder(self): ...
def assign(self, anchors, groundtruth_boxes, groundtruth_labels=None,
groundtruth_weights=None, **params):
-> Tuple[cls_targets, cls_weights, reg_targets, reg_weights, match]: ...
def _create_regression_targets(self, anchors, groundtruth_boxes, match): ...
def _create_classification_targets(self, groundtruth_labels, match): ...
def _create_regression_weights(self, match, groundtruth_weights): ...
def _create_classification_weights(self, match, groundtruth_weights): ...
def batch_assign_targets(target_assigner, anchors_batch,
gt_box_batch, gt_class_targets_batch):
-> Tuple[batch_cls_targets, batch_cls_weights,
batch_reg_targets, batch_reg_weights, match_list]: ...
Import
from pipeline.anchors_utils.target_assigner import TargetAssigner, batch_assign_targets
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| anchors | BoxList | Yes | Anchor boxes represented as a BoxList with N boxes |
| groundtruth_boxes | BoxList | Yes | Ground truth boxes represented as a BoxList with M boxes |
| groundtruth_labels | tf.Tensor | No | Labels tensor of shape [M, d_1, ..., d_k]; defaults to all-ones binary labels |
| groundtruth_weights | tf.Tensor | No | Per-box weights of shape [M] in range [0, 1]; defaults to all-ones |
| similarity_calc | RegionSimilarityCalculator | Yes | Calculator for pairwise anchor-GT similarity (e.g., IoU) |
| matcher | Matcher | Yes | Strategy for matching anchors to ground truth (e.g., argmax with thresholds) |
| box_coder | BoxCoder | Yes | Encoder for computing regression targets from matched box pairs |
Outputs
| Name | Type | Description |
|---|---|---|
| cls_targets | tf.Tensor | Classification targets of shape [num_anchors, d_1, ..., d_k] |
| cls_weights | tf.Tensor | Classification weights of shape [num_anchors] |
| reg_targets | tf.Tensor | Regression targets of shape [num_anchors, box_code_dimension] |
| reg_weights | tf.Tensor | Regression weights of shape [num_anchors] |
| match | Match | Match object encoding anchor-to-ground-truth correspondence |
Usage Examples
Assign Targets to Anchors
from pipeline.anchors_utils.target_assigner import TargetAssigner
# Create target assigner with IoU similarity, argmax matcher, and box coder
assigner = TargetAssigner(
similarity_calc=iou_similarity_calculator,
matcher=argmax_matcher,
box_coder=faster_rcnn_box_coder,
negative_class_weight=1.0,
)
# Assign targets for one image
cls_targets, cls_weights, reg_targets, reg_weights, match = assigner.assign(
anchors=anchor_boxlist,
groundtruth_boxes=gt_boxlist,
groundtruth_labels=gt_labels,
)