Class LayerBlock

java.lang.Object
smile.deep.layer.LayerBlock
All Implemented Interfaces:
Function<Tensor,Tensor>, Layer
Direct Known Subclasses:
EfficientNet, FusedMBConv, MBConv, SequentialBlock, SqueezeExcitation, Transformer

public abstract class LayerBlock extends Object implements Layer
A block is combinations of one or more layers. Blocks form the basis of more complex network designs. LayerBlock allows treating the whole container as a single layer, such that performing a transformation on the LayerBlock applies to each of the layers it contains (which are each a registered submodule of the block).
  • Field Details

    • module

      protected final org.bytedeco.pytorch.Module module
      The neural network module.
    • device

      protected Device device
      The compute device.
    • dtype

      protected ScalarType dtype
      The data type.
  • Constructor Details

    • LayerBlock

      public LayerBlock()
      Constructor.
    • LayerBlock

      public LayerBlock(String name)
      Constructor.
      Parameters:
      name - the module name.
    • LayerBlock

      public LayerBlock(org.bytedeco.pytorch.Module module)
      Constructor.
      Parameters:
      module - a module.
  • Method Details

    • asTorch

      public org.bytedeco.pytorch.Module asTorch()
      Description copied from interface: Layer
      Returns the PyTorch Module object.
      Specified by:
      asTorch in interface Layer
      Returns:
      the PyTorch Module object.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • add

      public LayerBlock add(String name, Layer layer)
      Adds a sub-layer.
      Parameters:
      name - the name of sub-layer.
      layer - the sub-layer.
      Returns:
      this object.
    • add

      public LayerBlock add(String name, org.bytedeco.pytorch.Module layer)
      Adds a sub-layer.
      Parameters:
      name - the name of sub-layer.
      layer - the sub-layer.
      Returns:
      this object.
    • isTraining

      public boolean isTraining()
      Returns true if the layer block is in training mode.
      Returns:
      true if the layer block is in training mode.
    • train

      public void train()
      Sets the layer block in the training mode.
    • eval

      public void eval()
      Sets the layer block in the evaluation/inference mode.
    • device

      public Device device()
      Returns the compute device of module.
    • dtype

      public ScalarType dtype()
      Returns the compute device of module.
    • to

      public LayerBlock to(Device device)
      Description copied from interface: Layer
      Moves the layer block to a device.
      Specified by:
      to in interface Layer
      Parameters:
      device - the compute device.
    • to

      public LayerBlock to(Device device, ScalarType dtype)
      Description copied from interface: Layer
      Moves the layer block to a device.
      Specified by:
      to in interface Layer
      Parameters:
      device - the compute device.
      dtype - the data type.
    • load

      public void load(String path)
      Loads a checkpoint.
      Parameters:
      path - the checkpoint file path.
    • save

      public void save(String path)
      Serialize the layer block as a checkpoint.
      Parameters:
      path - the checkpoint file path.