Package deepboof

Interface Function<T extends Tensor>

All Known Subinterfaces:
ActivationReLU<T>, ActivationSigmoid<T>, ActivationTanH<T>, DFunction<T>, FunctionBatchNorm<T>, FunctionElementWiseMult<T>, FunctionLinear<T>, SpatialAveragePooling<T>, SpatialBatchNorm<T>, SpatialConvolve2D<T>, SpatialMaxPooling<T>, SpatialPooling<T>
All Known Implementing Classes:
ActivationReLU_F32, ActivationReLU_F64, ActivationSigmoid_F32, ActivationSigmoid_F64, ActivationTanH_F32, ActivationTanH_F64, BaseFunction, BaseSpatialWindow, ElementWiseFunction, FunctionBatchNorm_F32, FunctionBatchNorm_F64, FunctionElementWiseMult_F32, FunctionElementWiseMult_F64, FunctionLinear_F32, FunctionLinear_F64, SpatialAveragePooling_F32, SpatialAveragePooling_F64, SpatialBatchNorm_F32, SpatialBatchNorm_F64, SpatialConvolve2D_F32, SpatialConvolve2D_F64, SpatialMaxPooling_F32, SpatialMaxPooling_F64, SpatialWindowChannel, SpatialWindowImage

public interface Function<T extends Tensor>

High level interface for functions in an Artificial Neural Network. This interface only defines the the operations in the forwards pass. When learning a network the gradient is typically needed and those additional operations can be found in DFunction, which extends this interface.

Forwards only implementations potentially have a lower memory foot print, faster specialized implementations, more simplistic implementations.

  • Method Summary

    Modifier and Type Method Description
    void forward​(T input, T output)
    Performs forward pass of the function on the provided inputs.
    int[] getOutputShape()
    Returns the output tensor's shape, without the mini-batch dimension.
    java.util.List<T> getParameters()
    If the parameters have been set, then this returns the list of parameters.
    java.util.List<int[]> getParameterShapes()
    Returns the shape of input tensors, without the mini-batch dimension.
    java.lang.Class<T> getTensorType()
    Returns the type of tensor it can process
    void initialize​(int... shapeInput)
    Initializes internal data structures given the shape of the input tensor, minus the stacked input dimension.
    void setParameters​(java.util.List<T> parameters)
    Specifies learnable function parameters, e.g.
  • Method Details

    • initialize

      void initialize​(int... shapeInput)
      Initializes internal data structures given the shape of the input tensor, minus the stacked input dimension. For example, an input tensor of shape (B,C,D) might be passed into initialize, while the actual input is (N,B,C,D). N is the number of stacked inputs and is allowed to vary after initialization.
      Parameters:
      shapeInput - Shape of the input tensor
      Throws:
      java.lang.IllegalArgumentException - If input tensor shapes are not valid
    • setParameters

      void setParameters​(java.util.List<T> parameters)

      Specifies learnable function parameters, e.g. weights for linear functions. This function only needs to be called once each time a parameter has been modified. Must be called before forward(T, T).

      NOTE: Reference to the parameters may be saved internally and the tensors should not be modified externally.
      Parameters:
      parameters - Tensors containing parameters which are optimized. Not modified.
    • getParameters

      java.util.List<T> getParameters()
      If the parameters have been set, then this returns the list of parameters. Otherwise null is returned.
      Returns:
      List of parameters or null if they have not been set yet
    • forward

      void forward​(T input, T output)
      Performs forward pass of the function on the provided inputs.
       Input tensor shape = (N,variable ... )
       - N is the mini-batch size
       - Other dimensions are implementation specific.
       
      Parameters:
      input - Input to the function.
      output - Output tensor. Modified.
    • getParameterShapes

      java.util.List<int[]> getParameterShapes()
      Returns the shape of input tensors, without the mini-batch dimension. Only valid after initialize(int...) has been called.
      Returns:
      Expected shapes of input tensors. This data structure may be recycled and is modified on the next call to initialize(int...).
    • getOutputShape

      int[] getOutputShape()
      Returns the output tensor's shape, without the mini-batch dimension. Only valid after initialize(int...) has been called.
      Returns:
      Expected shape of output tensor. This data structure may be recycled and is modified on the next call to initialize(int...).
    • getTensorType

      java.lang.Class<T> getTensorType()
      Returns the type of tensor it can process
      Returns:
      Type of tensor