Class DnnShape

java.lang.Object
qupath.opencv.dnn.DnnShape

public final class DnnShape extends Object
Helper class to represent input and output shapes associated with PredictionFunction. In general, the shape is expected to be in the format NCHW.

NCHW is used by OpenCV https://docs.opencv.org/4.5.2/d6/d0f/group__dnn.html#ga29f34df9376379a603acd8df581ac8d7 and also by PyTorch; for TensorFlow some rearrangement may be needed.

Note: NDCHW support may be added in the future, but is not currently supported.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static long
    Constant to represent an unknown dimension length.
    static DnnShape
    Constant to represent an unknown shape.
    static long
    Constant to represent an unknown size (i.e.
  • Method Summary

    Modifier and Type
    Method
    Description
    final long
    get(int i)
    Get the length of the specified dimension.
    final long[]
    Get a copy of the internal dimensions array.
    final boolean
    Returns true if the shape is unknown.
    final int
    The total number of dimensions, i.e.
    static DnnShape
    of(long... shape)
    Create a new DnnShape with the specified dimension lengths.
    final long
    Total number of elements in a blob with this shape This is the product of the lengths returned by getShape() or UNKNOWN_SHAPE.
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • UNKNOWN_SHAPE

      public static DnnShape UNKNOWN_SHAPE
      Constant to represent an unknown shape.
    • UNKNOWN_LENGTH

      public static long UNKNOWN_LENGTH
      Constant to represent an unknown dimension length.
    • UNKNOWN_SIZE

      public static long UNKNOWN_SIZE
      Constant to represent an unknown size (i.e. number of elements within a blob, mat or tensor).
  • Method Details

    • getShape

      public final long[] getShape()
      Get a copy of the internal dimensions array.
      Returns:
    • get

      public final long get(int i)
      Get the length of the specified dimension.
      Parameters:
      i -
      Returns:
    • of

      public static DnnShape of(long... shape)
      Create a new DnnShape with the specified dimension lengths.
      Parameters:
      shape -
      Returns:
    • numDimensions

      public final int numDimensions()
      The total number of dimensions, i.e. the length of the array returned by getShape().
      Returns:
    • isUnknown

      public final boolean isUnknown()
      Returns true if the shape is unknown.
      Returns:
    • size

      public final long size()
      Total number of elements in a blob with this shape This is the product of the lengths returned by getShape() or UNKNOWN_SHAPE.
      Returns:
    • toString

      public String toString()
      Overrides:
      toString in class Object