NeuralNetworkDsl
Core DSL interface for building neural networks with generic tensor types. This interface provides a fluent API for constructing neural network architectures with support for different data types and precision levels.
Parameters
The data type (DType) that determines the precision and storage format
The value type that corresponds to the native Kotlin type for the DType
Type constraints ensure compatibility between DType and value type:
T must extend DType to ensure valid tensor operations
V should match the native type expected by the DType implementation
Performance considerations:
FP32/Float: Best accuracy, higher memory usage
FP16/Float: Reduced memory, slightly lower accuracy
Int8/Byte: Minimal memory, quantized operations
Int32/Int: Integer operations, specific use cases
Inheritors
Functions
Creates a 2D convolutional layer with all parameters configured inside the DSL block. Example: conv2d("conv1") { outChannels = 16 kernelSize(5) stride(1) padding(2) }
Creates a 2D convolutional layer for processing spatial data like images.
Creates a 3D convolutional layer for processing volumetric data.
Creates a dense layer without specifying output dimension (must be set in content block).
Creates a dense layer with precision override without specifying output dimension.
Creates a dense (fully connected) layer with specified output dimension.
Creates a dense layer with precision override and specified output dimension. This allows individual layers to use different precision than the network default.
Creates a 2D max pooling layer with all parameters configured inside the DSL block. Example: maxPool2d("pool1") { kernelSize(2) stride(2) padding(0) }
Creates a 2D max pooling layer for downsampling feature maps.
Groups layers into a sequential block for better organization.
Creates a named stage/block within the network for modular design.
Creates a precision-scoped stage within the network. This allows grouping layers with a specific precision type that differs from the network default, enabling fine-grained mixed-precision control.
Creates a 2D upsampling layer with parameters configured in the DSL block.
Creates a 2D upsampling layer for increasing spatial resolution.