Interface DnnModel

All Superinterfaces:
AutoCloseable
All Known Implementing Classes:
AbstractDnnModel, OpenCVDnn

public interface DnnModel extends AutoCloseable
General interface for implementing a deep learning model in a pipeline using OpenCV.

It can encapsulate a custom method needed to convert the input Mat(s) into the appropriate format, and the output back into one or more Mats.

Implementations should provide convenience methods to both convert and predict for three common scenarios:

  • Single input, single output; batch size 1
  • Single or multiple inputs, single or multiple outputs; batch size 1
  • Single input, single output; batch size > 1

If only a single input and output are required, then only predict(Mat) needs to be implemented.

Note: This was originally implemented in QuPath v0.3.0, but simplified for QuPath v0.5.0. It no longer takes a generic parameter or requires 'blob' and 'prediction' functions to be defined. This makes it easier to implement, and also to handle memory management. If you want the old behavior, see AbstractDnnModel.

Since:
0.5.0
Author:
Pete Bankhead
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Default input layer name.
    static final String
    Default output layer name.
  • Method Summary

    Modifier and Type
    Method
    Description
    default List<Mat>
    batchPredict(List<? extends Mat> mats)
    Prediction function that can take a batch of inputs and gives a corresponding batch of outputs.
    default void
    Close this model if it will not be needed again.
    Prediction function that can take multiple inputs.
    default Mat
    predict(Mat mat)
    Prediction function that takes a single input and gives a single output.
  • Field Details

    • DEFAULT_INPUT_NAME

      static final String DEFAULT_INPUT_NAME
      Default input layer name. This should be used when the input layer name is known or unimportant (e.g. the common case of a single input).
      See Also:
    • DEFAULT_OUTPUT_NAME

      static final String DEFAULT_OUTPUT_NAME
      Default output layer name. This should be used when the output layer name is known or unimportant (e.g. the common case of a single output).
      See Also:
  • Method Details

    • predict

      Map<String,Mat> predict(Map<String,Mat> blobs)
      Prediction function that can take multiple inputs.
      Parameters:
      blobs -
      Returns:
    • predict

      default Mat predict(Mat mat)
      Prediction function that takes a single input and gives a single output.
      Parameters:
      mat -
      Returns:
    • batchPredict

      default List<Mat> batchPredict(List<? extends Mat> mats)
      Prediction function that can take a batch of inputs and gives a corresponding batch of outputs. Each input is expected to have a single output.
      Parameters:
      mats -
      Returns:
    • close

      default void close() throws Exception
      Close this model if it will not be needed again. Subclasses that require cleanup may override this. The default implementation does nothing.
      Specified by:
      close in interface AutoCloseable
      Throws:
      Exception