diff options
24 files changed, 88 insertions, 71 deletions
diff --git a/meta-template/README.md b/meta-template/README.md index 1e31cfce..f7fda1e2 100644 --- a/meta-template/README.md +++ b/meta-template/README.md @@ -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. diff --git a/meta-template/fd_blazeface_front_128x128.json b/meta-template/fd_blazeface_front_128x128.json index 4c94a035..a7c80413 100644 --- a/meta-template/fd_blazeface_front_128x128.json +++ b/meta-template/fd_blazeface_front_128x128.json @@ -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" } ], diff --git a/meta-template/fd_mobilenet_v1_ssd_postop_300x300.json b/meta-template/fd_mobilenet_v1_ssd_postop_300x300.json index e9aa00b4..75b5d652 100644 --- a/meta-template/fd_mobilenet_v1_ssd_postop_300x300.json +++ b/meta-template/fd_mobilenet_v1_ssd_postop_300x300.json @@ -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" } ], diff --git a/meta-template/fld_mediapipe_192x192.json b/meta-template/fld_mediapipe_192x192.json index 562fb777..ad266a8c 100644 --- a/meta-template/fld_mediapipe_192x192.json +++ b/meta-template/fld_mediapipe_192x192.json @@ -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" } ], diff --git a/meta-template/fld_tweakcnn_128x128.json b/meta-template/fld_tweakcnn_128x128.json index 7d8b48f2..0c30ad3d 100644 --- a/meta-template/fld_tweakcnn_128x128.json +++ b/meta-template/fld_tweakcnn_128x128.json @@ -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" } ], diff --git a/meta-template/ic_densenet_224x224.json b/meta-template/ic_densenet_224x224.json index 9a69d011..3e693930 100644 --- a/meta-template/ic_densenet_224x224.json +++ b/meta-template/ic_densenet_224x224.json @@ -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" } ], diff --git a/meta-template/ic_inception_resnet_v2_299x299.json b/meta-template/ic_inception_resnet_v2_299x299.json index 87d87da6..34d934ac 100644 --- a/meta-template/ic_inception_resnet_v2_299x299.json +++ b/meta-template/ic_inception_resnet_v2_299x299.json @@ -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" } ], diff --git a/meta-template/ic_inception_v3_299x299.json b/meta-template/ic_inception_v3_299x299.json index 7c2ef9f6..6e8c3f27 100644 --- a/meta-template/ic_inception_v3_299x299.json +++ b/meta-template/ic_inception_v3_299x299.json @@ -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" } ], diff --git a/meta-template/ic_inception_v4_299x299.json b/meta-template/ic_inception_v4_299x299.json index 8cd3f47e..4d31be40 100644 --- a/meta-template/ic_inception_v4_299x299.json +++ b/meta-template/ic_inception_v4_299x299.json @@ -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" } ], diff --git a/meta-template/ic_mnasnet_224x224.json b/meta-template/ic_mnasnet_224x224.json index 83938df6..e7eecf43 100644 --- a/meta-template/ic_mnasnet_224x224.json +++ b/meta-template/ic_mnasnet_224x224.json @@ -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" } ], diff --git a/meta-template/ic_mobilenet_v1_224x224.json b/meta-template/ic_mobilenet_v1_224x224.json index 2599d8c0..c68f1464 100644 --- a/meta-template/ic_mobilenet_v1_224x224.json +++ b/meta-template/ic_mobilenet_v1_224x224.json @@ -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" } ], diff --git a/meta-template/ic_mobilenet_v2_224x224.json b/meta-template/ic_mobilenet_v2_224x224.json index c0c976b7..c2bee18f 100644 --- a/meta-template/ic_mobilenet_v2_224x224.json +++ b/meta-template/ic_mobilenet_v2_224x224.json @@ -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" } ], diff --git a/meta-template/ic_nasnet_224x224.json b/meta-template/ic_nasnet_224x224.json index 8448561b..32769db1 100644 --- a/meta-template/ic_nasnet_224x224.json +++ b/meta-template/ic_nasnet_224x224.json @@ -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" } ], diff --git a/meta-template/ic_resnet_v2_299x299.json b/meta-template/ic_resnet_v2_299x299.json index 865652cd..8e6f7237 100644 --- a/meta-template/ic_resnet_v2_299x299.json +++ b/meta-template/ic_resnet_v2_299x299.json @@ -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" } ], diff --git a/meta-template/ic_squeezenet_224x224.json b/meta-template/ic_squeezenet_224x224.json index fdf00e2f..b0e8f348 100644 --- a/meta-template/ic_squeezenet_224x224.json +++ b/meta-template/ic_squeezenet_224x224.json @@ -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" } ], diff --git a/meta-template/image-classification-001-meta.json b/meta-template/image-classification-001-meta.json index 151908c8..a89bc97a 100644 --- a/meta-template/image-classification-001-meta.json +++ b/meta-template/image-classification-001-meta.json @@ -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" } ], diff --git a/meta-template/image-classification-quant-001-meta.json b/meta-template/image-classification-quant-001-meta.json index 9a44eab1..1936dbda 100644 --- a/meta-template/image-classification-quant-001-meta.json +++ b/meta-template/image-classification-quant-001-meta.json @@ -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" } ] diff --git a/meta-template/od_mobilenet_v1_ssd_postop_300x300.json b/meta-template/od_mobilenet_v1_ssd_postop_300x300.json index e9aa00b4..75b5d652 100644 --- a/meta-template/od_mobilenet_v1_ssd_postop_300x300.json +++ b/meta-template/od_mobilenet_v1_ssd_postop_300x300.json @@ -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" } ], diff --git a/meta-template/od_mobilenet_v2_ssd_320x320.json b/meta-template/od_mobilenet_v2_ssd_320x320.json index 6574f700..826640c9 100644 --- a/meta-template/od_mobilenet_v2_ssd_320x320.json +++ b/meta-template/od_mobilenet_v2_ssd_320x320.json @@ -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" } ], diff --git a/meta-template/pld_cpm_192x192.json b/meta-template/pld_cpm_192x192.json index e4f573bc..3bee725a 100644 --- a/meta-template/pld_cpm_192x192.json +++ b/meta-template/pld_cpm_192x192.json @@ -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" } ], diff --git a/meta-template/pld_mobilenet_v1_posenet_multi_257x257.json b/meta-template/pld_mobilenet_v1_posenet_multi_257x257.json index 1d69c7a1..44b942c2 100644 --- a/meta-template/pld_mobilenet_v1_posenet_multi_257x257.json +++ b/meta-template/pld_mobilenet_v1_posenet_multi_257x257.json @@ -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" } ], diff --git a/mv_machine_learning/mv_inference/inference/include/InputMetadata.h b/mv_machine_learning/mv_inference/inference/include/InputMetadata.h index 01da01cb..8b5e2bd1 100644 --- a/mv_machine_learning/mv_inference/inference/include/InputMetadata.h +++ b/mv_machine_learning/mv_inference/inference/include/InputMetadata.h @@ -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); }; diff --git a/mv_machine_learning/mv_inference/inference/src/InputMetadata.cpp b/mv_machine_learning/mv_inference/inference/src/InputMetadata.cpp index befbd434..66d257ca 100644 --- a/mv_machine_learning/mv_inference/inference/src/InputMetadata.cpp +++ b/mv_machine_learning/mv_inference/inference/src/InputMetadata.cpp @@ -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) diff --git a/packaging/capi-media-vision.spec b/packaging/capi-media-vision.spec index 6b974101..1462ad34 100644 --- a/packaging/capi-media-vision.spec +++ b/packaging/capi-media-vision.spec @@ -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 |