docstr: Return the losses from a set of FCOS predictions and their associated ground-truth.
  
  Returns:
      dict[loss name -> loss value]: A dict mapping from loss name to loss value.
docstr_tok: ["Return","the","losses","from","a","set","of","FCOS","predictions","and","their","associated","ground-truth",".","Returns",":","dict","[","loss","name","-",">","loss","value","]",":","A","dict","mapping","from","loss","name","to","loss","value","."]
code: def losses(
      self,
      logits_pred,
      reg_pred,
      ctrness_pred,
      locations,
      gt_instances,
      top_feats=None,
  ):
      """
      Return the losses from a set of FCOS predictions and their associated ground-truth.
  
      Returns:
          dict[loss name -> loss value]: A dict mapping from loss name to loss value.
      """
  
      training_targets = self._get_ground_truth(locations, gt_instances)
  
      # Collect all logits and regression predictions over feature maps
      # and images to arrive at the same shape as the labels and targets
      # The final ordering is L, N, H, W from slowest to fastest axis.
  
      instances = Instances((0, 0))
      instances.labels = cat(
          [
              # Reshape: (N, 1, Hi, Wi) -> (N*Hi*Wi,)
              x.reshape(-1)
              for x in training_targets["labels"]
          ],
          dim=0,
      )
      instances.gt_inds = cat(
          [
              # Reshape: (N, 1, Hi, Wi) -> (N*Hi*Wi,)
              x.reshape(-1)
              for x in training_targets["target_inds"]
          ],
          dim=0,
      )
      instances.im_inds = cat(
          [x.reshape(-1) for x in training_targets["im_inds"]], dim=0
      )
      instances.reg_targets = cat(
          [
              # Reshape: (N, Hi, Wi, 4) -> (N*Hi*Wi, 4)
              x.reshape(-1, 4)
              for x in training_targets["reg_targets"]
          ],
          dim=0,
      )
      instances.locations = cat(
          [x.reshape(-1, 2) for x in training_targets["locations"]],
          dim=0,
      )
      instances.fpn_levels = cat(
          [x.reshape(-1) for x in training_targets["fpn_levels"]], dim=0
      )
  
      instances.logits_pred = cat(
          [
              # Reshape: (N, C, Hi, Wi) -> (N, Hi, Wi, C) -> (N*Hi*Wi, C)
              x.permute(0, 2, 3, 1).reshape(-1, self.num_classes)
              for x in logits_pred
          ],
          dim=0,
      )
      instances.reg_pred = cat(
          [
              # Reshape: (N, B, Hi, Wi) -> (N, Hi, Wi, B) -> (N*Hi*Wi, B)
              x.permute(0, 2, 3, 1).reshape(-1, 4)
              for x in reg_pred
          ],
          dim=0,
      )
      instances.ctrness_pred = cat(
          [
              # Reshape: (N, 1, Hi, Wi) -> (N*Hi*Wi,)
              x.permute(0, 2, 3, 1).reshape(-1)
              for x in ctrness_pred
          ],
          dim=0,
      )
  
      if len(top_feats) > 0:
          instances.top_feats = cat(
              [
                  # Reshape: (N, -1, Hi, Wi) -> (N*Hi*Wi, -1)
                  x.permute(0, 2, 3, 1).reshape(-1, x.size(1))
                  for x in top_feats
              ],
              dim=0,
          )
  
      return self.fcos_losses(instances)
  
imports: import logging
  import math
  from typing import List, Dict
  import torch
  from torch import nn
  from torch.nn import functional
  from ...nn.shape_spec import ShapeSpec
  from ...nn.deform_conv import DeformConvWithChangeableStride
  from ...nn.group_norm import NaiveGroupNorm
  from ...data.structures import Instances, Boxes
  from ...nn.focal_loss import sigmoid_focal_loss_jit
  from ...nn.nms import ml_nms
  from ...utils.loss import IOULoss
  from ...utils.comm import get_world_size, reduce_sum, compute_locations
label_desc: Use image node_id 6 for calling the FCOSOutputs obj's underlying member method code with example usage: obj.losses(logits_pred, reg_pred, ctrness_pred, locations, gt_instances, top_feats) and returns: self