class_docstr: YOLO V3 detection network.
  Reference: https://arxiv.org/pdf/1804.02767.pdf.
  Parameters
  ----------
  stages : mxnet.gluon.HybridBlock
      Staged feature extraction blocks.
      For example, 3 stages and 3 YOLO output layers are used original paper.
  channels : iterable
      Number of conv channels for each appended stage.
      `len(channels)` should match `len(stages)`.
  num_class : int
      Number of foreground objects.
  anchors : iterable
      The anchor setting. `len(anchors)` should match `len(stages)`.
  strides : iterable
      Strides of feature map. `len(strides)` should match `len(stages)`.
  alloc_size : tuple of int, default is (128, 128)
      For advanced users. Define `alloc_size` to generate large enough anchor
      maps, which will later saved in parameters. During inference, we support arbitrary
      input image by cropping corresponding area of the anchor map. This allow us
      to export to symbol so we can run it in c++, Scalar, etc.
  nms_thresh : float, default is 0.45.
      Non-maximum suppression threshold. You can specify < 0 or > 1 to disable NMS.
  nms_topk : int, default is 400
      Apply NMS to top k detection results, use -1 to disable so that every Detection
       result is used in NMS.
  post_nms : int, default is 100
      Only return top `post_nms` detection results, the rest is discarded. The number is
      based on COCO dataset which has maximum 100 objects per image. You can adjust this
      number if expecting more objects. You can use -1 to return all detections.
  pos_iou_thresh : float, default is 1.0
      IOU threshold for true anchors that match real objects.
      'pos_iou_thresh < 1' is not implemented.
  ignore_iou_thresh : float
      Anchors that has IOU in `range(ignore_iou_thresh, pos_iou_thresh)` don't get
      penalized of objectness score.
  norm_layer : object
      Normalization layer used (default: :class:`mxnet.gluon.nn.BatchNorm`)
      Can be :class:`mxnet.gluon.nn.BatchNorm` or :class:`mxnet.gluon.contrib.nn.SyncBatchNorm`.
  norm_kwargs : dict
      Additional `norm_layer` arguments, for example `num_devices=4`
      for :class:`mxnet.gluon.contrib.nn.SyncBatchNorm`.
class_docstr_tok: ["YOLO","V3","detection","network",".","Reference",":","https",":","\/\/arxiv.org\/pdf\/1804.02767.pdf",".","Parameters","--","--","--","--","--","stages",":","mxnet.gluon.HybridBlock","Staged","feature","extraction","blocks",".","For","example",",","3","stages","and","3","YOLO","output","layers","are","used","original","paper",".","channels",":","iterable","Number","of","conv","channels","for","each","appended","stage",".","`","len","(","channels",")","`","should","match","`","len","(","stages",")","`",".","num_class",":","int","Number","of","foreground","objects",".","anchors",":","iterable","The","anchor","setting",".","`","len","(","anchors",")","`","should","match","`","len","(","stages",")","`",".","strides",":","iterable","Strides","of","feature","map",".","`","len","(","strides",")","`","should","match","`","len","(","stages",")","`",".","alloc_size",":","tuple","of","int",",","default","is","(","128",",","128",")","For","advanced","users",".","Define","`","alloc_size","`","to","generate","large","enough","anchor","maps",",","which","will","later","saved","in","parameters",".","During","inference",",","we","support","arbitrary","input","image","by","cropping","corresponding","area","of","the","anchor","map",".","This","allow","us","to","export","to","symbol","so","we","can","run","it","in","c++",",","Scalar",",","etc",".","nms_thresh",":","float",",","default","is","0.45",".","Non-maximum","suppression","threshold",".","You","can","specify","<","0","or",">","1","to","disable","NMS",".","nms_topk",":","int",",","default","is","400","Apply","NMS","to","top","k","detection","results",",","use","-1","to","disable","so","that","every","Detection","result","is","used","in","NMS",".","post_nms",":","int",",","default","is","100","Only","return","top","`","post_nms","`","detection","results",",","the","rest","is","discarded",".","The","number","is","based","on","COCO","dataset","which","has","maximum","100","objects","per","image",".","You","can","adjust","this","number","if","expecting","more","objects",".","You","can","use","-1","to","return","all","detections",".","pos_iou_thresh",":","float",",","default","is","1.0","IOU","threshold","for","true","anchors","that","match","real","objects",".","'pos_iou_thresh","<","1","'","is","not","implemented",".","ignore_iou_thresh",":","float","Anchors","that","has","IOU","in","`","range","(","ignore_iou_thresh",",","pos_iou_thresh",")","`","do","n't","get","penalized","of","objectness","score",".","norm_layer",":","object","Normalization","layer","used","(","default",":",":","class",":","`","mxnet.gluon.nn.BatchNorm","`",")","Can","be",":","class",":","`","mxnet.gluon.nn.BatchNorm","`","or",":","class",":","`","mxnet.gluon.contrib.nn.SyncBatchNorm","`",".","norm_kwargs",":","dict","Additional","`","norm_layer","`","arguments",",","for","example","`","num_devices=4","`","for",":","class",":","`","mxnet.gluon.contrib.nn.SyncBatchNorm","`","."]
docstr: YOLOV3 network hybrid forward.
  Parameters
  ----------
  F : mxnet.nd or mxnet.sym
      `F` is mxnet.sym if hybridized or mxnet.nd if not.
  x : mxnet.nd.NDArray
      Input data.
  *args : optional, mxnet.nd.NDArray
      During training, extra inputs are required:
      (gt_boxes, obj_t, centers_t, scales_t, weights_t, clas_t)
      These are generated by YOLOV3PrefetchTargetGenerator in dataloader transform function.
  Returns
  -------
  (tuple of) mxnet.nd.NDArray
      During inference, return detections in shape (B, N, 6)
      with format (cid, score, xmin, ymin, xmax, ymax)
      During training, return losses only: (obj_loss, center_loss, scale_loss, cls_loss).
code: def hybrid_forward(self, F, x, *args):
      """YOLOV3 network hybrid forward.
      Parameters
      ----------
      F : mxnet.nd or mxnet.sym
          `F` is mxnet.sym if hybridized or mxnet.nd if not.
      x : mxnet.nd.NDArray
          Input data.
      *args : optional, mxnet.nd.NDArray
          During training, extra inputs are required:
          (gt_boxes, obj_t, centers_t, scales_t, weights_t, clas_t)
          These are generated by YOLOV3PrefetchTargetGenerator in dataloader transform function.
      Returns
      -------
      (tuple of) mxnet.nd.NDArray
          During inference, return detections in shape (B, N, 6)
          with format (cid, score, xmin, ymin, xmax, ymax)
          During training, return losses only: (obj_loss, center_loss, scale_loss, cls_loss).
      """
      if len(args) != 0 and not autograd.is_training():
          raise TypeError("YOLOV3 inference only need one input data.")
  
      all_box_centers = []
      all_box_scales = []
      all_objectness = []
      all_class_pred = []
      all_anchors = []
      all_offsets = []
      all_feat_maps = []
      all_detections = []
      routes = []
      for stage, block, output in zip(
          self.stages, self.yolo_blocks, self.yolo_outputs
      ):
          x = stage(x)
          routes.append(x)
  
      # the YOLO output layers are used in reverse order, i.e., from very deep layers to shallow
      for i, block, output in zip(
          range(len(routes)), self.yolo_blocks, self.yolo_outputs
      ):
          x, tip = block(x)
          if autograd.is_training():
              (
                  dets,
                  box_centers,
                  box_scales,
                  objness,
                  class_pred,
                  anchors,
                  offsets,
              ) = output(tip)
              all_box_centers.append(box_centers.reshape((0, -3, -1)))
              all_box_scales.append(box_scales.reshape((0, -3, -1)))
              all_objectness.append(objness.reshape((0, -3, -1)))
              all_class_pred.append(class_pred.reshape((0, -3, -1)))
              all_anchors.append(anchors)
              all_offsets.append(offsets)
              # here we use fake featmap to reduce memory consuption, only shape[2, 3] is used
              fake_featmap = F.zeros_like(
                  tip.slice_axis(axis=0, begin=0, end=1).slice_axis(
                      axis=1, begin=0, end=1
                  )
              )
              all_feat_maps.append(fake_featmap)
          else:
              dets = output(tip)
          all_detections.append(dets)
          if i >= len(routes) - 1:
              break
          # add transition layers
          x = self.transitions[i](x)
          # upsample feature map reverse to shallow layers
          upsample = _upsample(x, stride=2)
          route_now = routes[::-1][i + 1]
          x = F.concat(
              F.slice_like(upsample, route_now * 0, axes=(2, 3)),
              route_now,
              dim=1,
          )
  
      if autograd.is_training():
          # during training, the network behaves differently since we don't need detection results
          if autograd.is_recording():
              # generate losses and return them directly
              box_preds = F.concat(*all_detections, dim=1)
              all_preds = [
                  F.concat(*p, dim=1)
                  for p in [
                      all_objectness,
                      all_box_centers,
                      all_box_scales,
                      all_class_pred,
                  ]
              ]
              all_targets = self._target_generator(box_preds, *args)
              return self._loss(*(all_preds + all_targets))
  
          # return raw predictions, this is only used in DataLoader transform function.
          return (
              F.concat(*all_detections, dim=1),
              all_anchors,
              all_offsets,
              all_feat_maps,
              F.concat(*all_box_centers, dim=1),
              F.concat(*all_box_scales, dim=1),
              F.concat(*all_objectness, dim=1),
              F.concat(*all_class_pred, dim=1),
          )
  
      # concat all detection results from different stages
      result = F.concat(*all_detections, dim=1)
      # apply nms per class
      if self.nms_thresh > 0 and self.nms_thresh < 1:
          result = F.contrib.box_nms(
              result,
              overlap_thresh=self.nms_thresh,
              valid_thresh=0.01,
              topk=self.nms_topk,
              id_index=0,
              score_index=1,
              coord_start=2,
              force_suppress=False,
          )
          if self.post_nms > 0:
              result = result.slice_axis(
                  axis=1, begin=0, end=self.post_nms
              )
      ids = result.slice_axis(axis=-1, begin=0, end=1)
      scores = result.slice_axis(axis=-1, begin=1, end=2)
      bboxes = result.slice_axis(axis=-1, begin=2, end=None)
      return ids, scores, bboxes
  
imports: from __future__ import absolute_import
  from __future__ import division
  import os
  import warnings
  import numpy
  import mxnet
  from mxnet import gluon
  from mxnet import autograd
  from mxnet.gluon import nn
  from mxnet.gluon.nn import BatchNorm
  from .darknet import _conv2d, darknet53
  from ..mobilenet import get_mobilenet
  from .yolo_target import YOLOV3TargetMerger
  from ...loss import YOLOV3Loss
label_desc: Use image node_id 4 for calling the YOLOV3 obj's underlying member method code with example usage: obj.hybrid_forward(F, x) and returns: ids,  scores,  bboxes, F,  all_anchors,  all_offsets,  all_feat_maps,  F,  F,  F,  F, self