--- /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 Dataset
+ {
+ /* int ml_train_dataset_create(ml_train_dataset_h *dataset) */
+ [DllImport(Libraries.Nntrainer, EntryPoint = "ml_train_dataset_create")]
+ public static extern NNTrainerError Create(out IntPtr datasetHandle);
+
+ /* int ml_train_dataset_destroy(ml_train_dataset_h dataset) */
+ [DllImport(Libraries.Nntrainer, EntryPoint = "ml_train_dataset_destroy")]
+ public static extern NNTrainerError Destroy(IntPtr datasetHandle);
+
+ /* int ml_train_dataset_add_file(ml_train_dataset_h dataset, ml_train_dataset_mode_e mode, const char *file) */
+ [DllImport(Libraries.Nntrainer, EntryPoint = "ml_train_dataset_add_file")]
+ internal static extern NNTrainerError AddFile(IntPtr datasetHandle, NNTrainerDatasetMode mode, string file);
+ }
+}
--- /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 dataset.
+ /// </summary>
+ /// <remarks>
+ /// Use this function to create a dataset. dataset should be released using Dispose().
+ /// dataset is available until the model is released.
+ /// </remarks>
+ /// <since_tizen> 10 </since_tizen>
+ public class Dataset: IDisposable
+ {
+ private IntPtr handle = IntPtr.Zero;
+ private bool disposed = false;
+
+ /// <summary>
+ /// Constructs the dataset.
+ /// </summary>
+ /// <since_tizen> 10 </since_tizen>
+ public Dataset()
+ {
+ NNTrainerError ret = Interop.Dataset.Create(out handle);
+ NNTrainer.CheckException(ret, "Failed to create dataset instance");
+ Log.Info(NNTrainer.Tag, "Create Dataset");
+ }
+ /// <summary>
+ /// Frees the neural network dataset.
+ /// </summary>
+ /// <since_tizen> 10 </since_tizen>
+ /// <remarks>
+ /// Use this function to destroy dataset. Fails if dataset is owned by a model.
+ /// </remarks>
+ ~Dataset()
+ {
+ 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 dataset.
+ NNTrainerError ret = Interop.Dataset.Destroy(handle);
+ NNTrainer.CheckException(ret, "Failed to destroy dataset instance");
+ Log.Info(NNTrainer.Tag, "Destroy Dataset");
+
+ handle = IntPtr.Zero;
+ }
+ disposed = true;
+ }
+
+ /// <summary>
+ /// Adds data file to dataset.
+ /// </summary>
+ /// <remarks>
+ /// Use this function to add a data file from where data is retrieved.
+ /// 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 can access both
+ /// storage, you must add all privilege
+ /// </remarks>
+ /// <param name="mode">The phase where this generator should be used.</param>
+ /// <param name="file">file path.</param>
+ /// <since_tizen> 10 </since_tizen>
+ public void AddFile(NNTrainerDatasetMode mode, string file)
+ {
+ if (string.IsNullOrEmpty(file))
+ NNTrainer.CheckException(NNTrainerError.InvalidParameter, "file is null");
+
+ NNTrainerError ret = Interop.Dataset.AddFile(handle, mode, file);
+ NNTrainer.CheckException(ret, "Failed to add file");
+ Log.Info(NNTrainer.Tag, $"Add file{file}");
+ }
+
+ internal IntPtr GetHandle()
+ {
+ return handle;
+ }
+ }
+}