Class YOLOv3Loss


  • public final class YOLOv3Loss
    extends Loss
    YOLOv3Loss is an implementation of Loss. It is used to compute the loss while training a YOLOv3 model for object detection. It involves computing the targets given the generated anchors, labels and predictions, and then computing the sum of class predictions and bounding box predictions.
    • Method Detail

      • getPresetAnchors

        public static float[] getPresetAnchors()
        Gets the preset anchors of YoloV3.
        Returns:
        the preset anchors of YoloV3
      • clipByTensor

        public NDArray clipByTensor​(NDArray tList,
                                    float tMin,
                                    float tMax)
        Make the value of given NDArray between tMin and tMax.
        Parameters:
        tList - the given NDArray
        tMin - the min value
        tMax - the max value
        Returns:
        a NDArray where values are set between tMin and tMax
      • mseLoss

        public NDArray mseLoss​(NDArray prediction,
                               NDArray target)
        Calculates the MSELoss between prediction and target.
        Parameters:
        prediction - the prediction array
        target - the target array
        Returns:
        the MSELoss between prediction and target
      • bceLoss

        public NDArray bceLoss​(NDArray prediction,
                               NDArray target)
        Calculates the BCELoss between prediction and target.
        Parameters:
        prediction - the prediction array
        target - the target array
        Returns:
        the BCELoss between prediction and target
      • evaluate

        public NDArray evaluate​(NDList labels,
                                NDList predictions)
        Calculates the evaluation between the labels and the predictions.
        Specified by:
        evaluate in class Evaluator
        Parameters:
        labels - the correct values
        predictions - the predicted values
        Returns:
        the evaluation result
      • evaluateOneOutput

        public NDArray evaluateOneOutput​(int componentIndex,
                                         NDArray input,
                                         NDArray labels)
        Computes the Loss for one outputLayer.
        Parameters:
        componentIndex - which outputLayer does current input represent. the shape should be (13*13,26*26,52*52)
        input - one prediction layer of YOLOv3
        labels - target labels. Must contain (offsetLabels, masks, classlabels)
        Returns:
        the total loss of a outputLayer
      • getTarget

        public NDList getTarget​(NDArray labels,
                                int inH,
                                int inW)
        Gets target NDArray for a given evaluator.
        Parameters:
        labels - the true labels
        inH - the height of current layer
        inW - the width of current layer
        Returns:
        an NDList of {boxLossScale and groundTruth}
      • calculateIOU

        public NDArray calculateIOU​(NDArray predx,
                                    NDArray predy,
                                    NDArray groundTruth,
                                    int componentIndex)
        Calculates the IOU between priori Anchors and groundTruth.
        Parameters:
        predx - the tx value of prediction
        predy - the ty value of prediction
        groundTruth - the groundTruth value of labels
        componentIndex - the current component Index
        Returns:
        an NDArray of IOU