class_docstr: Implement FCOS in :paper:`fcos`.
class_docstr_tok: ["Implement","FCOS","in",":","paper",":","`","fcos","`","."]
docstr: Same interface as :meth:`RetinaNet.label_anchors`, but implemented with FCOS
  anchor matching rule.
  
  Unlike RetinaNet, there are no ignored anchors.
docstr_tok: ["Same","interface","as",":","meth",":","`","RetinaNet.label_anchors","`",",","but","implemented","with","FCOS","anchor","matching","rule",".","Unlike","RetinaNet",",","there","are","no","ignored","anchors","."]
code: def label_anchors(
      self, anchors: List[Boxes], gt_instances: List[Instances]
  ):
      """
      Same interface as :meth:`RetinaNet.label_anchors`, but implemented with FCOS
      anchor matching rule.
  
      Unlike RetinaNet, there are no ignored anchors.
      """
  
      gt_labels, matched_gt_boxes = [], []
  
      for inst in gt_instances:
          if len(inst) > 0:
              match_quality_matrix = self._match_anchors(
                  inst.gt_boxes, anchors
              )
  
              # Find matched ground-truth box per anchor. Un-matched anchors are
              # assigned -1. This is equivalent to using an anchor matcher as used
              # in R-CNN/RetinaNet: `Matcher(thresholds=[1e-5], labels=[0, 1])`
              match_quality, matched_idxs = match_quality_matrix.max(
                  dim=0
              )
              matched_idxs[match_quality < 1e-5] = -1
  
              matched_gt_boxes_i = inst.gt_boxes.tensor[
                  matched_idxs.clip(min=0)
              ]
              gt_labels_i = inst.gt_classes[matched_idxs.clip(min=0)]
  
              # Anchors with matched_idxs = -1 are labeled background.
              gt_labels_i[matched_idxs < 0] = self.num_classes
          else:
              matched_gt_boxes_i = torch.zeros_like(
                  Boxes.cat(anchors).tensor
              )
              gt_labels_i = torch.full(
                  (len(matched_gt_boxes_i),),
                  fill_value=self.num_classes,
                  dtype=torch.long,
                  device=matched_gt_boxes_i.device,
              )
  
          gt_labels.append(gt_labels_i)
          matched_gt_boxes.append(matched_gt_boxes_i)
  
      return gt_labels, matched_gt_boxes
  
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 4 for calling the FCOS obj's underlying member method code with example usage: obj.label_anchors(anchors, gt_instances) and returns: gt_labels,  matched_gt_boxes