--- /dev/null
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+internal static partial class Interop
+{
+ internal static partial class Libraries
+ {
+ public const string Nntrainer = "libcapi-nntrainer.so";
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.Runtime.InteropServices;
+using Tizen.MachineLearning.Train;
+
+internal static partial class Interop
+{
+ internal static partial class Model
+ {
+ /* typedef int ml_train_model_construct(ml_train_model_h *model) */
+ [DllImport(Libraries.Nntrainer, EntryPoint = "ml_train_model_construct")]
+ public static extern NNTrainerError Construct(out IntPtr model_handle);
+
+ /* typedef int ml_train_model_destroy(ml_train_model_h model) */
+ [DllImport(Libraries.Nntrainer, EntryPoint = "ml_train_model_destroy")]
+ public static extern NNTrainerError Destroy(IntPtr model_handle);
+ }
+}
--- /dev/null
+<Project Sdk="Microsoft.NET.Sdk">
+
+ <PropertyGroup>
+ <TargetFramework>netstandard2.0</TargetFramework>
+ </PropertyGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\Tizen.Log\Tizen.Log.csproj"/>
+ <ProjectReference Include="..\Tizen\Tizen.csproj"/>
+ <ProjectReference Include="..\Tizen.System.Information\Tizen.System.Information.csproj"/>
+ </ItemGroup>
+
+</Project>
--- /dev/null
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 16
+VisualStudioVersion = 16.0.30114.105
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tizen.MachineLearning.Train", "Tizen.MachineLearning.Train.csproj", "{EEC5226C-00A7-482A-956C-D81DB1CFE06A}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {EEC5226C-00A7-482A-956C-D81DB1CFE06A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {EEC5226C-00A7-482A-956C-D81DB1CFE06A}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {EEC5226C-00A7-482A-956C-D81DB1CFE06A}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {EEC5226C-00A7-482A-956C-D81DB1CFE06A}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+EndGlobal
--- /dev/null
+/*
+* Copyright (c) 2022 Samsung Electronics Co., Ltd. All Rights Reserved.
+*
+* Licensed under the Apache License, Version 2.0 (the License);
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an AS IS BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+using System;
+using System.IO;
+using Tizen.Internals.Errors;
+
+namespace Tizen.MachineLearning.Train
+{
+ internal enum NNTrainerError
+ {
+ None = ErrorCode.None,
+ InvalidParameter = ErrorCode.InvalidParameter,
+ StreamsPipe = ErrorCode.StreamsPipe,
+ TryAgain = ErrorCode.TryAgain,
+ Unknown = ErrorCode.Unknown,
+ TimedOut = ErrorCode.TimedOut,
+ NotSupported = ErrorCode.NotSupported,
+ PermissionDenied = ErrorCode.PermissionDenied,
+ OutOfMemory = ErrorCode.OutOfMemory,
+ InvalidOperation = ErrorCode.InvalidOperation
+ }
+
+ internal static class NNTrainer
+ {
+
+ internal const string Tag = "Tizen.MachineLearning.Train";
+
+ internal static void CheckException(NNTrainerError error, string msg)
+ {
+ if (error != NNTrainerError.None)
+ {
+ Log.Error(NNTrainer.Tag, msg + ": " + error.ToString());
+ throw NNTrainerExceptionFactory.CreateException(error, msg);
+ }
+ }
+
+ }
+
+ internal class NNTrainerExceptionFactory
+ {
+ internal static Exception CreateException(NNTrainerError err, string msg)
+ {
+ Exception e;
+
+ switch (err)
+ {
+ case NNTrainerError.InvalidParameter:
+ e = new ArgumentException(msg);
+ break;
+
+ case NNTrainerError.NotSupported:
+ e = new NotSupportedException(msg);
+ break;
+
+ case NNTrainerError.PermissionDenied:
+ e = new UnauthorizedAccessException(msg);
+ break;
+
+ case NNTrainerError.TryAgain:
+ case NNTrainerError.Unknown:
+ case NNTrainerError.OutOfMemory:
+ e = new InvalidOperationException(msg);
+ break;
+
+ case NNTrainerError.TimedOut:
+ e = new TimeoutException(msg);
+ break;
+
+ default:
+ e = new InvalidOperationException(msg);
+ break;
+ }
+ return e;
+ }
+ }
+}
--- /dev/null
+/*
+* Copyright (c) 2022 Samsung Electronics Co., Ltd. All Rights Reserved.
+*
+* Licensed under the Apache License, Version 2.0 (the License);
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an AS IS BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+using static Interop;
+using System;
+using System.IO;
+
+namespace Tizen.MachineLearning.Train
+{
+ /// <summary>
+ /// Constructs the neural network model
+ /// </summary>
+ /// <remarks>
+ /// Use this function 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 function,
+ /// you should add privilege %http://tizen.org/privilege/mediastorage. Or, if you
+ /// want to access only external storage by using this function, you should add
+ /// privilege %http://tizen.org/privilege/externalstorage. If you want to access
+ /// both storage, you must add all the privileges.
+ /// </remarks>
+ /// <since_tizen> 10 </since_tizen>
+ public class Model: IDisposable
+ {
+ private IntPtr _handle = IntPtr.Zero;
+ private bool _disposed = false;
+
+ /// <summary>
+ /// Create a new Model instance.
+ /// </summary>
+ /// <since_tizen> 10 </since_tizen>
+ public Model()
+ {
+ NNTrainerError ret = Interop.Model.Construct(out _handle);
+ NNTrainer.CheckException(ret, "Failed to create model instance");
+ }
+
+ /// <summary>
+ /// Destructor of Model
+ /// </summary>
+ /// <since_tizen> 10 </since_tizen>
+ ~Model()
+ {
+ Dispose(false);
+ }
+
+ /// <summary>
+ /// Releases any unmanaged resources used by this object.
+ /// </summary>
+ /// <since_tizen> 10 </since_tizen>
+ public void Dispose()
+ {
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ /// <summary>
+ /// Releases any unmanaged resources used by this object including opened handle.
+ /// </summary>
+ /// <param name="disposing">If true, disposes any disposable objects. If false, does not dispose disposable objects.</param>
+ /// <since_tizen> 10 </since_tizen>
+ protected virtual void Dispose(bool disposing)
+ {
+ if (_disposed)
+ return;
+ if (disposing)
+ {
+ // release managed object
+ }
+
+ // release unmanaged object
+ if (_handle != IntPtr.Zero)
+ {
+ // Destroy the neural network model.
+ NNTrainerError ret = Interop.Model.Destroy(_handle);
+ NNTrainer.CheckException(ret, "Failed to destroy model instance");
+
+ _handle = IntPtr.Zero;
+ }
+ _disposed = true;
+ }
+ }
+}