Class LinearLayer

java.lang.Object
smile.deep.layer.ModuleLayer
smile.deep.layer.LinearLayer
All Implemented Interfaces:
AutoCloseable, Function<Tensor,Tensor>, Layer, LinearOp

public class LinearLayer extends ModuleLayer implements LinearOp
A fully connected linear layer.
  • Constructor Details

    • LinearLayer

      public LinearLayer(int in, int out)
      Constructor.
      Parameters:
      in - the number of input features.
      out - the number of output features.
    • LinearLayer

      public LinearLayer(int in, int out, boolean bias)
      Constructor.
      Parameters:
      in - the number of input features.
      out - the number of output features.
      bias - If false, the layer will not learn an additive bias.
  • Method Details

    • gemm

      public static LinearLayer gemm(int in, int out, boolean bias)
      A linear layer for a projection that a quantized backend may replace: identical to the constructor, except inside ParameterInit.placeholderGemms() where only a 1x1 placeholder is allocated.
      Parameters:
      in - the number of input features.
      out - the number of output features.
      bias - whether the layer has a bias.
      Returns:
      the layer.
    • forward

      public Tensor forward(Tensor input)
      Description copied from interface: Layer
      Forward propagation (or forward pass) through the layer.
      Specified by:
      forward in interface Layer
      Specified by:
      forward in interface LinearOp
      Parameters:
      input - the input tensor.
      Returns:
      the output tensor.
    • weight

      public Tensor weight()
      The weight [out, in] as an alias of the module parameter (shares storage; do not close it before the layer is done with).
      Returns:
      the weight, or null when the native binding is unavailable.