discopat.nn_training.detr.matcher

Compute the matching cost and solve the corresponding LSAP.

Classes

HungarianMatcher([cost_class, cost_bbox, ...])

Compute an assignment between the targets and the predictions of the network.

class discopat.nn_training.detr.matcher.HungarianMatcher(cost_class=1, cost_bbox=1, cost_giou=1)[source]

Bases: Module

Compute an assignment between the targets and the predictions of the network.

For efficiency reasons, the targets don’t include the no_object. Because of this, in general, there are more predictions than targets. In this case, we do a 1-to-1 matching of the best predictions, while the others are un-matched (and thus treated as non-objects).

Parameters:
  • cost_class (float)

  • cost_bbox (float)

  • cost_giou (float)

forward(outputs, targets)[source]

Perform the matching.

Params:
outputs: This is a dict that contains at least these entries:

“pred_logits”: Tensor of dim [batch_size, num_queries, num_classes] with the classification logits “pred_boxes”: Tensor of dim [batch_size, num_queries, 4] with the predicted box coordinates

targets: This is a list of targets (len(targets) = batch_size), where each target is a dict containing:
“labels”: Tensor of dim [num_target_boxes] (where num_target_boxes is the number of ground-truth

objects in the target) containing the class labels

“boxes”: Tensor of dim [num_target_boxes, 4] containing the target box coordinates

Returns:

  • index_i is the indices of the selected predictions (in order)
    • index_j is the indices of the corresponding selected targets (in order)

For each batch element, it holds:

len(index_i) = len(index_j) = min(num_queries, num_target_boxes)

Return type:

A list of size batch_size, containing tuples of (index_i, index_j) where