From: Hyunsoo Park Date: Fri, 17 Dec 2021 07:49:05 +0000 (+0900) Subject: tools: Add metadata class to correspond to multiple output layers X-Git-Tag: submit/tizen/20220105.080154~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=052c0f627d482d1fe55229561950ec5b339d5e0b;p=platform%2Fcore%2Fmultimedia%2Finference-engine-interface.git tools: Add metadata class to correspond to multiple output layers [Version] 0.2.2-0 [Issue Type] Update feature Change-Id: I91cd820a301e142c5878706593ff12bf2608c939 Signed-off-by: Hyunsoo Park --- diff --git a/packaging/inference-engine-interface.spec b/packaging/inference-engine-interface.spec index 6b32047..faced4f 100644 --- a/packaging/inference-engine-interface.spec +++ b/packaging/inference-engine-interface.spec @@ -1,6 +1,6 @@ Name: inference-engine-interface Summary: Interface of inference engines -Version: 0.3.0 +Version: 0.3.1 Release: 0 Group: Multimedia/Framework License: Apache-2.0 diff --git a/tools/include/OutputMetadata.h b/tools/include/OutputMetadata.h index 5d242aa..92f4b85 100644 --- a/tools/include/OutputMetadata.h +++ b/tools/include/OutputMetadata.h @@ -17,18 +17,18 @@ #ifndef __INFERENCE_ENGINE_OUTPUTMETADATA_H__ #define __INFERENCE_ENGINE_OUTPUTMETADATA_H__ -#include -#include #include #include +#include +#include -#include +#include "inference_engine_error.h" #include "inference_engine_private_type.h" #include "inference_engine_type.h" -#include "inference_engine_error.h" +#include -#include #include "OutputMetadataTypes.h" +#include /** * @file OutputMetadata.h @@ -88,13 +88,179 @@ namespace Cltuner int ParseScore(JsonObject *root); }; + class BoxInfo + { + private: + std::string name; + DimInfo dimInfo; + inference_box_type_e type; + std::vector order; + inference_box_coordinate_type_e coordinate; + inference_box_decoding_type_e decodingType; + + std::map supportedBoxTypes; + std::map supportedBoxCoordinateTypes; + std::map supportedBoxDecodingTypes; + + public: + BoxInfo(); + ~BoxInfo() = default; + + std::string GetName() { return name; } + DimInfo GetDimInfo() { return dimInfo; } + inference_box_type_e GetType() { return type; } + inference_box_decoding_type_e GetDecodingType() { return decodingType; } + std::vector GetOrder() { return order; } + int GetCoordinate() { return coordinate; } + + int ParseBox(JsonObject *root); + }; + + class Label + { + private: + std::string name; + DimInfo dimInfo; + inference_box_decoding_type_e decodingType; + + public: + Label() = default; + ~Label() = default; + std::string GetName() { return name; } + DimInfo GetDimInfo() { return dimInfo; } + + int ParseLabel(JsonObject *root); + }; + + class Number + { + private: + std::string name; + DimInfo dimInfo; + + public: + Number() = default; + ~Number() = default; + std::string GetName() { return name; } + DimInfo GetDimInfo() { return dimInfo; } + + int ParseNumber(JsonObject *root); + }; + + class Landmark + { + public: + class DecodeInfo { + public: + class HeatMapInfo { + public: + int wIdx; + int hIdx; + int cIdx; + inference_tensor_shape_type_e shapeType; + float nmsRadius; + HeatMapInfo() = default; + ~HeatMapInfo() = default; + }; + HeatMapInfo heatMap; + DecodeInfo() = default; + ~DecodeInfo() = default; + }; + private: + std::string name; + DimInfo dimInfo; + inference_landmark_type_e type; + int offset; + inference_landmark_coorindate_type_e coordinate; + inference_landmark_decoding_type_e decodingType; + DecodeInfo decodingInfo; + + std::map supportedLandmarkTypes; + std::map supportedLandmarkCoordinateTypes; + std::map supportedLandmarkDecodingTypes; + + public: + Landmark(); + ~Landmark() = default; + std::string GetName() { return name; } + DimInfo GetDimInfo() { return dimInfo; } + inference_landmark_type_e GetType(); + int GetOffset(); + inference_landmark_coorindate_type_e GetCoordinate(); + inference_landmark_decoding_type_e GetDecodingType(); + DecodeInfo& GetDecodingInfo(); + + int ParseLandmark(JsonObject *root); + }; + + class OffsetVec + { + private: + std::string name; + DimInfo dimInfo; + int shapeType; + public: + OffsetVec() = default; + ~OffsetVec() = default; + std::string GetName() { return name; } + DimInfo GetDimInfo() { return dimInfo; } + int GetShapeType() { return shapeType; } + + int ParseOffset(JsonObject *root); + }; + + class DispVec + { + private: + std::string name; + DimInfo dimInfo; + inference_displacement_type_e type; + int shapeType; + std::map supportedDispTypes; + public: + DispVec(); + ~DispVec() = default; + std::string GetName() { return name; } + DimInfo GetDimInfo() { return dimInfo; } + inference_displacement_type_e GetType() { return type; } + int GetShapeType() { return shapeType; } + + int ParseDisplacement(JsonObject *root); + }; + + class Edge + { + private: + std::vector> edges; + public: + Edge() = default; + ~Edge() = default; + int ParseEdge(JsonObject *root); + std::vector>& GetEdgesAll(); + }; + class OutputMetadata { private: bool parsed; ScoreInfo score; + BoxInfo box; + Label label; + Number number; + Landmark landmark; + OffsetVec offsetVec; + std::vector dispVecs; + Edge edgeMap; int ParseScore(JsonObject *root); + int ParseBox(JsonObject *root); + int ParseLabel(JsonObject *root); + int ParseNumber(JsonObject *root); + int ParseLandmark(JsonObject *root); + int ParseLandmarkDecodeInfo(JsonObject *root); + int ParseOffset(JsonObject *root); + int ParseDisplacement(JsonObject *root); + int ParseEdgeMap(JsonObject *root); public: static std::map supportedTensorShapes; @@ -121,6 +287,13 @@ namespace Cltuner bool IsParsed(); ScoreInfo& GetScore(); + BoxInfo& GetBox(); + Label& GetLabel(); + Number& GetNumber(); + Landmark& GetLandmark(); + OffsetVec& GetOffset(); + std::vector& GetDispVecAll(); + template static T GetSupportedType(JsonObject* root, std::string typeName, std::map& supportedTypes); diff --git a/tools/src/InputMetadata.cpp b/tools/src/InputMetadata.cpp index d4c3c5d..5a71e50 100644 --- a/tools/src/InputMetadata.cpp +++ b/tools/src/InputMetadata.cpp @@ -89,7 +89,7 @@ namespace Cltuner JsonObject *pObject = json_node_get_object(pNode); info.name = - static_cast(json_object_get_string_member(pObject,"name")); + static_cast(json_object_get_string_member(pObject, "name")); LOGI("layer: %s", info.name.c_str()); try { diff --git a/tools/src/OutputMetadata.cpp b/tools/src/OutputMetadata.cpp index 5f0f0a2..b11aea1 100755 --- a/tools/src/OutputMetadata.cpp +++ b/tools/src/OutputMetadata.cpp @@ -14,13 +14,22 @@ * limitations under the License. */ -#include +#include "OutputMetadata.h" +#include #include -#include #include -#include -#include "OutputMetadata.h" +#include +#include + +extern "C" +{ +#ifdef LOG_TAG +#undef LOG_TAG +#endif +#define MAX_STR 256 +#define LOG_TAG "INFERENCE_ENGINE_CLTUNER" +} namespace InferenceEngineInterface { namespace Cltuner @@ -73,7 +82,7 @@ namespace Cltuner JsonNode *pNode = json_array_get_element(rootArray, elem); JsonObject *pObject = json_node_get_object(pNode); - name = json_object_get_string_member(pObject,"name"); + name = json_object_get_string_member(pObject, "name"); LOGI("layer: %s", name.c_str()); JsonArray * array = json_object_get_array_member(pObject, "index"); @@ -122,48 +131,629 @@ namespace Cltuner return score.ParseScore(root); } + int OutputMetadata::Parse(JsonObject *root) + { + LOGI("ENTER"); + + int ret = ParseScore(root); + if (ret != INFERENCE_ENGINE_ERROR_NONE) { + LOGE("Fail to ParseScore[%d]", ret); + return ret; + } + + ret = ParseBox(root); + if (ret != INFERENCE_ENGINE_ERROR_NONE) { + LOGE("Fail to ParseBox[%d]", ret); + return ret; + } + + if (!box.GetName().empty()) { + // addtional parsing is required according to decoding type + + switch (box.GetDecodingType()) { + case INFERENCE_BOX_DECODING_TYPE_BYPASS: + ret = ParseLabel(root); + if (ret != INFERENCE_ENGINE_ERROR_NONE) { + LOGE("Fail to ParseLabel[%d]", ret); + return ret; + } + + ret = ParseNumber(root); + if (ret != INFERENCE_ENGINE_ERROR_NONE) { + LOGE("Fail to ParseNumber[%d]", ret); + return ret; + } + + break; + case INFERENCE_BOX_DECODING_TYPE_SSD_ANCHOR: + LOGW("Not support because of OpenCV dependency. Ignore"); + break; + default: + LOGW("Unknown box decoding type. Ignore"); + } + } + + ret = ParseLandmark(root); + if (ret != INFERENCE_ENGINE_ERROR_NONE) { + LOGE("Fail to GetLandmark[%d]", ret); + return ret; + } + + if (!landmark.GetName().empty()) { + switch (landmark.GetDecodingType()) { + case INFERENCE_LANDMARK_DECODING_TYPE_BYPASS: + ret = ParseLandmarkDecodeInfo(root); + if (ret != INFERENCE_ENGINE_ERROR_NONE) { + LOGE("Fail to ParseLandmarkDecodeInfo[%d]", ret); + return ret; + } + + break; + case INFERENCE_LANDMARK_DECODING_TYPE_HEATMAP_REFINE: + ret = ParseOffset(root); + if (ret != INFERENCE_ENGINE_ERROR_NONE) { + LOGE("Fail to ParseOffset[%d]", ret); + return ret; + } + + ret = ParseDisplacement(root); + if (ret != INFERENCE_ENGINE_ERROR_NONE) { + LOGE("Fail to ParseDisplacement[%d]", ret); + return ret; + } + + ret = ParseEdgeMap(root); + if (ret != INFERENCE_ENGINE_ERROR_NONE) { + LOGE("Fail to ParseEdgeMap[%d]", ret); + return ret; + } + + break; + default: + LOGW("Unknown landmark decoding type. Ignore"); + } + } + parsed = true; + + LOGI("LEAVE"); + + return INFERENCE_ENGINE_ERROR_NONE; + } + + void DimInfo::SetValidIndex(int index) + { + LOGI("ENTER"); + + dims.push_back(index); + + LOGI("LEAVE"); + } + + std::vector DimInfo::GetValidIndexAll() const + { + LOGI("ENTER"); + + LOGI("LEAVE"); + return dims; + } + + BoxInfo::BoxInfo() : + name(), + dimInfo(), + type(INFERENCE_BOX_TYPE_ORIGIN_LEFTTOP), + order(), + coordinate(INFERENCE_BOX_COORDINATE_TYPE_RATIO), + decodingType(INFERENCE_BOX_DECODING_TYPE_BYPASS) + { + supportedBoxTypes.insert({"ORIGIN_LEFTTOP", INFERENCE_BOX_TYPE_ORIGIN_LEFTTOP}); + supportedBoxTypes.insert({"ORIGIN_CENTER", INFERENCE_BOX_TYPE_ORIGIN_CENTER}); + + supportedBoxCoordinateTypes.insert({"RATIO", INFERENCE_BOX_COORDINATE_TYPE_RATIO}); + supportedBoxCoordinateTypes.insert({"PIXEL", INFERENCE_BOX_COORDINATE_TYPE_PIXEL}); + + supportedBoxDecodingTypes.insert({"BYPASS", INFERENCE_BOX_DECODING_TYPE_BYPASS}); + supportedBoxDecodingTypes.insert({"SSD_ANCHOR", INFERENCE_BOX_DECODING_TYPE_SSD_ANCHOR}); + } + + int BoxInfo::ParseBox(JsonObject *root) + { + LOGI("ENTER"); + + JsonArray * rootArray = json_object_get_array_member(root, "box"); + unsigned int elements = json_array_get_length(rootArray); + + for (unsigned int elem = 0; elem < elements; ++elem) { + JsonNode *pNode = json_array_get_element(rootArray, elem); + JsonObject *pObject = json_node_get_object(pNode); + + name = json_object_get_string_member(pObject, "name"); + LOGI("layer: %s", name.c_str()); + + JsonArray * array = json_object_get_array_member(pObject, "index"); + unsigned int elements2 = json_array_get_length(array); + LOGI("range dim: size[%u]", elements2); + for (unsigned int elem2 = 0; elem2 < elements2; ++elem2) { + if (static_cast(json_array_get_int_element(array, elem2)) == 1) + dimInfo.SetValidIndex(elem2); + } + + try { + type = OutputMetadata::GetSupportedType(pObject, "box_type", supportedBoxTypes); + coordinate = OutputMetadata::GetSupportedType(pObject, "box_coordinate", supportedBoxCoordinateTypes); + decodingType = OutputMetadata::GetSupportedType(pObject, "decoding_type", supportedBoxDecodingTypes); + } catch (const std::exception& e) { + LOGE("Invalid %s", e.what()); + return INFERENCE_ENGINE_ERROR_INVALID_OPERATION; + } + + array = json_object_get_array_member(pObject, "box_order"); + elements2 = json_array_get_length(array); + LOGI("box order should have 4 elements and it has [%u]", elements2); + for (unsigned int elem2 = 0; elem2 < elements2; ++elem2) { + auto val = static_cast(json_array_get_int_element(array, elem2)); + order.push_back(val); + LOGI("%d", val); + } + } + + LOGI("LEAVE"); + return INFERENCE_ENGINE_ERROR_NONE; + } + + int OutputMetadata::ParseBox(JsonObject *root) + { + if (!json_object_has_member(root, "box")) { + LOGE("No box outputmetadata"); + return INFERENCE_ENGINE_ERROR_NONE; + } + + return box.ParseBox(root); + } + + int Label::ParseLabel(JsonObject *root) + { + LOGI("ENTER"); + + JsonArray * rootArray = json_object_get_array_member(root, "label"); + unsigned int elements = json_array_get_length(rootArray); + + // TODO: handling error + for (unsigned int elem = 0; elem < elements; ++elem) { + JsonNode *pNode = json_array_get_element(rootArray, elem); + JsonObject *pObject = json_node_get_object(pNode); + + name = json_object_get_string_member(pObject, "name"); + LOGI("layer: %s", name.c_str()); + + JsonArray * array = json_object_get_array_member(pObject, "index"); + unsigned int elements2 = json_array_get_length(array); + LOGI("range dim: size[%u]", elements2); + for (unsigned int elem2 = 0; elem2 < elements2; ++elem2) { + if (static_cast(json_array_get_int_element(array, elem2)) == 1) + dimInfo.SetValidIndex(elem2); + } + } + + LOGI("LEAVE"); + return INFERENCE_ENGINE_ERROR_NONE; + } + + int OutputMetadata::ParseLabel(JsonObject *root) + { + LOGI("ENTER"); + + if (!json_object_has_member(root, "label")) { + LOGE("No box outputmetadata"); + LOGI("LEAVE"); + return INFERENCE_ENGINE_ERROR_INVALID_OPERATION; + } + + label.ParseLabel(root); + + LOGI("LEAVE"); + return INFERENCE_ENGINE_ERROR_NONE; + } + + int Number::ParseNumber(JsonObject *root) + { + // box + JsonArray * rootArray = json_object_get_array_member(root, "number"); + unsigned int elements = json_array_get_length(rootArray); + + // TODO: handling error + for (unsigned int elem = 0; elem < elements; ++elem) { + JsonNode *pNode = json_array_get_element(rootArray, elem); + JsonObject *pObject = json_node_get_object(pNode); + + name = json_object_get_string_member(pObject, "name"); + LOGI("layer: %s", name.c_str()); + + JsonArray * array = json_object_get_array_member(pObject, "index"); + unsigned int elements2 = json_array_get_length(array); + LOGI("range dim: size[%u]", elements2); + for (unsigned int elem2 = 0; elem2 < elements2; ++elem2) { + if (static_cast(json_array_get_int_element(array, elem2)) == 1) + dimInfo.SetValidIndex(elem2); + } + } + + return INFERENCE_ENGINE_ERROR_NONE; + } + + int OutputMetadata::ParseNumber(JsonObject *root) + { + LOGI("ENTER"); + + if (!json_object_has_member(root, "number")) { + LOGE("No number outputmetadata"); + LOGI("LEAVE"); + return INFERENCE_ENGINE_ERROR_INVALID_OPERATION; + } + number.ParseNumber(root); + + LOGI("LEAVE"); + return INFERENCE_ENGINE_ERROR_NONE; + } + + int Edge::ParseEdge(JsonObject *root) + { + LOGI("ENTER"); + JsonArray * rootArray = json_object_get_array_member(root, "edgemap"); + unsigned int elements = json_array_get_length(rootArray); + + // TODO: handling error + int pEdgeNode, cEdgeNode; + for (unsigned int elem = 0; elem < elements; ++elem) { + + JsonNode *pNode = json_array_get_element(rootArray, elem); + JsonObject *pObject = json_node_get_object(pNode); + + pEdgeNode = json_object_get_int_member(pObject, "parent"); + cEdgeNode = json_object_get_int_member(pObject, "child"); + + edges.push_back(std::make_pair(pEdgeNode, cEdgeNode)); + LOGI("%ud: parent - child: %d - %d", elem, pEdgeNode, cEdgeNode); + } + LOGI("LEAVE"); + return INFERENCE_ENGINE_ERROR_NONE; + } + + int OutputMetadata::ParseEdgeMap(JsonObject * root) + { + LOGI("ENTER"); + + if (!json_object_has_member(root, "edgemap")) { + LOGI("No edgemap outputmetadata"); + LOGI("LEAVE"); + return INFERENCE_ENGINE_ERROR_INVALID_OPERATION; + } + + edgeMap.ParseEdge(root); + + LOGI("LEAVE"); + return INFERENCE_ENGINE_ERROR_NONE; + } + ScoreInfo& OutputMetadata::GetScore() { return score; } + BoxInfo& OutputMetadata::GetBox() + { + return box; + } + + Label& OutputMetadata::GetLabel() + { + return label; + } + + Number& OutputMetadata::GetNumber() + { + return number; + } + + Landmark& OutputMetadata::GetLandmark() + { + return landmark; + } + + OffsetVec& OutputMetadata::GetOffset() + { + return offsetVec; + } + + std::vector& OutputMetadata::GetDispVecAll() + { + return dispVecs; + } + bool OutputMetadata::IsParsed() { return parsed; } - int OutputMetadata::Parse(JsonObject *root) + Landmark::Landmark() : + name(), + dimInfo(), + type(INFERENCE_LANDMARK_TYPE_2D_SINGLE), + offset(), + coordinate(INFERENCE_LANDMARK_COORDINATE_TYPE_RATIO), + decodingType(INFERENCE_LANDMARK_DECODING_TYPE_BYPASS), + decodingInfo() + + { + supportedLandmarkTypes.insert({"2D_SINGLE", INFERENCE_LANDMARK_TYPE_2D_SINGLE}); + supportedLandmarkTypes.insert({"2D_MULTI", INFERENCE_LANDMARK_TYPE_2D_MULTI}); + supportedLandmarkTypes.insert({"3D_SINGLE", INFERENCE_LANDMARK_TYPE_3D_SINGLE}); + + supportedLandmarkCoordinateTypes.insert({"RATIO", INFERENCE_LANDMARK_COORDINATE_TYPE_RATIO}); + supportedLandmarkCoordinateTypes.insert({"PIXEL", INFERENCE_LANDMARK_COORDINATE_TYPE_PIXEL}); + + supportedLandmarkDecodingTypes.insert({"BYPASS", INFERENCE_LANDMARK_DECODING_TYPE_BYPASS}); + supportedLandmarkDecodingTypes.insert({"HEATMAP", INFERENCE_LANDMARK_DECODING_TYPE_HEATMAP}); + supportedLandmarkDecodingTypes.insert({"HEATMAP_REFINE", INFERENCE_LANDMARK_DECODING_TYPE_HEATMAP_REFINE}); + } + + int Landmark::ParseLandmark(JsonObject *root) + { + // box + JsonArray * rootArray = json_object_get_array_member(root, "landmark"); + unsigned int elements = json_array_get_length(rootArray); + + // TODO: handling error + for (unsigned int elem = 0; elem < elements; ++elem) { + + JsonNode *pNode = json_array_get_element(rootArray, elem); + JsonObject *pObject = json_node_get_object(pNode); + + name = + static_cast(json_object_get_string_member(pObject, "name")); + LOGI("layer: %s", name.c_str()); + + JsonArray * array = json_object_get_array_member(pObject, "index"); + unsigned int elements2 = json_array_get_length(array); + LOGI("range dim: size[%u]", elements2); + for (unsigned int elem2 = 0; elem2 < elements2; ++elem2) { + if (static_cast(json_array_get_int_element(array, elem2)) == 1) + dimInfo.SetValidIndex(elem2); + } + + try { + type = OutputMetadata::GetSupportedType(pObject, "landmark_type", supportedLandmarkTypes); + coordinate = OutputMetadata::GetSupportedType(pObject, "landmark_coordinate", supportedLandmarkCoordinateTypes); + decodingType = OutputMetadata::GetSupportedType(pObject, "decoding_type", supportedLandmarkDecodingTypes); + } catch (const std::exception& e) { + LOGE("Invalid %s", e.what()); + return INFERENCE_ENGINE_ERROR_INVALID_OPERATION; + } + + offset = static_cast(json_object_get_int_member(pObject, "landmark_offset")); + LOGI("landmark offset: %d", offset); + } + + LOGI("LEAVE"); + return INFERENCE_ENGINE_ERROR_NONE; + } + + inference_landmark_type_e Landmark::GetType() + { + return type; + } + + int Landmark::GetOffset() + { + return offset; + } + + inference_landmark_coorindate_type_e Landmark::GetCoordinate() + { + return coordinate; + } + + inference_landmark_decoding_type_e Landmark::GetDecodingType() + { + return decodingType; + } + + Landmark::DecodeInfo& Landmark::GetDecodingInfo() + { + return decodingInfo; + } + + int OutputMetadata::ParseLandmark(JsonObject *root) { LOGI("ENTER"); - int ret = ParseScore(root); - if (ret != INFERENCE_ENGINE_ERROR_NONE) { - LOGE("Fail to GetScore[%d]", ret); - return ret; + if (!json_object_has_member(root, "landmark")) { + LOGI("No landmark outputmetadata"); + LOGI("LEAVE"); + return INFERENCE_ENGINE_ERROR_NONE; } - parsed = true; + landmark.ParseLandmark(root); LOGI("LEAVE"); + return INFERENCE_ENGINE_ERROR_NONE; + } + + int OutputMetadata::ParseLandmarkDecodeInfo(JsonObject *root) + { + LOGI("ENTER"); + if (!json_object_has_member(root, "landmark")) { + LOGI("No landmark outputmetadata"); + LOGI("LEAVE"); + return INFERENCE_ENGINE_ERROR_NONE; + } + + // box + JsonArray * rootArray = json_object_get_array_member(root, "landmark"); + unsigned int elements = json_array_get_length(rootArray); + + // TODO: handling error + for (unsigned int elem = 0; elem < elements; ++elem) { + + JsonNode *pNode = json_array_get_element(rootArray, elem); + JsonObject *pObject = json_node_get_object(pNode); + + if (!json_object_has_member(pObject, "decoding_info")) { + LOGE("decoding_info is mandatory. Invalid metadata"); + LOGI("LEAVE"); + + return INFERENCE_ENGINE_ERROR_INVALID_OPERATION; + } + + JsonObject *cObject = json_object_get_object_member(pObject, "decoding_info"); + if (!json_object_has_member(cObject, "heatmap")) { + LOGE("heatmap is mandatory. Invalid metadata"); + LOGI("LEAVE"); + + return INFERENCE_ENGINE_ERROR_INVALID_OPERATION; + } + + JsonObject *object = json_object_get_object_member(cObject, "heatmap") ; + try { + landmark.GetDecodingInfo().heatMap.shapeType = OutputMetadata::GetSupportedType(object, "shape_type", supportedTensorShapes); + } catch (const std::exception& e) { + LOGE("Invalid %s", e.what()); + return INFERENCE_ENGINE_ERROR_INVALID_OPERATION; + } + + std::vector heatMapIndexes = landmark.GetDimInfo().GetValidIndexAll(); + if (landmark.GetDecodingInfo().heatMap.shapeType == INFERENCE_TENSOR_SHAPE_NCHW) { + landmark.GetDecodingInfo().heatMap.cIdx = heatMapIndexes[0]; + landmark.GetDecodingInfo().heatMap.hIdx = heatMapIndexes[1]; + landmark.GetDecodingInfo().heatMap.wIdx = heatMapIndexes[2]; + } else { + landmark.GetDecodingInfo().heatMap.hIdx = heatMapIndexes[0]; + landmark.GetDecodingInfo().heatMap.wIdx = heatMapIndexes[1]; + landmark.GetDecodingInfo().heatMap.cIdx = heatMapIndexes[2]; + } + + if (json_object_has_member(object, "nms_radius")) { + landmark.GetDecodingInfo().heatMap.nmsRadius = static_cast(json_object_get_double_member(object, "nms_radius")); + LOGI("nms is enabled with %3.f", landmark.GetDecodingInfo().heatMap.nmsRadius ); + } + } + + LOGI("LEAVE"); return INFERENCE_ENGINE_ERROR_NONE; } - void DimInfo::SetValidIndex(int index) + int OffsetVec::ParseOffset(JsonObject *root) + { + JsonArray * rootArray = json_object_get_array_member(root, "offset"); + unsigned int elements = json_array_get_length(rootArray); + + // TODO: handling error + for (unsigned int elem = 0; elem < elements; ++elem) { + + JsonNode *pNode = json_array_get_element(rootArray, elem); + JsonObject *pObject = json_node_get_object(pNode); + + name = + static_cast(json_object_get_string_member(pObject, "name")); + LOGI("layer: %s", name.c_str()); + + JsonArray * array = json_object_get_array_member(pObject, "index"); + unsigned int elements2 = json_array_get_length(array); + LOGI("range dim: size[%u]", elements2); + for (unsigned int elem2 = 0; elem2 < elements2; ++elem2) { + if (static_cast(json_array_get_int_element(array, elem2)) == 1) + dimInfo.SetValidIndex(elem2); + } + + try { + shapeType = OutputMetadata::GetSupportedType(pObject, "shape_type", OutputMetadata::supportedTensorShapes); + } catch (const std::exception& e) { + LOGE("Invalid %s", e.what()); + return INFERENCE_ENGINE_ERROR_INVALID_OPERATION; + } + + } + + LOGI("LEAVE"); + return INFERENCE_ENGINE_ERROR_NONE; + } + + int OutputMetadata::ParseOffset(JsonObject *root) { LOGI("ENTER"); - dims.push_back(index); + if (!json_object_has_member(root, "offset")) { + LOGI("No offset outputmetadata"); + LOGI("LEAVE"); + return INFERENCE_ENGINE_ERROR_INVALID_OPERATION; + } + + offsetVec.ParseOffset(root); LOGI("LEAVE"); + return INFERENCE_ENGINE_ERROR_NONE; } - std::vector DimInfo::GetValidIndexAll() const + DispVec::DispVec() : + name(), + dimInfo(), + type(INFERENCE_DISPLACEMENT_TYPE_FORWARD), + shapeType(INFERENCE_TENSOR_SHAPE_NCHW) + { + supportedDispTypes.insert({"FORWARD", INFERENCE_DISPLACEMENT_TYPE_FORWARD}); + supportedDispTypes.insert({"BACKWARD", INFERENCE_DISPLACEMENT_TYPE_BACKWARD}); + } + + int DispVec::ParseDisplacement(JsonObject *root) { LOGI("ENTER"); + name = + static_cast(json_object_get_string_member(root, "name")); + LOGI("layer: %s", name.c_str()); + + JsonArray * array = json_object_get_array_member(root, "index"); + unsigned int elements2 = json_array_get_length(array); + LOGI("range dim: size[%u]", elements2); + for (unsigned int elem2 = 0; elem2 < elements2; ++elem2) { + if(static_cast(json_array_get_int_element(array, elem2)) == 1) + dimInfo.SetValidIndex(elem2); + } + + try { + shapeType = OutputMetadata::GetSupportedType(root, "shape_type", OutputMetadata::supportedTensorShapes); + type = OutputMetadata::GetSupportedType(root, "type", supportedDispTypes); + } catch (const std::exception& e) { + LOGE("Invalid %s", e.what()); + return INFERENCE_ENGINE_ERROR_INVALID_OPERATION; + } LOGI("LEAVE"); - return dims; + return INFERENCE_ENGINE_ERROR_NONE; + } + + int OutputMetadata::ParseDisplacement(JsonObject *root) + { + LOGI("ENTER"); + + if (!json_object_has_member(root, "displacement")) { + LOGI("No displacement outputmetadata"); + LOGI("LEAVE"); + return INFERENCE_ENGINE_ERROR_INVALID_OPERATION; + } + + JsonArray * rootArray = json_object_get_array_member(root, "displacement"); + unsigned int elements = json_array_get_length(rootArray); + + dispVecs.resize(elements); + unsigned int elem = 0; + for (auto& disp : dispVecs) { + JsonNode *pNode = json_array_get_element(rootArray, elem++); + JsonObject *pObject = json_node_get_object(pNode); + disp.ParseDisplacement(pObject); + } + + LOGI("LEAVE"); + return INFERENCE_ENGINE_ERROR_NONE; } } /* Inference */ } /* MediaVision */ diff --git a/tools/src/inference_engine_cltuner.cpp b/tools/src/inference_engine_cltuner.cpp index 277dd77..ee9b0eb 100644 --- a/tools/src/inference_engine_cltuner.cpp +++ b/tools/src/inference_engine_cltuner.cpp @@ -138,7 +138,30 @@ int ConfigureOutputInfo(InferenceEngineCommon* backend, Metadata& metadata, tensorConfig.mOutputLayerNames.clear(); if (!outputMeta.GetScore().GetName().empty()) tensorConfig.mOutputLayerNames.push_back( - outputMeta.GetScore().GetName()); + outputMeta.GetScore().GetName()); + + if (!outputMeta.GetBox().GetName().empty()) + tensorConfig.mOutputLayerNames.push_back( + outputMeta.GetBox().GetName()); + + if (!outputMeta.GetLabel().GetName().empty()) + tensorConfig.mOutputLayerNames.push_back( + outputMeta.GetLabel().GetName()); + + if (!outputMeta.GetNumber().GetName().empty()) + tensorConfig.mOutputLayerNames.push_back( + outputMeta.GetNumber().GetName()); + + if (!outputMeta.GetLandmark().GetName().empty()) + tensorConfig.mOutputLayerNames.push_back( + outputMeta.GetLandmark().GetName()); + + if (!outputMeta.GetOffset().GetName().empty()) + tensorConfig.mOutputLayerNames.push_back( + outputMeta.GetOffset().GetName()); + + for (auto& dispVec : outputMeta.GetDispVecAll()) + tensorConfig.mOutputLayerNames.push_back(dispVec.GetName()); inference_engine_layer_property property; inference_engine_tensor_info tensor_info = {