Change inputmetadata's shape_type, data_type, color_space to string 68/262668/3
authorTae-Young Chung <ty83.chung@samsung.com>
Tue, 17 Aug 2021 09:35:02 +0000 (18:35 +0900)
committerTae-Young Chung <ty83.chung@samsung.com>
Wed, 18 Aug 2021 03:19:12 +0000 (12:19 +0900)
Those metadata are user unfriendly and difficult to use because of a lack of decscription.
They are changed to string and user can understand what they mean.
The string values are parsed and converted to proper enumerations.

Change-Id: Ia98f29790d68fe2bf2fb38e2e922cc0b9b4d80e4
Signed-off-by: Tae-Young Chung <ty83.chung@samsung.com>
24 files changed:
meta-template/README.md
meta-template/fd_blazeface_front_128x128.json
meta-template/fd_mobilenet_v1_ssd_postop_300x300.json
meta-template/fld_mediapipe_192x192.json
meta-template/fld_tweakcnn_128x128.json
meta-template/ic_densenet_224x224.json
meta-template/ic_inception_resnet_v2_299x299.json
meta-template/ic_inception_v3_299x299.json
meta-template/ic_inception_v4_299x299.json
meta-template/ic_mnasnet_224x224.json
meta-template/ic_mobilenet_v1_224x224.json
meta-template/ic_mobilenet_v2_224x224.json
meta-template/ic_nasnet_224x224.json
meta-template/ic_resnet_v2_299x299.json
meta-template/ic_squeezenet_224x224.json
meta-template/image-classification-001-meta.json
meta-template/image-classification-quant-001-meta.json
meta-template/od_mobilenet_v1_ssd_postop_300x300.json
meta-template/od_mobilenet_v2_ssd_320x320.json
meta-template/pld_cpm_192x192.json
meta-template/pld_mobilenet_v1_posenet_multi_257x257.json
mv_machine_learning/mv_inference/inference/include/InputMetadata.h
mv_machine_learning/mv_inference/inference/src/InputMetadata.cpp
packaging/capi-media-vision.spec

index 1e31cfc..f7fda1e 100644 (file)
@@ -11,9 +11,9 @@ The Meta file consists of 1) inputmetadata and 2) outputmetadata. For example, a
         "tensor_info" : [
             {
                 "name" : "input_2",
-                "shape_type" : 1,
+                "shape_type" : "NHWC",
                 "shape_dims" : [ 1, 224, 224, 3],
-                "data_type" : 0,
+                "data_type" : "FLOAT32",
                 "color_space" : "RGB888"
             }
         ],
@@ -47,7 +47,7 @@ In the classification meta file, the `inputmetadata` includes
 `tensor_info` which has knowledge of an input tensor such as
 
 - `name`: name to an input tensor
-- `shape_type`: shape type of the input tensor on `NCHW = 0` and `NHWC = 1`
+- `shape_type`: shape type of the input tensor on `NCHW` and `NHWC`
 - `shape_dims`: shape dimensions based on the `shape_type`
 - `data_type`: data type of the input tensor on `MV_INFERENCE_DATA_FLOAT32 = 0` and `MV_INFERENCE_DATA_UINT8 = 1`
 - `color_space`: color space of the input tensor.
index 4c94a03..a7c8041 100644 (file)
@@ -4,9 +4,9 @@
         "tensor_info" : [
             {
                 "name" : "input",
-                "shape_type" : 1,
+                "shape_type" : "NHWC",
                 "shape_dims" : [ 1, 128, 128, 3],
-                "data_type" : 0,
+                "data_type" : "FLOAT32",
                 "color_space" : "RGB888"
             }
         ],
index e9aa00b..75b5d65 100644 (file)
@@ -4,9 +4,9 @@
         "tensor_info" : [
             {
                 "name" : "normalized_input_image_tensor",
-                "shape_type" : 1,
+                "shape_type" : "NHWC",
                 "shape_dims" : [ 1, 300, 300, 3],
-                "data_type" : 0,
+                "data_type" : "FLOAT32",
                 "color_space" : "RGB888"
             }
         ],
index 562fb77..ad266a8 100644 (file)
@@ -4,9 +4,9 @@
         "tensor_info" : [
             {
                 "name" : "input",
-                "shape_type" : 1,
+                "shape_type" : "NHWC",
                 "shape_dims" : [ 1, 192, 192, 3],
-                "data_type" : 0,
+                "data_type" : "FLOAT32",
                 "color_space" : "RGB888"
             }
         ],
index 7d8b48f..0c30ad3 100644 (file)
@@ -4,9 +4,9 @@
         "tensor_info" : [
             {
                 "name" : "Placeholder",
-                "shape_type" : 1,
+                "shape_type" : "NHWC",
                 "shape_dims" : [ 1, 128, 128, 3],
-                "data_type" : 0,
+                "data_type" : "FLOAT32",
                 "color_space" : "RGB888"
             }
         ],
index 9a69d01..3e69393 100644 (file)
@@ -4,9 +4,9 @@
         "tensor_info" : [
             {
                 "name" : "Placeholder",
-                "shape_type" : 1,
+                "shape_type" : "NHWC",
                 "shape_dims" : [ 1, 224, 224, 3],
-                "data_type" : 0,
+                "data_type" : "FLOAT32",
                 "color_space" : "RGB888"
             }
         ],
index 87d87da..34d934a 100644 (file)
@@ -4,9 +4,9 @@
         "tensor_info" : [
             {
                 "name" : "input",
-                "shape_type" : 1,
+                "shape_type" : "NHWC",
                 "shape_dims" : [ 1, 299, 299, 3],
-                "data_type" : 0,
+                "data_type" : "FLOAT32",
                 "color_space" : "RGB888"
             }
         ],
index 7c2ef9f..6e8c3f2 100644 (file)
@@ -4,9 +4,9 @@
         "tensor_info" : [
             {
                 "name" : "input",
-                "shape_type" : 1,
+                "shape_type" : "NHWC",
                 "shape_dims" : [ 1, 299, 299, 3],
-                "data_type" : 0,
+                "data_type" : "FLOAT32",
                 "color_space" : "RGB888"
             }
         ],
index 8cd3f47..4d31be4 100644 (file)
@@ -4,9 +4,9 @@
         "tensor_info" : [
             {
                 "name" : "input",
-                "shape_type" : 1,
+                "shape_type" : "NHWC",
                 "shape_dims" : [ 1, 299, 299, 3],
-                "data_type" : 0,
+                "data_type" : "FLOAT32",
                 "color_space" : "RGB888"
             }
         ],
index 83938df..e7eecf4 100644 (file)
@@ -4,9 +4,9 @@
         "tensor_info" : [
             {
                 "name" : "input",
-                "shape_type" : 1,
+                "shape_type" : "NHWC",
                 "shape_dims" : [ 1, 224, 224, 3],
-                "data_type" : 0,
+                "data_type" : "FLOAT32",
                 "color_space" : "RGB888"
             }
         ],
index 2599d8c..c68f146 100644 (file)
@@ -4,9 +4,9 @@
         "tensor_info" : [
             {
                 "name" : "input",
-                "shape_type" : 1,
+                "shape_type" : "NHWC",
                 "shape_dims" : [ 1, 224, 224, 3],
-                "data_type" : 0,
+                "data_type" : "FLOAT32",
                 "color_space" : "RGB888"
             }
         ],
index c0c976b..c2bee18 100644 (file)
@@ -4,9 +4,9 @@
         "tensor_info" : [
             {
                 "name" : "input",
-                "shape_type" : 1,
+                "shape_type" : "NHWC",
                 "shape_dims" : [ 1, 224, 224, 3],
-                "data_type" : 0,
+                "data_type" : "FLOAT32",
                 "color_space" : "RGB888"
             }
         ],
index 8448561..32769db 100644 (file)
@@ -4,9 +4,9 @@
         "tensor_info" : [
             {
                 "name" : "input",
-                "shape_type" : 1,
+                "shape_type" : "NHWC",
                 "shape_dims" : [ 1, 224, 224, 3],
-                "data_type" : 0,
+                "data_type" : "FLOAT32",
                 "color_space" : "RGB888"
             }
         ],
index 865652c..8e6f723 100644 (file)
@@ -4,9 +4,9 @@
         "tensor_info" : [
             {
                 "name" : "input",
-                "shape_type" : 1,
+                "shape_type" : "NHWC",
                 "shape_dims" : [ 1, 299, 299, 3],
-                "data_type" : 0,
+                "data_type" : "FLOAT32",
                 "color_space" : "RGB888"
             }
         ],
index fdf00e2..b0e8f34 100644 (file)
@@ -4,9 +4,9 @@
         "tensor_info" : [
             {
                 "name" : "Placeholder",
-                "shape_type" : 1,
+                "shape_type" : "NHWC",
                 "shape_dims" : [ 1, 224, 224, 3],
-                "data_type" : 0,
+                "data_type" : "FLOAT32",
                 "color_space" : "RGB888"
             }
         ],
index 151908c..a89bc97 100644 (file)
@@ -4,9 +4,9 @@
         "tensor_info" : [
             {
                 "name" : "input_2",
-                "shape_type" : 1,
+                "shape_type" : "NHWC",
                 "shape_dims" : [ 1, 224, 224, 3],
-                "data_type" : 0,
+                "data_type" : "FLOAT32",
                 "color_space" : "RGB888"
             }
         ],
index 9a44eab..1936dbd 100644 (file)
@@ -4,9 +4,9 @@
         "tensor_info" : [
             {
                 "name" : "input",
-                "shape_type" : 1,
+                "shape_type" : "NHWC",
                 "shape_dims" : [ 1, 224, 224, 3],
-                "data_type" : 1,
+                "data_type" : "UNIT8",
                 "color_space" : "RGB888"
             }
         ]
index e9aa00b..75b5d65 100644 (file)
@@ -4,9 +4,9 @@
         "tensor_info" : [
             {
                 "name" : "normalized_input_image_tensor",
-                "shape_type" : 1,
+                "shape_type" : "NHWC",
                 "shape_dims" : [ 1, 300, 300, 3],
-                "data_type" : 0,
+                "data_type" : "FLOAT32",
                 "color_space" : "RGB888"
             }
         ],
index 6574f70..826640c 100644 (file)
@@ -4,9 +4,9 @@
         "tensor_info" : [
             {
                 "name" : "normalized_input_image_tensor",
-                "shape_type" : 1,
+                "shape_type" : "NHWC",
                 "shape_dims" : [ 1, 320, 320, 3],
-                "data_type" : 0,
+                "data_type" : "FLOAT32",
                 "color_space" : "RGB888"
             }
         ],
index e4f573b..3bee725 100644 (file)
@@ -4,9 +4,9 @@
         "tensor_info" : [
             {
                 "name" : "image",
-                "shape_type" : 1,
+                "shape_type" : "NHWC",
                 "shape_dims" : [ 1, 192, 192, 3],
-                "data_type" : 0,
+                "data_type" : "FLOAT32",
                 "color_space" : "RGB888"
             }
         ],
index 1d69c7a..44b942c 100644 (file)
@@ -4,9 +4,9 @@
         "tensor_info" : [
             {
                 "name" : "sub_2",
-                "shape_type" : 1,
+                "shape_type" : "NHWC",
                 "shape_dims" : [ 1, 257, 257, 3],
-                "data_type" : 0,
+                "data_type" : "FLOAT32",
                 "color_space" : "RGB888"
             }
         ],
index 01da01c..8b5e2bd 100644 (file)
@@ -97,7 +97,7 @@ namespace inference
                 *
                 * @since_tizen 6.5
                 */
-               InputMetadata() : parsed(false) {};
+               InputMetadata();
 
                /**
                 * @brief   Destroys an InputMetadata class instance including
@@ -115,9 +115,15 @@ namespace inference
                int Parse(JsonObject *root);
 
        private:
+               std::map<std::string, inference_tensor_shape_type_e> mSupportedShapeType;
+               std::map<std::string, mv_inference_data_type_e> mSupportedDataType;
+               std::map<std::string, mv_colorspace_e> mSupportedColorSpace;
+
+               template <typename T>
+               static T GetSupportedType(JsonObject* root, std::string typeName,
+                                                               std::map<std::string, T>& supportedTypes);
                int GetTensorInfo(JsonObject* root);
                int GetPreProcess(JsonObject* root);
-               mv_colorspace_e ConvertTypeToMD(const std::string& type);
 
        };
 
index befbd43..66d257c 100644 (file)
@@ -28,23 +28,36 @@ namespace mediavision
 {
 namespace inference
 {
-       mv_colorspace_e InputMetadata::ConvertTypeToMD(const std::string& type)
+       InputMetadata::InputMetadata() :
+                       parsed(false),
+                       layer(),
+                       option()
        {
-               mv_colorspace_e colorspace = MEDIA_VISION_COLORSPACE_INVALID;
-               if (type.empty()) {
-                       LOGE("Invalid type[null]");
-                       return colorspace;
-               }
+               // shape_type
+               mSupportedShapeType.insert({"NCHW", INFERENCE_TENSOR_SHAPE_NCHW});
+               mSupportedShapeType.insert({"NHWC", INFERENCE_TENSOR_SHAPE_NHWC});
+
+               // data_type
+               mSupportedDataType.insert({"FLOAT32", MV_INFERENCE_DATA_FLOAT32});
+               mSupportedDataType.insert({"UINT8", MV_INFERENCE_DATA_UINT8});
 
-               if (type.compare("RGB888") == 0) {
-                       colorspace = MEDIA_VISION_COLORSPACE_RGB888;
-               } else if (type.compare("Y800") == 0) {
-                       colorspace = MEDIA_VISION_COLORSPACE_Y800;
-               } else {
-                       LOGE("Not supported channel type");
+               // color_space
+               mSupportedColorSpace.insert({"RGB888", MEDIA_VISION_COLORSPACE_RGB888});
+               mSupportedColorSpace.insert({"GRAY8", MEDIA_VISION_COLORSPACE_Y800});
+       }
+
+       template <typename T>
+       T InputMetadata::GetSupportedType(JsonObject* root, std::string typeName,
+                                                                       std::map<std::string, T>& supportedTypes)
+       {
+               auto supportedType = supportedTypes.find(json_object_get_string_member(root, typeName.c_str()));
+               if (supportedType == supportedTypes.end()) {
+                       throw std::invalid_argument(typeName);
                }
 
-               return colorspace;
+               LOGI("%s: %d:%s", typeName.c_str(), supportedType->second, supportedType->first.c_str());
+
+               return supportedType->second;
        }
 
        int InputMetadata::GetTensorInfo(JsonObject *root)
@@ -57,6 +70,7 @@ namespace inference
                }
 
                // tensor_info
+               int ret = MEDIA_VISION_ERROR_NONE;
                JsonArray * rootArray = json_object_get_array_member(root, "tensor_info");
                unsigned int elements = json_array_get_length(rootArray);
 
@@ -72,17 +86,14 @@ namespace inference
                                        static_cast<const char*>(json_object_get_string_member(pObject,"name"));
                        LOGI("layer: %s", info.name.c_str());
 
-                       info.shapeType =
-                                       static_cast<inference_tensor_shape_type_e>(json_object_get_int_member(pObject, "shape_type"));
-                       LOGI("shape type: %d:%s", info.shapeType, info.shapeType == 0 ? "NCHW" : "NHWC");
-
-                       info.dataType =
-                                               static_cast<mv_inference_data_type_e>(json_object_get_int_member(pObject, "data_type"));
-                       LOGI("data type : %d:%s", info.dataType, info.dataType == 0  ? "FLOAT32" : "UINT8");
-
-                       const char *colorSpace = static_cast<const char*>(json_object_get_string_member(pObject,"color_space"));
-                       info.colorSpace = ConvertTypeToMD(std::string(colorSpace));
-                       LOGI("color space : %d:%s", info.colorSpace, info.colorSpace == MEDIA_VISION_COLORSPACE_RGB888 ? "RGB888" : "");
+                       try {
+                               info.shapeType = GetSupportedType(pObject, "shape_type", mSupportedShapeType);
+                               info.dataType = GetSupportedType(pObject, "data_type", mSupportedDataType);
+                               info.colorSpace = GetSupportedType(pObject, "color_space", mSupportedColorSpace);
+                       } catch (const std::exception& e) {
+                               LOGE("Invalid %s", e.what());
+                               return MEDIA_VISION_ERROR_INVALID_OPERATION;
+                       }
 
                        // dims
                        JsonArray * array = json_object_get_array_member(pObject, "shape_dims");
@@ -99,7 +110,7 @@ namespace inference
 
                LOGI("LEAVE");
 
-               return MEDIA_VISION_ERROR_NONE;
+               return ret;
        }
 
        int InputMetadata::GetPreProcess(JsonObject *root)
index 6b97410..1462ad3 100644 (file)
@@ -1,6 +1,6 @@
 Name:        capi-media-vision
 Summary:     Media Vision library for Tizen Native API
-Version:     0.8.6
+Version:     0.8.7
 Release:     0
 Group:       Multimedia/Framework
 License:     Apache-2.0 and BSD-3-Clause