discopat.nn_training.detr.criterion

DETR criterion class.

Functions

accuracy(output, target[, topk])

Compute the precision@k for the specified values of k.

Classes

SetCriterion(num_classes, matcher, ...)

Compute the loss for DETR.

class discopat.nn_training.detr.criterion.SetCriterion(num_classes, matcher, weight_dict, eos_coef, losses)[source]

Bases: Module

Compute the loss for DETR.

The process happens in two steps:
  1. we compute hungarian assignment between ground truth boxes and the outputs of the model

  2. we supervise each pair of matched ground-truth / prediction (supervise class and box)

forward(outputs, targets)[source]

Perform the loss computation.

Parameters:
  • outputs (dict of tensors, see the output specification of the model for the format)

  • targets (list of dicts, such that len(targets) == batch_size.) – The expected keys in each dict depends on the losses applied, see each loss’ doc

get_loss(loss, outputs, targets, indices, num_boxes, **kwargs)[source]
loss_boxes(outputs, targets, indices, num_boxes)[source]

Compute the losses related to the bounding boxes, the L1 regression loss and the GIoU loss.

targets dicts must contain the key “boxes” containing a tensor of dim [nb_target_boxes, 4] The target boxes are expected in format (center_x, center_y, w, h), normalized by the image size.

loss_cardinality(outputs, targets, indices, num_boxes)[source]

Compute the cardinality error, ie the absolute error in the number of predicted non-empty boxes.

This is not really a loss, it is intended for logging purposes only. It doesn’t propagate gradients

loss_labels(outputs, targets, indices, num_boxes, log=True)[source]

Classification loss (NLL).

targets dicts must contain the key “labels” containing a tensor of dim [nb_target_boxes]

discopat.nn_training.detr.criterion.accuracy(output, target, topk=(1,))[source]

Compute the precision@k for the specified values of k.