Add MV_INFERENCE_MODEL_META_FILE_PATH attribute and deprecate some attributes which... 65/263465/4 submit/tizen/20210907.045211
authorTae-Young Chung <ty83.chung@samsung.com>
Fri, 3 Sep 2021 03:58:27 +0000 (12:58 +0900)
committerTae-Young Chung <ty83.chung@samsung.com>
Tue, 7 Sep 2021 04:15:15 +0000 (13:15 +0900)
Deprecate attributes
- MV_INFERENCE_MODEL_MEAN_VALUE
- MV_INFERENCE_MODEL_STD_VALUE
- MV_INFERENCE_INPUT_TENSOR_WIDTH
- MV_INFERENCE_INPUT_TENSOR_HEIGHT
- MV_INFERENCE_INPUT_TENSOR_CHANNELS
- MV_INFERENCE_INPUT_DATA_TYPE
- MV_INFERENCE_INPUT_NODE_NAME
- MV_INFERENCE_INPUT_OUTPUT_NODE_NAMES
- MV_INFERENCE_OUTPUT_MAX_NUMBER
- MV_INFERENCE_CONFIDENCE_THRESHOLD

Change-Id: I340b6c2fa3872dd682bc2f60d45007ffb87a46b5
Signed-off-by: Tae-Young Chung <ty83.chung@samsung.com>
include/mv_inference.h
media-vision-config.json
mv_machine_learning/mv_inference/inference/src/mv_inference_open.cpp
packaging/capi-media-vision.spec

index 6949592..2b8e054 100644 (file)
@@ -68,6 +68,20 @@ extern "C" {
 #define MV_INFERENCE_MODEL_USER_FILE_PATH "MV_INFERENCE_MODEL_USER_FILE_PATH"
 
 /**
+ * @brief Defines #MV_INFERENCE_MODEL_META_FILE_PATH to set inference
+ *        models's metadata file attribute of the engine configuration.
+ * @details The file includes inference model's metadata such as input and output
+ *          node names, input tensor's width and height,
+ *          mean and standard deviation values for pre-processing.
+ *
+ * @since_tizen 6.5
+ * @see mv_engine_config_set_string_attribute()
+ * @see mv_engine_config_get_string_attribute()
+ */
+#define MV_INFERENCE_MODEL_META_FILE_PATH "MV_INFERENCE_MODEL_META_FILE_PATH"
+
+/**
+ * @deprecated Deprecated since 6.5. Use #MV_INFERENCE_MODEL_META_FILE_PATH instead.
  * @brief Defines #MV_INFERENCE_MODEL_MEAN_VALUE to set inference
  *        model's mean attribute of the engine configuration.
  *
@@ -78,6 +92,7 @@ extern "C" {
 #define MV_INFERENCE_MODEL_MEAN_VALUE "MV_INFERENCE_MODEL_MEAN_VALUE"
 
 /**
+ * @deprecated Deprecated since 6.5. Use #MV_INFERENCE_MODEL_META_FILE_PATH instead.
  * @brief Defines #MV_INFERENCE_MODEL_STD_VALUE to set an input image's
  *        standard deviation attribute of the engine configuration.
  *
@@ -138,6 +153,7 @@ extern "C" {
 #define MV_INFERENCE_TARGET_DEVICE_TYPE "MV_INFERENCE_TARGET_DEVICE_TYPE"
 
 /**
+ * @deprecated Deprecated since 6.5. Use #MV_INFERENCE_MODEL_META_FILE_PATH instead.
  * @brief Defines #MV_INFERENCE_INPUT_TENSOR_WIDTH to set the width
  *        of input tensor.
  *
@@ -148,6 +164,7 @@ extern "C" {
 #define MV_INFERENCE_INPUT_TENSOR_WIDTH "MV_INFERENCE_INPUT_TENSOR_WIDTH"
 
 /**
+ * @deprecated Deprecated since 6.5. Use #MV_INFERENCE_MODEL_META_FILE_PATH instead.
  * @brief Defines #MV_INFERENCE_INPUT_TENSOR_HEIGHT to set the height
  *        of input tensor.
  *
@@ -158,6 +175,7 @@ extern "C" {
 #define MV_INFERENCE_INPUT_TENSOR_HEIGHT "MV_INFERENCE_INPUT_TENSOR_HEIGHT"
 
 /**
+ * @deprecated Deprecated since 6.5. Use #MV_INFERENCE_MODEL_META_FILE_PATH instead.
  * @brief Defines #MV_INFERENCE_INPUT_TENSOR_CHANNELS to set the channels,
  *        for example 3 in case of RGB colorspace, of input tensor.
  *
@@ -168,6 +186,7 @@ extern "C" {
 #define MV_INFERENCE_INPUT_TENSOR_CHANNELS "MV_INFERENCE_INPUT_TENSOR_CHANNELS"
 
 /**
+ * @deprecated Deprecated since 6.5. Use #MV_INFERENCE_MODEL_META_FILE_PATH instead.
  * @brief Defines #MV_INFERENCE_INPUT_DATA_TYPE to set data type of input tensor.
  * @details Data type of input tensor can be changed according to a given weight file.
  *          Switches between Float32 or UInt8:\n
@@ -183,6 +202,7 @@ extern "C" {
 #define MV_INFERENCE_INPUT_DATA_TYPE "MV_INFERENCE_INPUT_DATA_TYPE"
 
 /**
+ * @deprecated Deprecated since 6.5. Use #MV_INFERENCE_MODEL_META_FILE_PATH instead.
  * @brief Defines #MV_INFERENCE_INPUT_NODE_NAME to set the input node name.
  *
  * @since_tizen 5.5
@@ -192,6 +212,7 @@ extern "C" {
 #define MV_INFERENCE_INPUT_NODE_NAME "MV_INFERENCE_INPUT_NODE_NAME"
 
 /**
+ * @deprecated Deprecated since 6.5. Use #MV_INFERENCE_MODEL_META_FILE_PATH instead.
  * @brief Defines #MV_INFERENCE_OUTPUT_NODE_NAMES to set the output node names.
  *
  * @since_tizen 5.5
@@ -201,6 +222,7 @@ extern "C" {
 #define MV_INFERENCE_OUTPUT_NODE_NAMES "MV_INFERENCE_OUTPUT_NODE_NAMES"
 
 /**
+ * @deprecated Deprecated since 6.5. Use #MV_INFERENCE_MODEL_META_FILE_PATH instead.
  * @brief Defines #MV_INFERENCE_OUTPUT_MAX_NUMBER
  *        to set the maximum number of output attributes
  *        of the engine configuration.
@@ -214,6 +236,7 @@ extern "C" {
 #define MV_INFERENCE_OUTPUT_MAX_NUMBER "MV_INFERENCE_OUTPUT_MAX_NUMBER"
 
 /**
+ * @deprecated Deprecated since 6.5. Use #MV_INFERENCE_MODEL_META_FILE_PATH instead.
  * @brief Defines #MV_INFERENCE_CONFIDENCE_THRESHOLD
  *        to set the threshold value for the confidence of inference results.
  * @details Default value is 0.6 and its range is between 0.0 and 1.0.
index c5ee5af..9987623 100644 (file)
             "subtype" : "string",
             "value" : [ "output"
             ]
+        },
+        {
+            "name"  : "MV_INFERENCE_MODEL_META_FILE_PATH",
+            "type"  : "string",
+            "value" : ""
         }
     ]
 }
index af2163e..d41b471 100644 (file)
@@ -111,6 +111,14 @@ int mv_inference_destroy_open(mv_inference_h infer)
        return MEDIA_VISION_ERROR_NONE;
 }
 
+bool IsJsonFile(const std::string& fileName)
+{
+       if (!fileName.substr(fileName.find_last_of(".") + 1).compare("json"))
+               return true;
+
+       return false;
+}
+
 int mv_inference_configure_model_open(mv_inference_h infer,
                                                                          mv_engine_config_h engine_config)
 {
@@ -123,13 +131,11 @@ int mv_inference_configure_model_open(mv_inference_h infer,
        char *modelConfigFilePath = NULL;
        char *modelWeightFilePath = NULL;
        char *modelUserFilePath = NULL;
+       char *modelMetaFilePath = NULL;
        double modelMeanValue = 0.0;
        int backendType = 0;
        size_t userFileLength = 0;
 
-       // TODO: a temporal variable, later, it should be removed.
-       std::string metaFilePath;
-
        ret = mv_engine_config_get_string_attribute(
                        engine_config, MV_INFERENCE_MODEL_CONFIGURATION_FILE_PATH,
                        &modelConfigFilePath);
@@ -154,6 +160,20 @@ int mv_inference_configure_model_open(mv_inference_h infer,
                goto _ERROR_;
        }
 
+       ret = mv_engine_config_get_string_attribute(
+                       engine_config, MV_INFERENCE_MODEL_META_FILE_PATH,
+                       &modelMetaFilePath);
+       if (ret != MEDIA_VISION_ERROR_NONE) {
+               LOGE("Fail to get model meta file path");
+               goto _ERROR_;
+       }
+
+       if (!IsJsonFile(std::string(modelMetaFilePath))) {
+               ret = MEDIA_VISION_ERROR_INVALID_PATH;
+               LOGE("Model meta file should be json");
+               goto _ERROR_;
+       }
+
        ret = mv_engine_config_get_double_attribute(
                        engine_config, MV_INFERENCE_MODEL_MEAN_VALUE, &modelMeanValue);
        if (ret != MEDIA_VISION_ERROR_NONE) {
@@ -198,16 +218,11 @@ int mv_inference_configure_model_open(mv_inference_h infer,
        pInfer->ConfigureModelFiles(std::string(modelConfigFilePath),
                                                                std::string(modelWeightFilePath),
                                                                std::string(modelUserFilePath));
-       /* FIXME
-        * temporal code lines to get a metafile, which has the same name
-        * with modelsWeightFilePath except the extension.
-        * Later, it should get a metafilename and the below lines should be
-        * removed.
-        */
-       metaFilePath = std::string(modelWeightFilePath).substr(0,
-                                       std::string(modelWeightFilePath).find_last_of('.')) + ".json";
-       LOGI("metaFilePath: %s", metaFilePath.c_str());
-       pInfer->ParseMetadata(metaFilePath);
+
+       ret = pInfer->ParseMetadata(std::string(modelMetaFilePath));
+       if (ret != MEDIA_VISION_ERROR_NONE) {
+               LOGE("Fail to ParseMetadata");
+       }
 
 _ERROR_:
        if (modelConfigFilePath)
@@ -219,6 +234,9 @@ _ERROR_:
        if (modelUserFilePath)
                free(modelUserFilePath);
 
+       if (modelMetaFilePath)
+               free(modelMetaFilePath);
+
        LOGI("LEAVE");
 
        return ret;
index 78ccc9b..a6a9574 100644 (file)
@@ -1,7 +1,7 @@
 Name:        capi-media-vision
 Summary:     Media Vision library for Tizen Native API
-Version:     0.8.14
-Release:     1
+Version:     0.8.15
+Release:     0
 Group:       Multimedia/Framework
 License:     Apache-2.0 and BSD-3-Clause
 Source0:     %{name}-%{version}.tar.gz