Class YOLOV3

  • All Implemented Interfaces:
    ai.djl.nn.Block

    public final class YOLOV3
    extends ai.djl.nn.AbstractBlock
    YOLOV3 contains a generic implementation of yolov3 (Original author bubbliiiing).

    Yolov3 is a fast and accurate model for ObjectDetection tasks.

    See Also:
    for more information and knowledge about yolov3
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  YOLOV3.Builder
      The Builder to construct a YOLOV3 object.
    • Field Summary

      • Fields inherited from class ai.djl.nn.AbstractBlock

        children, parameters
      • Fields inherited from class ai.djl.nn.AbstractBaseBlock

        inputNames, inputShapes, outputDataTypes, version
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static ai.djl.nn.Block basicBlock​(int filters, float batchNormMomentum, float leakyAlpha)
      Builds a Block that a basic residual block unit used in DarkNet53.
      static YOLOV3.Builder builder()
      Creates a builder to build a YOLOV3.
      static ai.djl.nn.Block convolutionBlock​(int filters, int kernel, float batchNormMomentum, float leakyAlpha)
      Builds a Block that represents a conv-bn-leakyRelu unit for darkNet53.
      protected ai.djl.ndarray.NDList forwardInternal​(ai.djl.training.ParameterStore parameterStore, ai.djl.ndarray.NDList inputs, boolean training, ai.djl.util.PairList<java.lang.String,​java.lang.Object> params)
      ai.djl.ndarray.types.Shape[] getOutputShapes​(ai.djl.ndarray.types.Shape[] inputShapes)
      void initializeChildBlocks​(ai.djl.ndarray.NDManager manager, ai.djl.ndarray.types.DataType dataType, ai.djl.ndarray.types.Shape... inputShapes)
      static ai.djl.nn.Block makeLastLayers​(int filtersIn, int filtersOut, float batchNormMomentum, float leakyAlpha)
      Builds a Block that represents the feature head in yolov3.
      static ai.djl.nn.Block makeLayer​(int filters, int repeats, float batchNormMomentum, float leakyAlpha)
      Creates repeated Residual Blocks used in DarkNet53.
      static ai.djl.nn.Block makeOutputLayers​(int filtersOut, int outClass, float batchNormMomentum, float leakyAlpha)
      Builds a Block that represents the output layer of yolov3.
      static ai.djl.nn.Block upSampleBlockNearest()
      Builds a Block that represents an upSampleLayer(the nearest mode) for yolov3.
      • Methods inherited from class ai.djl.nn.AbstractBlock

        addChildBlock, addChildBlock, addChildBlockSingleton, addParameter, getChildren, getDirectParameters
      • Methods inherited from class ai.djl.nn.AbstractBaseBlock

        beforeInitialize, cast, clear, describeInput, forward, forward, forwardInternal, getInputShapes, getOutputDataTypes, getParameters, initialize, isInitialized, loadMetadata, loadParameters, prepare, readInputShapes, saveInputShapes, saveMetadata, saveParameters, setInitializer, setInitializer, setInitializer, toString
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface ai.djl.nn.Block

        forward, freezeParameters, freezeParameters, getOutputShapes
    • Method Detail

      • upSampleBlockNearest

        public static ai.djl.nn.Block upSampleBlockNearest()
        Builds a Block that represents an upSampleLayer(the nearest mode) for yolov3.
        Returns:
        a Block that represent an upSampleLayer for yolov3
      • convolutionBlock

        public static ai.djl.nn.Block convolutionBlock​(int filters,
                                                       int kernel,
                                                       float batchNormMomentum,
                                                       float leakyAlpha)
        Builds a Block that represents a conv-bn-leakyRelu unit for darkNet53.
        Parameters:
        filters - the number of filters for conv
        kernel - the kernel size for conv
        batchNormMomentum - the momentum for batchNorm layer
        leakyAlpha - the alpha for leakyRelu activation
        Returns:
        a Block that represents a conv-bn-leakyRelu unit for darkNet53
      • makeLastLayers

        public static ai.djl.nn.Block makeLastLayers​(int filtersIn,
                                                     int filtersOut,
                                                     float batchNormMomentum,
                                                     float leakyAlpha)
        Builds a Block that represents the feature head in yolov3.
        Parameters:
        filtersIn - the number of input filters
        filtersOut - the number of output filters
        batchNormMomentum - the momentum of batchNorm layer
        leakyAlpha - the alpha value for leakyRelu activation
        Returns:
        a Block that represents the feature head in yolov3.
      • makeOutputLayers

        public static ai.djl.nn.Block makeOutputLayers​(int filtersOut,
                                                       int outClass,
                                                       float batchNormMomentum,
                                                       float leakyAlpha)
        Builds a Block that represents the output layer of yolov3.
        Parameters:
        filtersOut - the number of output filters
        outClass - the number of output classes
        batchNormMomentum - the momentum for batchNorm layer
        leakyAlpha - the alpha for leakyRelu activation
        Returns:
        a Block that represents the output layer of yolov3.
      • forwardInternal

        protected ai.djl.ndarray.NDList forwardInternal​(ai.djl.training.ParameterStore parameterStore,
                                                        ai.djl.ndarray.NDList inputs,
                                                        boolean training,
                                                        ai.djl.util.PairList<java.lang.String,​java.lang.Object> params)
        Specified by:
        forwardInternal in class ai.djl.nn.AbstractBaseBlock
      • getOutputShapes

        public ai.djl.ndarray.types.Shape[] getOutputShapes​(ai.djl.ndarray.types.Shape[] inputShapes)
      • initializeChildBlocks

        public void initializeChildBlocks​(ai.djl.ndarray.NDManager manager,
                                          ai.djl.ndarray.types.DataType dataType,
                                          ai.djl.ndarray.types.Shape... inputShapes)
        Overrides:
        initializeChildBlocks in class ai.djl.nn.AbstractBaseBlock
      • basicBlock

        public static ai.djl.nn.Block basicBlock​(int filters,
                                                 float batchNormMomentum,
                                                 float leakyAlpha)
        Builds a Block that a basic residual block unit used in DarkNet53.
        Parameters:
        filters - the output filter of the Convolutional Layer
        batchNormMomentum - the momentum used for computing batchNorm
        leakyAlpha - the alpha used in LeakyRelu Function
        Returns:
        a basic residual block unit used in DarkNet53
      • makeLayer

        public static ai.djl.nn.Block makeLayer​(int filters,
                                                int repeats,
                                                float batchNormMomentum,
                                                float leakyAlpha)
        Creates repeated Residual Blocks used in DarkNet53.
        Parameters:
        filters - the output filters of the final Convolutional Layer
        repeats - the repeat times of a residual unit
        batchNormMomentum - the momentum used for computing batchNorm
        leakyAlpha - the alpha used in LeakyRelu Function
        Returns:
        several repeats of a residual block
      • builder

        public static YOLOV3.Builder builder()
        Creates a builder to build a YOLOV3.
        Returns:
        a new builder