class_docstr: FoveaBox: Beyond Anchor-based Object Detector
  https://arxiv.org/abs/1904.03797
code: def loss(
      self,
      cls_scores,
      bbox_preds,
      gt_bbox_list,
      gt_label_list,
      img_metas,
      gt_bboxes_ignore=None,
  ):
      assert len(cls_scores) == len(bbox_preds)
  
      featmap_sizes = [featmap.size()[-2:] for featmap in cls_scores]
      points = self.get_points(
          featmap_sizes, bbox_preds[0].dtype, bbox_preds[0].device
      )
      num_imgs = cls_scores[0].size(0)
      flatten_cls_scores = [
          cls_score.permute(0, 2, 3, 1).reshape(
              -1, self.cls_out_channels
          )
          for cls_score in cls_scores
      ]
      flatten_bbox_preds = [
          bbox_pred.permute(0, 2, 3, 1).reshape(-1, 4)
          for bbox_pred in bbox_preds
      ]
      flatten_cls_scores = torch.cat(flatten_cls_scores)
      flatten_bbox_preds = torch.cat(flatten_bbox_preds)
      flatten_labels, flatten_bbox_targets = self.get_targets(
          gt_bbox_list, gt_label_list, featmap_sizes, points
      )
  
      # FG cat_id: [0, num_classes -1], BG cat_id: num_classes
      pos_inds = (
          ((flatten_labels >= 0) & (flatten_labels < self.num_classes))
          .nonzero()
          .view(-1)
      )
      num_pos = len(pos_inds)
  
      loss_cls = self.loss_cls(
          flatten_cls_scores,
          flatten_labels,
          avg_factor=num_pos + num_imgs,
      )
      if num_pos > 0:
          pos_bbox_preds = flatten_bbox_preds[pos_inds]
          pos_bbox_targets = flatten_bbox_targets[pos_inds]
          pos_weights = (
              pos_bbox_targets.new_zeros(pos_bbox_targets.size()) + 1.0
          )
          loss_bbox = self.loss_bbox(
              pos_bbox_preds,
              pos_bbox_targets,
              pos_weights,
              avg_factor=num_pos,
          )
      else:
          loss_bbox = torch.tensor(
              0,
              dtype=flatten_bbox_preds.dtype,
              device=flatten_bbox_preds.device,
          )
      return dict(loss_cls=loss_cls, loss_bbox=loss_bbox)
  
imports: import torch
  import torch.nn
  from mmcv.cnn import ConvModule, normal_init
  from mmcv.ops import DeformConv2d
  from mmdet.core import multi_apply, multiclass_nms
  from ..builder import HEADS
  from .anchor_free_head import AnchorFreeHead
label_desc: Use image node_id 6 for calling the FoveaHead obj's underlying member method code with example usage: obj.loss(cls_scores, bbox_preds, gt_bbox_list, gt_label_list, img_metas, gt_bboxes_ignore) and returns: dict