class_docstr: Implement FCOS (https://arxiv.org/abs/1904.01355).
class_docstr_tok: ["Implement","FCOS","(","https",":","\/\/arxiv.org\/abs\/1904.01355",")","."]
docstr: Arguments:
      images (list[Tensor] or ImageList): images to be processed
      targets (list[BoxList]): ground-truth boxes present in the image (optional)
  
  Returns:
      result (list[BoxList] or dict[Tensor]): the output from the model.
          During training, it returns a dict[Tensor] which contains the losses.
          During testing, it returns list[BoxList] contains additional fields
          like `scores`, `labels` and `mask` (for Mask R-CNN models).
docstr_tok: ["Arguments",":","images","(","list","[","Tensor","]","or","ImageList",")",":","images","to","be","processed","targets","(","list","[","BoxList","]",")",":","ground-truth","boxes","present","in","the","image","(","optional",")","Returns",":","result","(","list","[","BoxList","]","or","dict","[","Tensor","]",")",":","the","output","from","the","model",".","During","training",",","it","returns","a","dict","[","Tensor","]","which","contains","the","losses",".","During","testing",",","it","returns","list","[","BoxList","]","contains","additional","fields","like","`","scores","`",",","`","labels","`","and","`","mask","`","(","for","Mask","R-CNN","models",")","."]
code: def forward(
      self, images, features, gt_instances=None, top_module=None
  ):
      """
      Arguments:
          images (list[Tensor] or ImageList): images to be processed
          targets (list[BoxList]): ground-truth boxes present in the image (optional)
  
      Returns:
          result (list[BoxList] or dict[Tensor]): the output from the model.
              During training, it returns a dict[Tensor] which contains the losses.
              During testing, it returns list[BoxList] contains additional fields
              like `scores`, `labels` and `mask` (for Mask R-CNN models).
  
      """
      features = [features[f] for f in self.in_features]
      locations = self.compute_locations(features)
      (
          logits_pred,
          reg_pred,
          ctrness_pred,
          top_feats,
          bbox_towers,
      ) = self.fcos_head(features, top_module, self.yield_proposal)
  
      results = {}
      if self.yield_proposal:
          results["features"] = {
              f: b for f, b in zip(self.in_features, bbox_towers)
          }
  
      if self.training:
          results, losses = self.fcos_outputs.losses(
              logits_pred,
              reg_pred,
              ctrness_pred,
              locations,
              gt_instances,
              top_feats,
          )
  
          if self.yield_proposal:
              with torch.no_grad():
                  results[
                      "proposals"
                  ] = self.fcos_outputs.predict_proposals(
                      logits_pred,
                      reg_pred,
                      ctrness_pred,
                      locations,
                      images.image_sizes,
                      top_feats,
                  )
          return results, losses
      else:
          results = self.fcos_outputs.predict_proposals(
              logits_pred,
              reg_pred,
              ctrness_pred,
              locations,
              images.image_sizes,
              top_feats,
          )
  
          return results, {}
  
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 3 for calling the FCOS obj's underlying member method code with example usage: obj.forward(images, features, gt_instances, top_module) and returns: results,  losses, results,  dict