[CAPI] Propose dataset api sets
authorJihoon Lee <jhoon.it.lee@samsung.com>
Thu, 8 Jul 2021 04:47:28 +0000 (13:47 +0900)
committerJijoong Moon <jijoong.moon@samsung.com>
Wed, 14 Jul 2021 06:20:23 +0000 (15:20 +0900)
**Changes proposed in this PR:**
- `ml_train_dataset_create(ml_train_dataset_h *dataset);
- `ml_train_dataset_add_generator(dataset, usage, callback, user_data)`
- `ml_train_dataset_add_file(dataset, usage, file)`
- `ml_train_dataset_set_property_for_usage(dataset, usage)`

**Self evaluation:**
1. Build test: [X]Passed [ ]Failed [ ]Skipped
2. Run test: [X]Passed [ ]Failed [ ]Skipped

Signed-off-by: Jihoon Lee <jhoon.it.lee@samsung.com>
api/capi/include/nntrainer.h
api/ccapi/include/dataset.h
api/nntrainer-api-common.h

index 632bc973ba42a01519a75c1e18ca46d27e892f8b..8c661435ae691cf1ad440150d2d01893b770eaaa 100644 (file)
@@ -390,6 +390,56 @@ int ml_train_dataset_create_with_generator(ml_train_dataset_h *dataset,
                                            ml_train_datagen_cb valid_cb,
                                            ml_train_datagen_cb test_cb);
 
+/**
+ * @brief Constructs the dataset.
+ * @details Use this function to create a dataset
+ * @since_tizen 6.5
+ * @remarks If the function succeeds, @a dataset must be released using
+ * ml_train_dataset_destroy(), if not added to a model. If added to a model, @a
+ * dataset is available until the model is released.
+ * @param[out] dataset The NNTrainer dataset handle.
+ * @return @c 0 on success. Otherwise a negative error value.
+ * @retval #ML_ERROR_NONE Successful.
+ * @retval #ML_ERROR_NOT_SUPPORTED Not supported.
+ * @retval #ML_ERROR_INVALID_PARAMETER Invalid parameter.
+ */
+int ml_train_dataset_create(ml_train_dataset_h *dataset);
+
+/**
+ * @brief Add data generator callback to @a dataset
+ * @details Use this function to add a data generator callback which generates a
+ * single batch per call to the dataset.
+ * @param[in] dataset The NNTrainer dataset handle.
+ * @param[in] usage The phase where this generator should be used.
+ * @param[in] user_data user_data to be fed when @a cb is being called.
+ * @return @c 0 on success. Otherwise a negative error value.
+ * @retval #ML_ERROR_NONE Successful.
+ * @retval #ML_ERROR_NOT_SUPPORTED Not supported.
+ * @retval #ML_ERROR_INVALID_PARAMETER Invalid parameter.
+ */
+int ml_train_dataset_add_generator(ml_train_dataset_h dataset,
+                                   ml_train_dataset_data_usage_e usage,
+                                   ml_train_datagen_cb cb, void *user_data);
+
+/**
+ * @brief Add data file to @a dataset
+ * @details Use this function to add a data file from where data is retrieved.
+ * @remarks %http://tizen.org/privilege/mediastorage is needed if @a dataset is
+ * saved to media storage.
+ * @remarks %http://tizen.org/privilege/externalstorage is needed if @a model is
+ * saved to external storage.
+ * @param[in] dataset The NNTrainer dataset handle.
+ * @param[in] usage The phase where this file should be used.
+ * @param[in] file file path.
+ * @return @c 0 on success. Otherwise a negative error value.
+ * @retval #ML_ERROR_NONE Successful.
+ * @retval #ML_ERROR_NOT_SUPPORTED Not supported.
+ * @retval #ML_ERROR_INVALID_PARAMETER Invalid parameter.
+ */
+int ml_train_dataset_add_file(ml_train_dataset_h dataset,
+                              ml_train_dataset_data_usage_e usage,
+                              const char *file);
+
 /**
  * @brief Creates a dataset with files to feed to a neural network.
  * @details Use this function to create a neural network dataset using
@@ -428,6 +478,9 @@ int ml_train_dataset_destroy(ml_train_dataset_h dataset);
 /**
  * @brief Sets the neural network dataset property.
  * @details Use this function to set dataset property.
+ * @remarks the same property is applied over train, valid, testsets that are
+ * added to the @a dataset, it is recommened to use @a
+ * ml_train_dataset_set_property_for_usage() instead.
  * @since_tizen 6.0
  * @param[in] dataset The NNTrainer dataset handle.
  * @param[in]  ... Property values with NULL for termination.
@@ -438,6 +491,22 @@ int ml_train_dataset_destroy(ml_train_dataset_h dataset);
  */
 int ml_train_dataset_set_property(ml_train_dataset_h dataset, ...);
 
+/**
+ * @brief Sets the neural network dataset property.
+ * @details Use this function to set dataset property for a specific usage.
+ * @since_tizen 6.5
+ * @param[in] dataset The NNTrainer dataset handle.
+ * @param[in] usage The usage to set the property.
+ * @param[in]  ... Property values with NULL for termination.
+ * @return @c 0 on success. Otherwise a negative error value.
+ * @retval #ML_ERROR_NONE Successful.
+ * @retval #ML_ERROR_NOT_SUPPORTED Not supported.
+ * @retval #ML_ERROR_INVALID_PARAMETER Invalid parameter.
+ */
+int ml_train_dataset_set_property_for_usage(ml_train_dataset_h dataset,
+                                            ml_train_dataset_data_usage_e usage,
+                                            ...);
+
 /**
  * @}
  */
index 70ebd8c614542a9a94b6aefceb6fc592d573563d..8f4226a80bbee43c09f1f707c8d3186e323515ca 100644 (file)
@@ -46,13 +46,14 @@ enum class DatasetType {
 
 /**
  * @brief     Enumeration of data type
+ * @todo      deperecate data label
  */
 enum class DatasetDataType {
-  DATA_TRAIN /** data for training */
-  DATA_VAL   /** data for validation */
-  DATA_TEST,   /** data for test */
-  DATA_LABEL,  /** label names */
-  DATA_UNKNOWN /** data not known */
+  DATA_TRAIN = ML_TRAIN_DATASET_DATA_USAGE_TRAIN, /** data for training */
+  DATA_VAL = ML_TRAIN_DATASET_DATA_USAGE_VALID,   /** data for validation */
+  DATA_TEST = ML_TRAIN_DATASET_DATA_USAGE_TEST,   /** data for test */
+  DATA_LABEL,                                     /** label names */
+  DATA_UNKNOWN                                    /** data not known */
 };
 
 /**
index abdccdaacf7d4dcd50150389723c45d4f163eb05..74f4590c225f73639438185b83df9525cf565651 100644 (file)
@@ -151,6 +151,19 @@ typedef enum {
 typedef int (*ml_train_datagen_cb)(float **input, float **label, bool *last,
                                    void *user_data);
 
+/**
+ * @brief Enumeration for the dataset data type of NNTrainer.
+ * @since_tizen 6.5
+ */
+typedef enum {
+  ML_TRAIN_DATASET_DATA_USAGE_TRAIN =
+    0, /**< The given data is for used when training */
+  ML_TRAIN_DATASET_DATA_USAGE_VALID =
+    1, /**< The given data is for used when validating */
+  ML_TRAIN_DATASET_DATA_USAGE_TEST =
+    2, /**< The given data is for used when testing */
+} ml_train_dataset_data_usage_e;
+
 /**
  * @brief Enumeration for the neural network summary verbosity of NNTrainer.
  * @since_tizen 6.0