NeuralNetwork class
Neural Network class
Constructor parameters
inputLenght
- Lenght of the input data Listlayers
- List of Layer with lenght >= 1loss
- Loss function to minimizeoptimizer
- optional parameter, Optimizer for the NeuralNetworkname
- optional parameter, name of the NeuralNetworkuseAccuracyMetric
- optional parameter, add accuracy metric computation while fitting (learning) or evaluating (testing). Can be used only for classsification tasks, with both One-Hot encoded and labeled target class representation.
Example
NeuralNetwork nnClasses = NeuralNetwork(784, // input length of 28 by 28 image
[
LayerNormalization(), // preprocess normalization of data records
Dense(128, activation: Activation.elu()), // 1st hidden layer
Dense(32, activation: Activation.leakyReLU()), // 2nd hidden layer
// ...
LayerNormalization(),
Dense(10, activation: Activation.softmax()) // output layer for ten classes
],
loss: Loss.mse(), /// for sparse can be [Loss.sparseCrossEntropy()]
optimizer: SGD(learningRate: 0.05, momentum: 0.99),
useAccuracyMetric: true) /// set [true] to compute classififcation accuracy
NeuralNetwork nnRegression = NeuralNetwork(10, // input length of customer features
[
Dense(32, activation: Activation.elu()), // hidden layer
LayerNormalization()
Dense(1, activation: Activation.softmax()) // output layer
],
loss: Loss.mae(),
optimizer: SGD(learningRate: 0.3, momentum: 0),
useAccuracyMetric: false) /// use [false] for regression tasks
Constructors
-
NeuralNetwork(int inputLength, List<
Layer> layers, {required Loss loss, Optimizer? optimizer, String? name, bool useAccuracyMetric = false}) -
inputLenght
- Lenght of the input data Listlayers
- List of Layer with lenght >= 1loss
- Loss function to minimizeoptimizer
- optional parameter, Optimizer for the NeuralNetworkname
- optional parameter, name of the NeuralNetworkuseAccuracyMetric
- optional parameter, add accuracy metric computation while fitting (learning) or evaluating (testing). Can be used only for classsification tasks, with both One-Hot encoded and labeled target class representation.
Properties
Methods
-
evaluate(
List< List< x, List<double> >List< y, {int batchSize = 1, bool verbose = true}) → Map<double> >String, double> - Call evaluating or testing process of this NeuralNetwork on the given batches
-
fit(
List< List< x, List<double> >List< y, {int epochs = 1, int batchSize = 1, bool verbose = false}) → Map<double> >String, List< ?double> > -
Call trainig (or fitting) process of this NeuralNetwork over given
x
andy
-
loadWeights(
String path, [SaveType type = SaveType.bin]) → void -
Load weights and biases of trainable layers of this NeuralNetwork from the
$path/model_weights.bin
file -
loadWeightsFromBytes(
ByteBuffer buffer) → void -
Load weights and biases of trainable layers of this NeuralNetwork from
buffer
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
predict(
List< List< inputs) → List<double> >List< double> > - Call prediction process for this NeuralNetwork on the given input data
-
saveWeights(
String path, [SaveType type = SaveType.bin]) → void -
Save weights and biases of trainable layers of this NeuralNetwork to the
$path/model_weights.bin
file -
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited