code: def __init__(
      self,
      prefix,
      epoch,
      ctx_id=0,
      network="net3",
      nms=0.4,
      nocrop=False,
      decay4=0.5,
      vote=False,
  ):
      self.ctx_id = ctx_id
      self.network = network
      self.decay4 = decay4
      self.nms_threshold = nms
      self.vote = vote
      self.nocrop = nocrop
      self.debug = False
      self.fpn_keys = []
      self.anchor_cfg = None
      pixel_means = [0.0, 0.0, 0.0]
      pixel_stds = [1.0, 1.0, 1.0]
      pixel_scale = 1.0
      self.preprocess = False
      _ratio = (1.0,)
      fmc = 3
      if network == "ssh" or network == "vgg":
          pixel_means = [103.939, 116.779, 123.68]
          self.preprocess = True
      elif network == "net3":
          _ratio = (1.0,)
      elif network == "net3a":
          _ratio = (1.0, 1.5)
      elif network == "net6":  # like pyramidbox or s3fd
          fmc = 6
      elif network == "net5":  # retinaface
          fmc = 5
      elif network == "net5a":
          fmc = 5
          _ratio = (1.0, 1.5)
      elif network == "net4":
          fmc = 4
      elif network == "net4a":
          fmc = 4
          _ratio = (1.0, 1.5)
      elif network == "x5":
          fmc = 5
          pixel_means = [103.52, 116.28, 123.675]
          pixel_stds = [57.375, 57.12, 58.395]
      elif network == "x3":
          fmc = 3
          pixel_means = [103.52, 116.28, 123.675]
          pixel_stds = [57.375, 57.12, 58.395]
      elif network == "x3a":
          fmc = 3
          _ratio = (1.0, 1.5)
          pixel_means = [103.52, 116.28, 123.675]
          pixel_stds = [57.375, 57.12, 58.395]
      else:
          assert False, "network setting error %s" % network
  
      if fmc == 3:
          self._feat_stride_fpn = [32, 16, 8]
          self.anchor_cfg = {
              "32": {
                  "SCALES": (32, 16),
                  "BASE_SIZE": 16,
                  "RATIOS": _ratio,
                  "ALLOWED_BORDER": 9999,
              },
              "16": {
                  "SCALES": (8, 4),
                  "BASE_SIZE": 16,
                  "RATIOS": _ratio,
                  "ALLOWED_BORDER": 9999,
              },
              "8": {
                  "SCALES": (2, 1),
                  "BASE_SIZE": 16,
                  "RATIOS": _ratio,
                  "ALLOWED_BORDER": 9999,
              },
          }
      elif fmc == 4:
          self._feat_stride_fpn = [32, 16, 8, 4]
          self.anchor_cfg = {
              "32": {
                  "SCALES": (32, 16),
                  "BASE_SIZE": 16,
                  "RATIOS": _ratio,
                  "ALLOWED_BORDER": 9999,
              },
              "16": {
                  "SCALES": (8, 4),
                  "BASE_SIZE": 16,
                  "RATIOS": _ratio,
                  "ALLOWED_BORDER": 9999,
              },
              "8": {
                  "SCALES": (2, 1),
                  "BASE_SIZE": 16,
                  "RATIOS": _ratio,
                  "ALLOWED_BORDER": 9999,
              },
              "4": {
                  "SCALES": (2, 1),
                  "BASE_SIZE": 16,
                  "RATIOS": _ratio,
                  "ALLOWED_BORDER": 9999,
              },
          }
      elif fmc == 6:
          self._feat_stride_fpn = [128, 64, 32, 16, 8, 4]
          self.anchor_cfg = {
              "128": {
                  "SCALES": (32,),
                  "BASE_SIZE": 16,
                  "RATIOS": _ratio,
                  "ALLOWED_BORDER": 9999,
              },
              "64": {
                  "SCALES": (16,),
                  "BASE_SIZE": 16,
                  "RATIOS": _ratio,
                  "ALLOWED_BORDER": 9999,
              },
              "32": {
                  "SCALES": (8,),
                  "BASE_SIZE": 16,
                  "RATIOS": _ratio,
                  "ALLOWED_BORDER": 9999,
              },
              "16": {
                  "SCALES": (4,),
                  "BASE_SIZE": 16,
                  "RATIOS": _ratio,
                  "ALLOWED_BORDER": 9999,
              },
              "8": {
                  "SCALES": (2,),
                  "BASE_SIZE": 16,
                  "RATIOS": _ratio,
                  "ALLOWED_BORDER": 9999,
              },
              "4": {
                  "SCALES": (1,),
                  "BASE_SIZE": 16,
                  "RATIOS": _ratio,
                  "ALLOWED_BORDER": 9999,
              },
          }
      elif fmc == 5:
          self._feat_stride_fpn = [64, 32, 16, 8, 4]
          self.anchor_cfg = {}
          _ass = 2.0 ** (1.0 / 3)
          _basescale = 1.0
          for _stride in [4, 8, 16, 32, 64]:
              key = str(_stride)
              value = {
                  "BASE_SIZE": 16,
                  "RATIOS": _ratio,
                  "ALLOWED_BORDER": 9999,
              }
              scales = []
              for _ in range(3):
                  scales.append(_basescale)
                  _basescale *= _ass
              value["SCALES"] = tuple(scales)
              self.anchor_cfg[key] = value
  
      print(self._feat_stride_fpn, self.anchor_cfg)
  
      for s in self._feat_stride_fpn:
          self.fpn_keys.append("stride%s" % s)
  
      dense_anchor = False
      # self._anchors_fpn = dict(zip(self.fpn_keys, generate_anchors_fpn(base_size=fpn_base_size, scales=self._scales, ratios=self._ratios)))
      self._anchors_fpn = dict(
          zip(
              self.fpn_keys,
              generate_anchors_fpn(
                  dense_anchor=dense_anchor, cfg=self.anchor_cfg
              ),
          )
      )
      for k in self._anchors_fpn:
          v = self._anchors_fpn[k].astype(np.float32)
          self._anchors_fpn[k] = v
  
      self._num_anchors = dict(
          zip(
              self.fpn_keys,
              [
                  anchors.shape[0]
                  for anchors in self._anchors_fpn.values()
              ],
          )
      )
      # self._bbox_pred = nonlinear_pred
      # self._landmark_pred = landmark_pred
      sym, arg_params, aux_params = mx.model.load_checkpoint(
          prefix, epoch
      )
      if self.ctx_id >= 0:
          self.ctx = mx.gpu(self.ctx_id)
          self.nms = gpu_nms_wrapper(self.nms_threshold, self.ctx_id)
      else:
          self.ctx = mx.cpu()
          self.nms = cpu_nms_wrapper(self.nms_threshold)
      self.pixel_means = np.array(pixel_means, dtype=np.float32)
      self.pixel_stds = np.array(pixel_stds, dtype=np.float32)
      self.pixel_scale = float(pixel_scale)
      print("means", self.pixel_means)
      self.use_landmarks = False
      if len(sym) // len(self._feat_stride_fpn) >= 3:
          self.use_landmarks = True
      print("use_landmarks", self.use_landmarks)
      self.cascade = 0
      if float(len(sym)) // len(self._feat_stride_fpn) > 3.0:
          self.cascade = 1
      print("cascade", self.cascade)
      # self.bbox_stds = [0.1, 0.1, 0.2, 0.2]
      # self.landmark_std = 0.1
      self.bbox_stds = [1.0, 1.0, 1.0, 1.0]
      self.landmark_std = 1.0
  
      if self.debug:
          c = len(sym) // len(self._feat_stride_fpn)
          sym = sym[(c * 0) :]
          self._feat_stride_fpn = [32, 16, 8]
      print("sym size:", len(sym))
  
      image_size = (640, 640)
      self.model = mx.mod.Module(
          symbol=sym, context=self.ctx, label_names=None
      )
      self.model.bind(
          data_shapes=[("data", (1, 3, image_size[0], image_size[1]))],
          for_training=False,
      )
      self.model.set_params(arg_params, aux_params)
  
imports: from __future__ import print_function
  import sys
  import os
  import datetime
  import time
  import numpy
  import mxnet
  from mxnet import ndarray
  import cv2
  from rcnn.logger import logger
  from rcnn.processing.bbox_transform import clip_boxes
  from rcnn.processing.generate_anchor import generate_anchors_fpn, anchors_plane
  from rcnn.processing.nms import gpu_nms_wrapper, cpu_nms_wrapper
  from rcnn.processing.bbox_transform import bbox_overlaps
label_desc: Use image node_id 1 to create a new RetinaFace object  with example: obj = RetinaFace(prefix, epoch, ctx_id, network, nms, nocrop, decay4, vote)