class_docstr: Implement DirectPose.
class_docstr_tok: ["Implement","DirectPose","."]
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,
          bbox_reg_pred,
          kpt_reg_pred,
          kpts_locator_reg_pred,
          ctrness_pred,
          top_feats,
          kpts_towers,
          hms,
          hms_offset,
      ) = self.directpose_head(
          features, top_module, self.yield_proposal
      )
  
      results = {}
      if self.yield_proposal:
          results["features"] = {
              f: b for f, b in zip(self.in_features, kpts_towers)
          }
  
      if isinstance(images, torch.Tensor):
          image_sizes = [image.size()[-2:] for image in images]
      else:
          image_sizes = images.image_sizes
  
      if self.training:
          results, losses = self.directpose_outputs.losses(
              logits_pred,
              bbox_reg_pred,
              kpt_reg_pred,
              kpts_locator_reg_pred,
              ctrness_pred,
              hms,
              hms_offset,
              locations,
              gt_instances,
              top_feats,
              None,
          )
  
          if self.yield_proposal:
              with torch.no_grad():
                  results[
                      "proposals"
                  ] = self.directpose_outputs.predict_proposals(
                      logits_pred,
                      bbox_reg_pred,
                      kpt_reg_pred,
                      ctrness_pred,
                      hms,
                      locations,
                      image_sizes,
                      top_feats,
                  )
          return results, losses
      else:
          results = self.directpose_outputs.predict_proposals(
              logits_pred,
              bbox_reg_pred,
              kpt_reg_pred,
              ctrness_pred,
              hms,
              hms_offset,
              locations,
              image_sizes,
              top_feats,
              None,
          )
  
          return results, {}
  
imports: import math
  from typing import List, Dict
  import torch
  from torch import nn
  from torch.nn import functional
  from torch.autograd import Variable
  import numpy
  from ...utils.comm import compute_locations
  from ...nn.shape_spec import ShapeSpec
  from ...nn.batch_norm import NaiveSyncBatchNorm
  from ...nn.deform_conv import DeformConvWithChangeableStride
  from ...nn.group_norm import NaiveGroupNorm
  from .directpose_outputs import DirectPoseOutputs
label_desc: Use image node_id 3 for calling the DirectPose obj's underlying member method code with example usage: obj.forward(images, features, gt_instances, top_module) and returns: results,  losses, results,  dict