class_docstr: Implement FCOS in :paper:`fcos`.
class_docstr_tok: ["Implement","FCOS","in",":","paper",":","`","fcos","`","."]
docstr: Args:
      center_sampling_radius: radius of the "center" of a groundtruth box,
          within which all anchor points are labeled positive.
      Other arguments mean the same as in :class:`RetinaNet`.
docstr_tok: ["Args",":","center_sampling_radius",":","radius","of","the","``","center","''","of","a","groundtruth","box",",","within","which","all","anchor","points","are","labeled","positive",".","Other","arguments","mean","the","same","as","in",":","class",":","`","RetinaNet","`","."]
code: def __init__(
      self,
      *,
      backbone: Backbone,
      head: nn.Module,
      head_in_features: Optional[List[str]] = None,
      box2box_transform=None,
      num_classes,
      center_sampling_radius: float = 1.5,
      focal_loss_alpha=0.25,
      focal_loss_gamma=2.0,
      test_score_thresh=0.2,
      test_topk_candidates=1000,
      test_nms_thresh=0.6,
      max_detections_per_image=100,
      pixel_mean,
      pixel_std,
  ):
      """
      Args:
          center_sampling_radius: radius of the "center" of a groundtruth box,
              within which all anchor points are labeled positive.
          Other arguments mean the same as in :class:`RetinaNet`.
      """
      super().__init__(
          backbone,
          head,
          head_in_features,
          pixel_mean=pixel_mean,
          pixel_std=pixel_std,
      )
  
      self.num_classes = num_classes
  
      # FCOS uses one anchor point per location.
      # We represent the anchor point by a box whose size equals the anchor stride.
      feature_shapes = backbone.output_shape()
      fpn_strides = [
          feature_shapes[k].stride for k in self.head_in_features
      ]
      self.anchor_generator = DefaultAnchorGenerator(
          sizes=[[k] for k in fpn_strides],
          aspect_ratios=[1.0],
          strides=fpn_strides,
      )
  
      # FCOS parameterizes box regression by a linear transform,
      # where predictions are normalized by anchor stride (equal to anchor size).
      if box2box_transform is None:
          box2box_transform = Box2BoxTransformLinear(
              normalize_by_size=True
          )
      self.box2box_transform = box2box_transform
  
      self.center_sampling_radius = float(center_sampling_radius)
  
      # Loss parameters:
      self.focal_loss_alpha = focal_loss_alpha
      self.focal_loss_gamma = focal_loss_gamma
  
      # Inference parameters:
      self.test_score_thresh = test_score_thresh
      self.test_topk_candidates = test_topk_candidates
      self.test_nms_thresh = test_nms_thresh
      self.max_detections_per_image = max_detections_per_image
  
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 1 to create a new FCOS object from inherited base classes: DenseDetector with example: obj = FCOS()