code: def compute_targets_for_locations(
      self, locations, targets, size_ranges, num_loc_list
  ):
      labels = []
      reg_targets = []
      target_inds = []
      xs, ys = locations[:, 0], locations[:, 1]
  
      num_targets = 0
      for im_i in range(len(targets)):
          targets_per_im = targets[im_i]
          bboxes = targets_per_im.gt_boxes.tensor
          labels_per_im = targets_per_im.gt_classes
  
          # no gt
          if bboxes.numel() == 0:
              labels.append(
                  labels_per_im.new_zeros(locations.size(0))
                  + self.num_classes
              )
              reg_targets.append(
                  locations.new_zeros((locations.size(0), 4))
              )
              target_inds.append(
                  labels_per_im.new_zeros(locations.size(0)) - 1
              )
              continue
  
          area = targets_per_im.gt_boxes.area()
  
          l = xs[:, None] - bboxes[:, 0][None]
          t = ys[:, None] - bboxes[:, 1][None]
          r = bboxes[:, 2][None] - xs[:, None]
          b = bboxes[:, 3][None] - ys[:, None]
          reg_targets_per_im = torch.stack([l, t, r, b], dim=2)
  
          if self.center_sample:
              if targets_per_im.has("gt_bitmasks_full"):
                  bitmasks = targets_per_im.gt_bitmasks_full
              else:
                  bitmasks = None
              is_in_boxes = self.get_sample_region(
                  bboxes,
                  self.strides,
                  num_loc_list,
                  xs,
                  ys,
                  bitmasks=bitmasks,
                  radius=self.radius,
              )
          else:
              is_in_boxes = reg_targets_per_im.min(dim=2)[0] > 0
  
          max_reg_targets_per_im = reg_targets_per_im.max(dim=2)[0]
          # limit the regression range for each location
          is_cared_in_the_level = (
              max_reg_targets_per_im >= size_ranges[:, [0]]
          ) & (max_reg_targets_per_im <= size_ranges[:, [1]])
  
          locations_to_gt_area = area[None].repeat(len(locations), 1)
          locations_to_gt_area[is_in_boxes == 0] = INF
          locations_to_gt_area[is_cared_in_the_level == 0] = INF
  
          # if there are still more than one objects for a location,
          # we choose the one with minimal area
          (
              locations_to_min_area,
              locations_to_gt_inds,
          ) = locations_to_gt_area.min(dim=1)
  
          reg_targets_per_im = reg_targets_per_im[
              range(len(locations)), locations_to_gt_inds
          ]
          target_inds_per_im = locations_to_gt_inds + num_targets
          num_targets += len(targets_per_im)
  
          labels_per_im = labels_per_im[locations_to_gt_inds]
          labels_per_im[locations_to_min_area == INF] = self.num_classes
  
          labels.append(labels_per_im)
          reg_targets.append(reg_targets_per_im)
          target_inds.append(target_inds_per_im)
  
      return {
          "labels": labels,
          "reg_targets": reg_targets,
          "target_inds": target_inds,
      }
  
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 5 for calling the FCOSOutputs obj's underlying member method code with example usage: obj.compute_targets_for_locations(locations, targets, size_ranges, num_loc_list) and returns: dict