2 * Copyright (c) 2022 Samsung Electronics Co., Ltd. All Rights Reserved.
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 namespace Tizen.MachineLearning.Train
23 /// Constructs the neural network model
26 /// Use this function to create neural network model.
27 /// The Model class provides interfaces to construct, complle, run, adding layer
28 /// and etc with neural networks.
29 /// If you want to access only internal storage by using this function,
30 /// you should add privilege %http://tizen.org/privilege/mediastorage. Or, if you
31 /// want to access only external storage by using this function, you should add
32 /// privilege %http://tizen.org/privilege/externalstorage. If you want to access
33 /// both storage, you must add all the privileges.
35 /// <since_tizen> 10 </since_tizen>
36 public class Model: IDisposable
38 private IntPtr _handle = IntPtr.Zero;
39 private bool _disposed = false;
42 /// Constructs the neural network model.
44 /// <since_tizen> 10 </since_tizen>
47 NNTrainerError ret = Interop.Model.Construct(out _handle);
48 NNTrainer.CheckException(ret, "Failed to create model instance");
52 /// Constructs the neural network model with the given configuration file.
54 /// <param name="modelConf">The nntrainer model configuration file.</param>
55 /// <since_tizen> 10 </since_tizen>
56 public Model(string modelConf)
58 if (string.IsNullOrEmpty(modelConf))
59 NNTrainer.CheckException(NNTrainerError.InvalidParameter, "modelConf is null");
61 NNTrainerError ret = Interop.Model.ConstructWithConf(modelConf, out _handle);
62 NNTrainer.CheckException(ret, "Failed to create model instance with modelConf");
65 /// Destructor of Model
67 /// <since_tizen> 10 </since_tizen>
74 /// Releases any unmanaged resources used by this object.
76 /// <since_tizen> 10 </since_tizen>
80 GC.SuppressFinalize(this);
84 /// Releases any unmanaged resources used by this object including opened handle.
86 /// <param name="disposing">If true, disposes any disposable objects. If false, does not dispose disposable objects.</param>
87 /// <since_tizen> 10 </since_tizen>
88 protected virtual void Dispose(bool disposing)
94 // release managed object
97 // release unmanaged object
98 if (_handle != IntPtr.Zero)
100 // Destroy the neural network model.
101 NNTrainerError ret = Interop.Model.Destroy(_handle);
102 NNTrainer.CheckException(ret, "Failed to destroy model instance");
104 _handle = IntPtr.Zero;