class_docstr: YOLO output layer V3.
  Parameters
  ----------
  index : int
      Index of the yolo output layer, to avoid naming conflicts only.
  num_class : int
      Number of foreground objects.
  anchors : iterable
      The anchor setting. Reference: https://arxiv.org/pdf/1804.02767.pdf.
  stride : int
      Stride of feature map.
  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.
class_docstr_tok: ["YOLO","output","layer","V3",".","Parameters","--","--","--","--","--","index",":","int","Index","of","the","yolo","output","layer",",","to","avoid","naming","conflicts","only",".","num_class",":","int","Number","of","foreground","objects",".","anchors",":","iterable","The","anchor","setting",".","Reference",":","https",":","\/\/arxiv.org\/pdf\/1804.02767.pdf",".","stride",":","int","Stride","of","feature","map",".","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","."]
docstr: Hybrid Forward of YOLOV3Output layer.
  Parameters
  ----------
  F : mxnet.nd or mxnet.sym
      `F` is mxnet.sym if hybridized or mxnet.nd if not.
  x : mxnet.nd.NDArray
      Input feature map.
  anchors : mxnet.nd.NDArray
      Anchors loaded from self, no need to supply.
  offsets : mxnet.nd.NDArray
      Offsets loaded from self, no need to supply.
  Returns
  -------
  (tuple of) mxnet.nd.NDArray
      During training, return (bbox, raw_box_centers, raw_box_scales, objness,
      class_pred, anchors, offsets).
      During inference, return detections.
code: def hybrid_forward(self, F, x, anchors, offsets):
      """Hybrid Forward of YOLOV3Output layer.
      Parameters
      ----------
      F : mxnet.nd or mxnet.sym
          `F` is mxnet.sym if hybridized or mxnet.nd if not.
      x : mxnet.nd.NDArray
          Input feature map.
      anchors : mxnet.nd.NDArray
          Anchors loaded from self, no need to supply.
      offsets : mxnet.nd.NDArray
          Offsets loaded from self, no need to supply.
      Returns
      -------
      (tuple of) mxnet.nd.NDArray
          During training, return (bbox, raw_box_centers, raw_box_scales, objness,
          class_pred, anchors, offsets).
          During inference, return detections.
      """
      # prediction flat to (batch, pred per pixel, height * width)
      pred = self.prediction(x).reshape(
          (0, self._num_anchors * self._num_pred, -1)
      )
      # transpose to (batch, height * width, num_anchor, num_pred)
      pred = pred.transpose(axes=(0, 2, 1)).reshape(
          (0, -1, self._num_anchors, self._num_pred)
      )
      # components
      raw_box_centers = pred.slice_axis(axis=-1, begin=0, end=2)
      raw_box_scales = pred.slice_axis(axis=-1, begin=2, end=4)
      objness = pred.slice_axis(axis=-1, begin=4, end=5)
      class_pred = pred.slice_axis(axis=-1, begin=5, end=None)
  
      # valid offsets, (1, 1, height, width, 2)
      offsets = F.slice_like(offsets, x * 0, axes=(2, 3))
      # reshape to (1, height*width, 1, 2)
      offsets = offsets.reshape((1, -1, 1, 2))
  
      box_centers = (
          F.broadcast_add(F.sigmoid(raw_box_centers), offsets)
          * self._stride
      )
      box_scales = F.broadcast_mul(F.exp(raw_box_scales), anchors)
      confidence = F.sigmoid(objness)
      class_score = F.broadcast_mul(F.sigmoid(class_pred), confidence)
      wh = box_scales / 2.0
      bbox = F.concat(box_centers - wh, box_centers + wh, dim=-1)
  
      if autograd.is_training():
          # during training, we don't need to convert whole bunch of info to detection results
          return (
              bbox.reshape((0, -1, 4)),
              raw_box_centers,
              raw_box_scales,
              objness,
              class_pred,
              anchors,
              offsets,
          )
  
      # prediction per class
      bboxes = F.tile(bbox, reps=(self._classes, 1, 1, 1, 1))
      scores = F.transpose(class_score, axes=(3, 0, 1, 2)).expand_dims(
          axis=-1
      )
      ids = F.broadcast_add(
          scores * 0,
          F.arange(0, self._classes).reshape((0, 1, 1, 1, 1)),
      )
      detections = F.concat(ids, scores, bboxes, dim=-1)
      # reshape to (B, xx, 6)
      detections = F.reshape(
          detections.transpose(axes=(1, 0, 2, 3, 4)), (0, -1, 6)
      )
      return detections
  
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 3 for calling the YOLOOutputV3 obj's underlying member method code with example usage: obj.hybrid_forward(F, x, anchors, offsets) and returns: detections, bbox,  raw_box_centers,  raw_box_scales,  objness,  class_pred,  anchors,  offsets