Show / Hide Table of Contents

Class Sequential

The Sequential model is a linear stack of layers. Use model to add layers with Add method. Train function to train the layers with dataset. Predict function to invoke prediction against new data.

Inheritance
System.Object
Sequential
Namespace: SiaNet
Assembly: SiaNet.dll
Syntax
public class Sequential

Constructors

| Improve this Doc View Source

Sequential()

Initializes a new instance of the Sequential class.

Declaration
public Sequential()

Properties

| Improve this Doc View Source

Layers

Stach of layers for this model

Declaration
public List<BaseLayer> Layers { get; set; }
Property Value
Type Description
System.Collections.Generic.List<BaseLayer>

The layers.

| Improve this Doc View Source

LearningHistory

Gets or sets the learning history.

Declaration
public History LearningHistory { get; set; }
Property Value
Type Description
History

The learning history.

Methods

| Improve this Doc View Source

Add(BaseLayer)

Function to add layer to the sequential model.

Example use:

var model = new Sequential();
model.EpochEnd += Model_EpochEnd;
model.Add(new Dense(100, ActType.ReLU));
model.Add(new Dense(50, ActType.ReLU));
model.Add(new Dense(1, ActType.Sigmoid));

Declaration
public void Add(BaseLayer l)
Parameters
Type Name Description
BaseLayer l

The l.

| Improve this Doc View Source

Compile(OptimizerType, LossType, MetricType)

Before training a model, you need to configure the learning process, which is done via the compile method. It receives three arguments:

1. An optimizer.This could be the OptimizerType enum or an instance of the Optimizer class.

2. A loss function.This is the objective that the model will try to minimize. It can be the LossType enum identifier of an existing loss function (such as CategoricalCrossentropy or MeanSquaredError), or it can be an instance of the loss class.

3. A metric function.For any classification problem you will want the Accuracy of model. A metric could be the MetricType enum or instance of metric class.

Declaration
public void Compile(OptimizerType optimizer, LossType loss, MetricType metric)
Parameters
Type Name Description
OptimizerType optimizer

The optimizer type.

LossType loss

The loss type.

MetricType metric

The metric type.

| Improve this Doc View Source

Compile(BaseOptimizer, LossType, MetricType)

Before training a model, you need to configure the learning process, which is done via the compile method. It receives three arguments:

1. An optimizer.This could be the OptimizerType enum or an instance of the Optimizer class.

2. A loss function.This is the objective that the model will try to minimize. It can be the LossType enum identifier of an existing loss function (such as CategoricalCrossentropy or MeanSquaredError), or it can be an instance of the loss class.

3. A metric function.For any classification problem you will want the Accuracy of model. A metric could be the MetricType enum or instance of metric class.

Declaration
public void Compile(BaseOptimizer optimizer, LossType loss, MetricType metric)
Parameters
Type Name Description
BaseOptimizer optimizer

The optimizer instance.

LossType loss

The loss type.

MetricType metric

The metric type.

| Improve this Doc View Source

LoadModel(String)

Loads the model from the saved json to the Sequential model instance.

Declaration
public static Sequential LoadModel(string filePath)
Parameters
Type Name Description
System.String filePath

The file path.

Returns
Type Description
Sequential
| Improve this Doc View Source

OnBatchEnd(Int32, Int32, Single, Single)

Called when [batch end].

Declaration
protected void OnBatchEnd(int epoch, int batch, float loss, float metric)
Parameters
Type Name Description
System.Int32 epoch

The epoch.

System.Int32 batch

The batch.

System.Single loss

The loss.

System.Single metric

The metric.

| Improve this Doc View Source

OnBatchStart(Int32, Int32)

Called when [batch start].

Declaration
protected void OnBatchStart(int epoch, int batch)
Parameters
Type Name Description
System.Int32 epoch

The epoch.

System.Int32 batch

The batch.

| Improve this Doc View Source

OnEpochEnd(Int32, Int64, Single, Single, Single, Single, Int64)

Called when [epoch end].

Declaration
protected void OnEpochEnd(int epoch, long samplesSeenPerSec, float loss, float validationLoss, float metric, float validationMetric, long duration)
Parameters
Type Name Description
System.Int32 epoch

The epoch.

System.Int64 samplesSeenPerSec

The samples seen per sec.

System.Single loss

The loss.

System.Single validationLoss

The validation loss.

System.Single metric

The metric.

System.Single validationMetric

The validation metric.

System.Int64 duration

The duration.

| Improve this Doc View Source

OnEpochStart(Int32)

Called when [epoch start].

Declaration
protected void OnEpochStart(int epoch)
Parameters
Type Name Description
System.Int32 epoch

The epoch.

| Improve this Doc View Source

OnTrainingEnd(History, Int64)

Called when [training end].

Declaration
protected void OnTrainingEnd(History history, long duration)
Parameters
Type Name Description
History history

The history.

System.Int64 duration

The duration.

| Improve this Doc View Source

Predict(DataFrame)

Generates output predictions for the input samples.

Declaration
public Tensor Predict(DataFrame x)
Parameters
Type Name Description
DataFrame x

The input data frame to run prediction.

Returns
Type Description
Tensor
| Improve this Doc View Source

Predict(DataFrame, Int32)

Generates output predictions for the input samples. Computation is done in batches.

Declaration
public Tensor Predict(DataFrame x, int batch_size)
Parameters
Type Name Description
DataFrame x

The input data frame to run prediction.

System.Int32 batch_size

Size of the batch.

Returns
Type Description
Tensor
| Improve this Doc View Source

SaveModel(String)

Saves the model in json format to the file path.

Declaration
public void SaveModel(string filePath)
Parameters
Type Name Description
System.String filePath

The file path.

| Improve this Doc View Source

Train(DataFrameIter, Int32, Int32, DataFrameIter)

Trains the model for a given number of epochs (iterations on a dataset).

Declaration
public void Train(DataFrameIter train, int epochs, int batchSize, DataFrameIter val = null)
Parameters
Type Name Description
DataFrameIter train

The train dataset which is an instance of DataFrame Iter.

System.Int32 epochs

Integer. Number of epochs to train the model. An epoch is an iteration over the entire x and y data provided. Note that in conjunction with initial_epoch, epochs is to be understood as "final epoch". The model is not trained for a number of iterations given by epochs, but merely until the epoch of index epochs is reached.

System.Int32 batchSize

Integer or None. Number of samples per gradient update. If unspecified, batch_size will default to 32.

DataFrameIter val

The validation set of data to evaluate the model at every epoch.

Events

| Improve this Doc View Source

BatchEnd

Occurs when [batch end].

Declaration
public event EventHandler<BatchEndEventArgs> BatchEnd
Event Type
Type Description
System.EventHandler<BatchEndEventArgs>
| Improve this Doc View Source

BatchStart

Occurs when [on batch start].

Declaration
public event EventHandler<BatchStartEventArgs> BatchStart
Event Type
Type Description
System.EventHandler<BatchStartEventArgs>
| Improve this Doc View Source

EpochEnd

Occurs when [on epoch end].

Declaration
public event EventHandler<EpochEndEventArgs> EpochEnd
Event Type
Type Description
System.EventHandler<EpochEndEventArgs>
| Improve this Doc View Source

EpochStart

Occurs when [on epoch start].

Declaration
public event EventHandler<EpochStartEventArgs> EpochStart
Event Type
Type Description
System.EventHandler<EpochStartEventArgs>
| Improve this Doc View Source

TrainingEnd

Occurs when [on training end].

Declaration
public event EventHandler<TrainingEndEventArgs> TrainingEnd
Event Type
Type Description
System.EventHandler<TrainingEndEventArgs>
  • Improve this Doc
  • View Source
Back to top Generated by DocFX