class_docstr: Implement RetinaNet in :paper:`RetinaNet`.
class_docstr_tok: ["Implement","RetinaNet","in",":","paper",":","`","RetinaNet","`","."]
code: def from_config(cls, cfg):
      backbone = build_backbone(cfg)
      backbone_shape = backbone.output_shape()
      feature_shapes = [
          backbone_shape[f] for f in cfg.MODEL.RETINANET.IN_FEATURES
      ]
      head = RetinaNetHead(cfg, feature_shapes)
      anchor_generator = build_anchor_generator(cfg, feature_shapes)
      return {
          "backbone": backbone,
          "head": head,
          "anchor_generator": anchor_generator,
          "box2box_transform": Box2BoxTransform(
              weights=cfg.MODEL.RETINANET.BBOX_REG_WEIGHTS
          ),
          "anchor_matcher": Matcher(
              cfg.MODEL.RETINANET.IOU_THRESHOLDS,
              cfg.MODEL.RETINANET.IOU_LABELS,
              allow_low_quality_matches=True,
          ),
          "pixel_mean": cfg.MODEL.PIXEL_MEAN,
          "pixel_std": cfg.MODEL.PIXEL_STD,
          "num_classes": cfg.MODEL.RETINANET.NUM_CLASSES,
          "head_in_features": cfg.MODEL.RETINANET.IN_FEATURES,
          # Loss parameters:
          "focal_loss_alpha": cfg.MODEL.RETINANET.FOCAL_LOSS_ALPHA,
          "focal_loss_gamma": cfg.MODEL.RETINANET.FOCAL_LOSS_GAMMA,
          "smooth_l1_beta": cfg.MODEL.RETINANET.SMOOTH_L1_LOSS_BETA,
          "box_reg_loss_type": cfg.MODEL.RETINANET.BBOX_REG_LOSS_TYPE,
          # Inference parameters:
          "test_score_thresh": cfg.MODEL.RETINANET.SCORE_THRESH_TEST,
          "test_topk_candidates": cfg.MODEL.RETINANET.TOPK_CANDIDATES_TEST,
          "test_nms_thresh": cfg.MODEL.RETINANET.NMS_THRESH_TEST,
          "max_detections_per_image": cfg.TEST.DETECTIONS_PER_IMAGE,
          # Vis parameters
          "vis_period": cfg.VIS_PERIOD,
          "input_format": cfg.INPUT.FORMAT,
      }
  
imports: import logging
  import math
  from typing import List, Tuple
  import torch
  from fvcore.nn import sigmoid_focal_loss_jit
  from torch import Tensor, nn
  from torch.nn import functional
  from detectron2.config import configurable
  from detectron2.layers import CycleBatchNormList, ShapeSpec, batched_nms, cat, get_norm
  from detectron2.structures import Boxes, ImageList, Instances, pairwise_iou
  from detectron2.utils.events import get_event_storage
  from ..anchor_generator import build_anchor_generator
  from ..backbone import Backbone, build_backbone
  from ..box_regression import Box2BoxTransform, _dense_box_regression_loss
  from ..matcher import Matcher
  from .build import META_ARCH_REGISTRY
  from .dense_detector import DenseDetector, permute_to_N_HWA_K
label_desc: Use image node_id 2 for calling the RetinaNet obj's underlying member method code with example usage: obj.from_config(cls, cfg) and returns: dict