class_docstr: Implement FCOS in :paper:`fcos`.
class_docstr_tok: ["Implement","FCOS","in",":","paper",":","`","fcos","`","."]
code: def forward_training(
      self, images, features, predictions, gt_instances
  ):
      # Transpose the Hi*Wi*A dimension to the middle:
      (
          pred_logits,
          pred_anchor_deltas,
          pred_centerness,
      ) = self._transpose_dense_predictions(
          predictions, [self.num_classes, 4, 1]
      )
      anchors = self.anchor_generator(features)
      gt_labels, gt_boxes = self.label_anchors(anchors, gt_instances)
      return self.losses(
          anchors,
          pred_logits,
          gt_labels,
          pred_anchor_deltas,
          gt_boxes,
          pred_centerness,
      )
  
imports: import logging
  from typing import List, Optional, Tuple
  import torch
  from fvcore.nn import sigmoid_focal_loss_jit
  from torch import nn
  from torch.nn import functional
  from detectron2.layers import ShapeSpec, batched_nms
  from detectron2.structures import Boxes, ImageList, Instances, pairwise_point_box_distance
  from detectron2.utils.events import get_event_storage
  from ..anchor_generator import DefaultAnchorGenerator
  from ..backbone import Backbone
  from ..box_regression import Box2BoxTransformLinear, _dense_box_regression_loss
  from .dense_detector import DenseDetector
  from .retinanet import RetinaNetHead
label_desc: Use image node_id 2 for calling the FCOS obj's underlying member method code with example usage: obj.forward_training(images, features, predictions, gt_instances) and returns: self