class_docstr: Region Proposal Network, introduced by :paper:`Faster R-CNN`.
class_docstr_tok: ["Region","Proposal","Network",",","introduced","by",":","paper",":","`","Faster","R-CNN","`","."]
code: def from_config(cls, cfg, input_shape: Dict[str, ShapeSpec]):
      in_features = cfg.MODEL.RPN.IN_FEATURES
      ret = {
          "in_features": in_features,
          "min_box_size": cfg.MODEL.PROPOSAL_GENERATOR.MIN_SIZE,
          "nms_thresh": cfg.MODEL.RPN.NMS_THRESH,
          "batch_size_per_image": cfg.MODEL.RPN.BATCH_SIZE_PER_IMAGE,
          "positive_fraction": cfg.MODEL.RPN.POSITIVE_FRACTION,
          "loss_weight": {
              "loss_rpn_cls": cfg.MODEL.RPN.LOSS_WEIGHT,
              "loss_rpn_loc": cfg.MODEL.RPN.BBOX_REG_LOSS_WEIGHT
              * cfg.MODEL.RPN.LOSS_WEIGHT,
          },
          "anchor_boundary_thresh": cfg.MODEL.RPN.BOUNDARY_THRESH,
          "box2box_transform": Box2BoxTransform(
              weights=cfg.MODEL.RPN.BBOX_REG_WEIGHTS
          ),
          "box_reg_loss_type": cfg.MODEL.RPN.BBOX_REG_LOSS_TYPE,
          "smooth_l1_beta": cfg.MODEL.RPN.SMOOTH_L1_BETA,
      }
  
      ret["pre_nms_topk"] = (
          cfg.MODEL.RPN.PRE_NMS_TOPK_TRAIN,
          cfg.MODEL.RPN.PRE_NMS_TOPK_TEST,
      )
      ret["post_nms_topk"] = (
          cfg.MODEL.RPN.POST_NMS_TOPK_TRAIN,
          cfg.MODEL.RPN.POST_NMS_TOPK_TEST,
      )
  
      ret["anchor_generator"] = build_anchor_generator(
          cfg, [input_shape[f] for f in in_features]
      )
      ret["anchor_matcher"] = Matcher(
          cfg.MODEL.RPN.IOU_THRESHOLDS,
          cfg.MODEL.RPN.IOU_LABELS,
          allow_low_quality_matches=True,
      )
      ret["head"] = build_rpn_head(
          cfg, [input_shape[f] for f in in_features]
      )
      return ret
  
imports: from typing import Dict, List, Optional, Tuple, Union
  import torch
  import torch.nn.functional
  from torch import nn
  from detectron2.config import configurable
  from detectron2.layers import Conv2d, ShapeSpec, cat
  from detectron2.structures import Boxes, ImageList, Instances, pairwise_iou
  from detectron2.utils.events import get_event_storage
  from detectron2.utils.memory import retry_if_cuda_oom
  from detectron2.utils.registry import Registry
  from ..anchor_generator import build_anchor_generator
  from ..box_regression import Box2BoxTransform, _dense_box_regression_loss
  from ..matcher import Matcher
  from ..sampling import subsample_labels
  from .build import PROPOSAL_GENERATOR_REGISTRY
  from .proposal_utils import find_top_rpn_proposals
label_desc: Use image node_id 2 for calling the RPN obj's underlying member method code with example usage: obj.from_config(cls, cfg, input_shape) and returns: ret