code: def compute_targets_for_locations(
      self, locations, targets, size_ranges, num_loc_list, images=None
  ):
      labels = []
      bbox_reg_targets = []
      kpt_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
              )
              bbox_reg_targets.append(
                  locations.new_zeros((locations.size(0), 4))
              )
              kpt_reg_targets.append(
                  locations.new_zeros(
                      (locations.size(0), self.num_kpts, 3)
                  )
              )
              target_inds.append(
                  labels_per_im.new_zeros(locations.size(0)) - 1
              )
              continue
  
          area = targets_per_im.gt_boxes.area()
          kpts = targets_per_im.gt_keypoints.tensor
  
          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)
  
          kpt_x_offset = kpts[:, :, 0][None] - xs[:, None, None]
          kpt_y_offset = kpts[:, :, 1][None] - ys[:, None, None]
          kpt_vis = kpts[:, :, 2][None].expand(len(locations), -1, -1)
          kpt_reg_targets_per_im = torch.stack(
              [kpt_x_offset, kpt_y_offset, kpt_vis], dim=3
          )
          kpt_reg_targets_per_im[kpt_vis == 0] = 0
  
          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
          ]
          kpt_reg_targets_per_im = kpt_reg_targets_per_im[
              range(len(locations)), locations_to_gt_inds
          ]
          target_inds_per_im = locations_to_gt_inds + num_targets
          num_targets += len(bboxes)
  
          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)
          bbox_reg_targets.append(reg_targets_per_im)
          kpt_reg_targets.append(kpt_reg_targets_per_im)
          target_inds.append(target_inds_per_im)
  
      return {
          "labels": labels,
          "bbox_reg_targets": bbox_reg_targets,
          "kpt_reg_targets": kpt_reg_targets,
          "target_inds": target_inds,
      }
  
imports: import logging
  import os
  from typing import List
  import numpy
  import torch
  from torch import nn
  import torch.nn.functional
  from torchvision.ops import nms
  from ...data.structures import Instances, Boxes
  from ...utils.comm import get_world_size
  from ...nn.focal_loss import sigmoid_focal_loss_jit
  from ...nn.smooth_l1_loss import smooth_l1_loss
  from ...utils.comm import reduce_sum
  from ...nn.nms import ml_nms, oks_nms, close_kpt_nms
  from ...nn.iou_loss import IOULoss
  from ...nn.keypoint_loss import WeightedMSELoss, HMFocalLoss
label_desc: Use image node_id 5 for calling the DirectPoseOutputs obj's underlying member method code with example usage: obj.compute_targets_for_locations(locations, targets, size_ranges, num_loc_list, images) and returns: dict