Class AbstractDnnModel<T>

java.lang.Object
qupath.opencv.dnn.AbstractDnnModel<T>
Type Parameters:
T -
All Implemented Interfaces:
AutoCloseable, DnnModel
Direct Known Subclasses:
OpenCVDnn

public abstract class AbstractDnnModel<T> extends Object implements DnnModel
Wrapper for 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.

This provides 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
Author:
Pete Bankhead
See Also:
  • Constructor Details

    • AbstractDnnModel

      public AbstractDnnModel()
  • Method Details

    • getBlobFunction

      public abstract BlobFunction<T> getBlobFunction()
      Get the function that can convert one or more OpenCV Mats into a blob supported by the prediction function for the first (or only) input.
      Returns:
    • getBlobFunction

      public abstract BlobFunction<T> getBlobFunction(String name)
      Get the function that can convert one or more OpenCV Mats into a blob supported by the prediction function for a specified input layer.
      Parameters:
      name -
      Returns:
    • getPredictionFunction

      public abstract PredictionFunction<T> getPredictionFunction()
      Get the prediction function that can apply a prediction with one or more blobs as input.
      Returns:
    • predict

      public Map<String,Mat> predict(Map<String,Mat> blobs)
      Convenience method to convert input image patches to a blobs, apply a PredictionFunction (optionally with multiple inputs/outputs), and convert the output to a standard Mat.

      Note that this only supports a batch size of 1. For larger batches or more control, getBlobFunction(String) and getPredictionFunction() should be used directly.

      Specified by:
      predict in interface DnnModel
      Parameters:
      blobs -
      Returns:
    • predict

      public Mat predict(Mat mat)
      Convenience method to convert a single image patch to a blob, apply the PredictionFunction, and convert the output to a standard Mat.

      Note that this only supports a batch size of 1. For larger batches or more control, getBlobFunction(String) and getPredictionFunction() should be used directly.

      Specified by:
      predict in interface DnnModel
      Parameters:
      mat -
      Returns:
    • batchPredict

      public List<Mat> batchPredict(List<? extends Mat> mats)
      Convenience method to convert one or more image patches to a blob, apply the PredictionFunction, and convert the output to standard Mats. This method is intended for cases where the batch size should be greater than one; for a batch size of one, predict(Mat) can be used instead.
      Specified by:
      batchPredict in interface DnnModel
      Parameters:
      mats -
      Returns: