Class SimpleCompositeLoss


public class SimpleCompositeLoss extends AbstractCompositeLoss
SimpleCompositeLoss is an implementation of the Loss abstract class that can combine different Loss functions by adding the individual losses together.

For cases where the losses use only a single index of the labels and/or predictions, use the IndexLoss.

For an example of using this loss, see the captcha training example.

  • Constructor Details

    • SimpleCompositeLoss

      public SimpleCompositeLoss()
      Creates a new empty instance of CompositeLoss that can combine the given Loss components.
    • SimpleCompositeLoss

      public SimpleCompositeLoss(String name)
      Creates a new empty instance of CompositeLoss that can combine the given Loss components.
      Parameters:
      name - the display name of the loss
  • Method Details

    • addLoss

      public SimpleCompositeLoss addLoss(Loss loss)
      Adds a Loss that applies to all labels and predictions to this composite loss.
      Parameters:
      loss - the loss to add
      Returns:
      this composite loss
    • inputForComponent

      protected ai.djl.util.Pair<NDList,NDList> inputForComponent(int componentIndex, NDList labels, NDList predictions)
      Returns the inputs to computing the loss for a component loss.
      Specified by:
      inputForComponent in class AbstractCompositeLoss
      Parameters:
      componentIndex - the index of the component loss
      labels - the label input to the composite loss
      predictions - the predictions input to the composite loss
      Returns:
      a pair of the (labels, predictions) inputs to the component loss