Class Model

Definition

Namespace:
Tizen.MachineLearning.Train
Assembly:
Tizen.MachineLearning.Train.dll
API Level:
10
Feature:
http://tizen.org/feature/machine_learning.training

Constructs the neural network model

C#
Copy
public class Model : IDisposable
Inheritance
System.Object
Model
Implements
System.IDisposable
Remarks

Use this class to create neural network model. The Model class provides interfaces to construct, complle, run, adding layer and etc with neural networks. If you want to access only internal storage by using this method, you should add privilege %http://tizen.org/privilege/mediastorage. Or, if you want to access only external storage by using this method, you should add privilege %http://tizen.org/privilege/externalstorage. If you want to access both storage, you must add all the privileges.

Constructors

View Source

Model()

Constructs the neural network model.

Declaration
C#
Copy
public Model()
Exceptions
Type Condition
System.NotSupportedException

Thrown when the feature is not supported.

System.ArgumentException

Thrown when the method failed due to an invalid parameter.

UnauthorizedAccessException

Thrown when the application does not have the required privilege.

System.InvalidOperationException

Thrown when the method failed due to the wrong pipeline description or internal error.

API Level: 10
View Source

Model(String)

Constructs the neural network model with the given configuration file.

Declaration
C#
Copy
public Model(string modelConf)
Parameters
Type Name Description
System.String modelConf

The nntrainer model configuration file.

Exceptions
Type Condition
System.NotSupportedException

Thrown when the feature is not supported.

System.ArgumentException

Thrown when the method failed due to an invalid parameter.

UnauthorizedAccessException

Thrown when the application does not have the required privilege.

System.InvalidOperationException

Thrown when the method failed due to the wrong pipeline description or internal error.

API Level: 10

Methods

View Source

AddLayer(Layer)

Adds layer in neural network model.

Declaration
C#
Copy
public void AddLayer(Layer layer)
Parameters
Type Name Description
Layer layer

The instance of Layer class

Remarks

Use this method to add a layer to the model. The layer is added to the end of the existing layers in the model. This transfers the ownership of the layer to the network. No need to destroy the layer once it is added to a model. Layer is available until the model is released, so Dispose() must never be used.

Exceptions
Type Condition
System.NotSupportedException

Thrown when the feature is not supported.

System.ArgumentException

Thrown when the method failed due to an invalid parameter.

UnauthorizedAccessException

Thrown when the application does not have the required privilege.

System.InvalidOperationException

Thrown when the method failed due to the wrong pipeline description or internal error.

API Level: 10
View Source

Compile(String[])

Compiles and finalizes the neural network model with the hyperparameter.

Declaration
C#
Copy
public void Compile(params string[] hyperparameter)
Parameters
Type Name Description
System.String[] hyperparameter
Remarks

Use this method to initialize neural network model.Various hyperparameter can be set before compile the model. Once compiled, any modification to the properties of model or layers/dataset/optimizer in the model will be restricted. Further, addition of layers or changing the optimizer/dataset of the model will not be permitted. The input format of hyperparameter must be 'key = value' format. Hyperparameter for train complie.

Exceptions
Type Condition
System.NotSupportedException

Thrown when the feature is not supported.

System.ArgumentException

Thrown when the method failed due to an invalid parameter.

UnauthorizedAccessException

Thrown when the application does not have the required privilege.

System.InvalidOperationException

Thrown when the method failed due to the wrong pipeline description or internal error.

API Level: 10
View Source

Dispose()

Releases any unmanaged resources used by this object.

Declaration
C#
Copy
public void Dispose()
Exceptions
Type Condition
System.NotSupportedException

Thrown when the feature is not supported.

System.ArgumentException

Thrown when the method failed due to an invalid parameter.

UnauthorizedAccessException

Thrown when the application does not have the required privilege.

System.InvalidOperationException

Thrown when the method failed due to the wrong pipeline description or internal error.

API Level: 10
View Source

Dispose(Boolean)

Releases any unmanaged resources used by this object including opened handle.

Declaration
C#
Copy
protected virtual void Dispose(bool disposing)
Parameters
Type Name Description
Boolean disposing

If true, disposes any disposable objects. If false, does not dispose disposable objects.

Exceptions
Type Condition
System.NotSupportedException

Thrown when the feature is not supported.

System.ArgumentException

Thrown when the method failed due to an invalid parameter.

UnauthorizedAccessException

Thrown when the application does not have the required privilege.

System.InvalidOperationException

Thrown when the method failed due to the wrong pipeline description or internal error.

API Level: 10
View Source

Finalize()

Destructor of Model

Declaration
C#
Copy
protected void Finalize()
Exceptions
Type Condition
System.NotSupportedException

Thrown when the feature is not supported.

System.ArgumentException

Thrown when the method failed due to an invalid parameter.

UnauthorizedAccessException

Thrown when the application does not have the required privilege.

System.InvalidOperationException

Thrown when the method failed due to the wrong pipeline description or internal error.

API Level: 10
View Source

GetInputTensorsInfo()

Gets input tensors information of the model.

Declaration
C#
Copy
public TensorsInfo GetInputTensorsInfo()
Returns
Type Description
TensorsInfo

TensorsInfo instance

Remarks

Use this method to get input tensors information of the model. Model must be compiled before calling this method.

Exceptions
Type Condition
System.NotSupportedException

Thrown when the feature is not supported.

System.ArgumentException

Thrown when the method failed due to an invalid parameter.

UnauthorizedAccessException

Thrown when the application does not have the required privilege.

System.InvalidOperationException

Thrown when the method failed due to the wrong pipeline description or internal error.

API Level: 10
View Source

GetLayer(String)

Gets neural network layer from the model with the given name.

Declaration
C#
Copy
public Layer GetLayer(string layerName)
Parameters
Type Name Description
System.String layerName

Name of the already created layer.

Returns
Type Description
Layer

layer instance

Remarks

Use this method to get already created Neural Network Layer. The returned layer must not be deleted as it is owned by the model. layerName can be set by SetProperty method of Layer. Returned layer instance is different with same layerName, but internally the native layer handle is same.

Exceptions
Type Condition
System.NotSupportedException

Thrown when the feature is not supported.

System.ArgumentException

Thrown when the method failed due to an invalid parameter.

UnauthorizedAccessException

Thrown when the application does not have the required privilege.

System.InvalidOperationException

Thrown when the method failed due to the wrong pipeline description or internal error.

API Level: 10
View Source

GetOutputTensorsInfo()

Gets output tensors information of the model.

Declaration
C#
Copy
public TensorsInfo GetOutputTensorsInfo()
Returns
Type Description
TensorsInfo

TensorsInfo instance

Remarks

Use this method to get output tensors information of the model. Model must be compiled before calling this method.

Exceptions
Type Condition
System.NotSupportedException

Thrown when the feature is not supported.

System.ArgumentException

Thrown when the method failed due to an invalid parameter.

UnauthorizedAccessException

Thrown when the application does not have the required privilege.

System.InvalidOperationException

Thrown when the method failed due to the wrong pipeline description or internal error.

API Level: 10
View Source

GetSummary(NNTrainerSummaryType)

Gets the summary of the neural network model.

Declaration
C#
Copy
public string GetSummary(NNTrainerSummaryType verbosity)
Parameters
Type Name Description
NNTrainerSummaryType verbosity

Verbose level of the summary.

Returns
Type Description
System.String

On return, a string value. The summary of the current model. Avoid logic to parse and exploit summary if possible.

Exceptions
Type Condition
System.NotSupportedException

Thrown when the feature is not supported.

System.ArgumentException

Thrown when the method failed due to an invalid parameter.

UnauthorizedAccessException

Thrown when the application does not have the required privilege.

System.InvalidOperationException

Thrown when the method failed due to the wrong pipeline description or internal error.

API Level: 10
View Source

Load(String, NNTrainerModelFormat)

Loads the model.

Declaration
C#
Copy
public void Load(string filePath, NNTrainerModelFormat format)
Parameters
Type Name Description
System.String filePath

File path to load the file.

NNTrainerModelFormat format

Format flag to determine which format should be used to load.

Remarks

Use this method to load the current model. Format describes various formats in which various selections of the parameters of the models can be loaded. Some formats may load parameters required for training. Some other formats may load model configurations. Unless stated otherwise, loading model configuration requires a freshly constructed model with new Model() without Compile(String[]), loading model parameter requires Compile() to be called upon the model before calling this method. If you want to access only internal storage by using this method, you should add privilege %http://tizen.org/privilege/mediastorage. Or, if you want to access only external storage by using this method, you should add privilege %http://tizen.org/privilege/externalstorage. If you want to access both storage, you must add all the privileges.

Exceptions
Type Condition
System.NotSupportedException

Thrown when the feature is not supported.

System.ArgumentException

Thrown when the method failed due to an invalid parameter.

UnauthorizedAccessException

Thrown when the application does not have the required privilege.

System.InvalidOperationException

Thrown when the method failed due to the wrong pipeline description or internal error.

API Level: 10
View Source

Run(String[])

Trains the neural network model with the hyperparameter.

Declaration
C#
Copy
public void Run(params string[] hyperparameter)
Parameters
Type Name Description
System.String[] hyperparameter

Hyperparameters for train model.

Remarks

Use this method to train the compiled neural network model with the passed training hyperparameters. This method will return once the training, along with requested validation and testing, is completed. The input format of hyperparameter must be 'key = value' format.

Exceptions
Type Condition
System.NotSupportedException

Thrown when the feature is not supported.

System.ArgumentException

Thrown when the method failed due to an invalid parameter.

UnauthorizedAccessException

Thrown when the application does not have the required privilege.

System.InvalidOperationException

Thrown when the method failed due to the wrong pipeline description or internal error.

API Level: 10
View Source

Save(String, NNTrainerModelFormat)

Saves the model.

Declaration
C#
Copy
public void Save(string filePath, NNTrainerModelFormat format)
Parameters
Type Name Description
System.String filePath

File path to save the file.

NNTrainerModelFormat format

Format flag to determine which format should be used to save.

Remarks

Use this method to save the current model. Format describes various formats in which various selections of the parameters of the models can be saved. Some formats may save parameters required for training. Some other formats may save model configurations. Unless stated otherwise, Compile(String[]) has to be called upon the a model before calling this method. Saved ini, if any, is not guaranteed to be identical to the original ini that might have been used to load the model. If you want to access only internal storage by using this method, you should add privilege %http://tizen.org/privilege/mediastorage. Or, if you want to access only external storage by using this method, you should add privilege %http://tizen.org/privilege/externalstorage. If you want to access both storage, you must add all the privileges.

Exceptions
Type Condition
System.NotSupportedException

Thrown when the feature is not supported.

System.ArgumentException

Thrown when the method failed due to an invalid parameter.

UnauthorizedAccessException

Thrown when the application does not have the required privilege.

System.InvalidOperationException

Thrown when the method failed due to the wrong pipeline description or internal error.

API Level: 10
View Source

SetDataset(Dataset)

Sets the dataset (data provider) for the neural network model.

Declaration
C#
Copy
public void SetDataset(Dataset dataset)
Parameters
Type Name Description
Dataset dataset

The instance of Dataset class

Remarks

Use this method to set dataset for running the model. The dataset will provide training, validation and test data for the model. This transfers the ownership of the dataset to the network. No need to destroy the dataset once it is set to a model. Unsets the previously set dataset, if any. The previously set dataset must be freed using Dispose().

Exceptions
Type Condition
System.NotSupportedException

Thrown when the feature is not supported.

System.ArgumentException

Thrown when the method failed due to an invalid parameter.

UnauthorizedAccessException

Thrown when the application does not have the required privilege.

System.InvalidOperationException

Thrown when the method failed due to the wrong pipeline description or internal error.

API Level: 10
View Source

SetOptimizer(Optimizer)

Sets the optimizer for the neural network model.

Declaration
C#
Copy
public void SetOptimizer(Optimizer optimizer)
Parameters
Type Name Description
Optimizer optimizer

The instance of Optimizer class

Remarks

Use this method to set neural network optimizer. This transfers the ownership of the optimizer to the network. No need to destroy the optimizer if it is added to a model.

Exceptions
Type Condition
System.NotSupportedException

Thrown when the feature is not supported.

System.ArgumentException

Thrown when the method failed due to an invalid parameter.

UnauthorizedAccessException

Thrown when the application does not have the required privilege.

System.InvalidOperationException

Thrown when the method failed due to the wrong pipeline description or internal error.

API Level: 10

Implements

System.IDisposable