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 1e31cfcef6c910564a7db42b8b348639c1bb5070..f7fda1e2881c52d53cf293641f25ca76000cfbbb 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 4c94a035dafdc91c114e153059459879d84d70f4..a7c804130ac62febd0ff7f8a89591582e8a87c6c 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 e9aa00b4904762dd1d92840c8018809d0430187f..75b5d652cb4b1900ac85bb8f880744da76b7bfe5 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 562fb77765b4fe6cc458b877b265ff84ad4a3837..ad266a8c52641a64f8b9fce36e877f637fd374b1 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 7d8b48f253a64bc8254600b674cd204e68b26157..0c30ad3d40a25ba91fd6f3ccef9fb524e48131a2 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 9a69d0114b2cec6b4d82e5ab0dc59bea822551fa..3e693930010d219b043fe5a936a4f97d942d9e8c 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 87d87da6a91bb71a4b1d182e6774e617f9eac6db..34d934ac7f442c945e1f6b6eec582ff44d698208 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 7c2ef9f6cdb6399f2429d42ac1883bd47a24fff5..6e8c3f27ae9318a344fb5902016bb98f1cb33fe1 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 8cd3f47ed7addf719bc4c520d929ed7a6d78f7a7..4d31be40727e995c6bf6bfe736c94a7ae6512404 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 83938df6bf6c07ab2c546d2f688c2126ea7b19a4..e7eecf43c05d5d525c28b98c20bff01cc1acc31a 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 2599d8c0b4e491a3dcb0ae4b876299a8e1d47f13..c68f146444dc9a1e8906cf0dc9807bc1109f1724 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 c0c976b72c3e982641e95f185394776f2f1df790..c2bee18f808b35118826566d42ab19d2f9a7436a 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 8448561b1b3408871014f9d0377c79a6c19a79ed..32769db1eaf8f2d1bedc2bd76a4542978dd45cbc 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 865652cdd8dab00695eabce95e79238893aa8af0..8e6f723756140861f53e1d4dd1000a516b92dae8 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 fdf00e2f163ef1cd760a1c9eec15a6a9ff6d7cfe..b0e8f348c287883e9edf0bf061cdeb403a067e3e 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 151908c8600749657328daad1072aeb15322a8bd..a89bc97a3d2120be8e28b81ff51bd705601c31cd 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 9a44eab1d5bf2fa88cbef4af09e7a2b79fa63f73..1936dbda6d8d4680fdbbcd2ec616136a970e0b0e 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 e9aa00b4904762dd1d92840c8018809d0430187f..75b5d652cb4b1900ac85bb8f880744da76b7bfe5 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 6574f7006d3ee044aa011782cc35a1e1e9b2ac5c..826640c93f50d6ada8bdcb90053bc3241c3d7c5d 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 e4f573bca53fd95b28e59fa3aa57269f79c4d739..3bee725af532756e870577ae5b565edb44a1c573 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 1d69c7a136e671039bae457bcac9e1433e3d0fb9..44b942c29e9ce68200076ba802b2e7b724f07253 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 01da01cb0a4d95547160c6b12e61b3c8a5177deb..8b5e2bd1f9097925c843d0be314d2d1e7649e6b7 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 befbd434319ab5ad5226fe464b8f0426b46e0216..66d257caa0275752ea00783668b1540feaa88e62 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 6b97410132fa93254eb286a82f789b1dfcee66f1..1462ad34d74872b8e269499cd3f80edb41926b51 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