class_docstr: From DETR source: https://github.com/facebookresearch/detr
  (detr/models/detr.py)
class_docstr_tok: ["From","DETR","source",":","https",":","\/\/github.com\/facebookresearch\/detr","(","detr\/models\/detr.py",")"]
docstr: 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
docstr_tok: ["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","does","n't","propagate","gradients"]
code: def loss_cardinality(outputs, targets):
      """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
      """
  
      pred_logits = outputs["pred_logits"]
      device = pred_logits.device
      tgt_lengths = torch.as_tensor(
          [len(v["labels"]) for v in targets], device=device
      )
      card_pred = (
          pred_logits.argmax(-1) != pred_logits.shape[-1] - 1
      ).sum(1)
      card_err = torch.nn.functional.l1_loss(
          card_pred.float(), tgt_lengths.float()
      )
      losses = {"cardinality_error": card_err}
      return losses
  
imports: from typing import List, Optional, Tuple, Union
  import torch
label_desc: Use image node_id 5 for calling the SetCriterion obj's underlying member method code with example usage: obj.loss_cardinality(outputs, targets) and returns: losses