Package ai.djl.training.loss
Class YOLOv3Loss
java.lang.Object
ai.djl.training.evaluator.Evaluator
ai.djl.training.loss.Loss
ai.djl.training.loss.YOLOv3Loss
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.-
Nested Class Summary
Nested Classes -
Field Summary
Fields inherited from class ai.djl.training.evaluator.Evaluator
totalInstances
-
Method Summary
Modifier and TypeMethodDescriptionCalculates the BCELoss between prediction and target.static YOLOv3Loss.Builder
builder()
Creates a new builder to build aYOLOv3Loss
.calculateIOU
(NDArray predx, NDArray predy, NDArray groundTruth, int componentIndex) Calculates the IOU between priori Anchors and groundTruth.clipByTensor
(NDArray tList, float tMin, float tMax) Make the value of given NDArray between tMin and tMax.Calculates the evaluation between the labels and the predictions.evaluateOneOutput
(int componentIndex, NDArray input, NDArray labels) Computes the Loss for one outputLayer.static float[]
Gets the preset anchors of YoloV3.Gets target NDArray for a given evaluator.Calculates the MSELoss between prediction and target.Methods inherited from class ai.djl.training.loss.Loss
addAccumulator, elasticNetWeightedDecay, elasticNetWeightedDecay, elasticNetWeightedDecay, elasticNetWeightedDecay, getAccumulator, hingeLoss, hingeLoss, hingeLoss, l1Loss, l1Loss, l1Loss, l1WeightedDecay, l1WeightedDecay, l1WeightedDecay, l2Loss, l2Loss, l2Loss, l2WeightedDecay, l2WeightedDecay, l2WeightedDecay, maskedSoftmaxCrossEntropyLoss, maskedSoftmaxCrossEntropyLoss, maskedSoftmaxCrossEntropyLoss, quantileL1Loss, quantileL1Loss, resetAccumulator, sigmoidBinaryCrossEntropyLoss, sigmoidBinaryCrossEntropyLoss, sigmoidBinaryCrossEntropyLoss, softmaxCrossEntropyLoss, softmaxCrossEntropyLoss, softmaxCrossEntropyLoss, updateAccumulator, updateAccumulators
Methods inherited from class ai.djl.training.evaluator.Evaluator
checkLabelShapes, checkLabelShapes, getName
-
Method Details
-
getPresetAnchors
public static float[] getPresetAnchors()Gets the preset anchors of YoloV3.- Returns:
- the preset anchors of YoloV3
-
clipByTensor
Make the value of given NDArray between tMin and tMax.- Parameters:
tList
- the given NDArraytMin
- the min valuetMax
- the max value- Returns:
- a NDArray where values are set between tMin and tMax
-
mseLoss
Calculates the MSELoss between prediction and target.- Parameters:
prediction
- the prediction arraytarget
- the target array- Returns:
- the MSELoss between prediction and target
-
bceLoss
Calculates the BCELoss between prediction and target.- Parameters:
prediction
- the prediction arraytarget
- the target array- Returns:
- the BCELoss between prediction and target
-
evaluate
Calculates the evaluation between the labels and the predictions. -
evaluateOneOutput
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 YOLOv3labels
- target labels. Must contain (offsetLabels, masks, classlabels)- Returns:
- the total loss of a outputLayer
-
getTarget
Gets target NDArray for a given evaluator.- Parameters:
labels
- the true labelsinH
- the height of current layerinW
- the width of current layer- Returns:
- an NDList of {boxLossScale and groundTruth}
-
calculateIOU
Calculates the IOU between priori Anchors and groundTruth.- Parameters:
predx
- the tx value of predictionpredy
- the ty value of predictiongroundTruth
- the groundTruth value of labelscomponentIndex
- the current component Index- Returns:
- an NDArray of IOU
-
builder
Creates a new builder to build aYOLOv3Loss
.- Returns:
- a new builder;
-