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
-
public final class YOLOv3Loss extends Loss
YOLOv3Lossis an implementation ofLoss. 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 Modifier and Type Class Description static classYOLOv3Loss.BuilderThe Builder to construct aYOLOv3Lossobject.
-
Field Summary
-
Fields inherited from class ai.djl.training.evaluator.Evaluator
totalInstances
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description NDArraybceLoss(NDArray prediction, NDArray target)Calculates the BCELoss between prediction and target.static YOLOv3Loss.Builderbuilder()Creates a new builder to build aYOLOv3Loss.NDArraycalculateIOU(NDArray predx, NDArray predy, NDArray groundTruth, int componentIndex)Calculates the IOU between priori Anchors and groundTruth.NDArrayclipByTensor(NDArray tList, float tMin, float tMax)Make the value of given NDArray between tMin and tMax.NDArrayevaluate(NDList labels, NDList predictions)Calculates the evaluation between the labels and the predictions.NDArrayevaluateOneOutput(int componentIndex, NDArray input, NDArray labels)Computes the Loss for one outputLayer.static float[]getPresetAnchors()Gets the preset anchors of YoloV3.NDListgetTarget(NDArray labels, int inH, int inW)Gets target NDArray for a given evaluator.NDArraymseLoss(NDArray prediction, NDArray target)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
-
Methods inherited from class ai.djl.training.evaluator.Evaluator
checkLabelShapes, checkLabelShapes, getName
-
-
-
-
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 NDArraytMin- the min valuetMax- 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 arraytarget- 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 arraytarget- 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.
-
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 YOLOv3labels- 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 labelsinH- the height of current layerinW- 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 predictionpredy- the ty value of predictiongroundTruth- the groundTruth value of labelscomponentIndex- the current component Index- Returns:
- an NDArray of IOU
-
builder
public static YOLOv3Loss.Builder builder()
Creates a new builder to build aYOLOv3Loss.- Returns:
- a new builder;
-
-