diff options
author | Kwanghoon Son <k.son@samsung.com> | 2022-08-25 22:00:57 -0400 |
---|---|---|
committer | Inki Dae <inki.dae@samsung.com> | 2022-09-02 17:09:25 +0900 |
commit | fa6bfdb69365fb4285322eccc86aec19516e24d0 (patch) | |
tree | 190023b923afaa2b4770956a46afd0156956915d | |
parent | 1b01e0440e55b5baf5daecbb27f28e1b15386642 (diff) | |
download | mediavision-fa6bfdb69365fb4285322eccc86aec19516e24d0.tar.gz mediavision-fa6bfdb69365fb4285322eccc86aec19516e24d0.tar.bz2 mediavision-fa6bfdb69365fb4285322eccc86aec19516e24d0.zip |
Apply code lint and update copyright year
Change-Id: I53fd18c3c5b3961b8c7e8fb903199e4150bf03e3
Signed-off-by: Kwanghoon Son <k.son@samsung.com>
-rw-r--r-- | mv_machine_learning/inference/include/ScoreInfo.h | 205 |
1 files changed, 116 insertions, 89 deletions
diff --git a/mv_machine_learning/inference/include/ScoreInfo.h b/mv_machine_learning/inference/include/ScoreInfo.h index 20040021..096a120c 100644 --- a/mv_machine_learning/inference/include/ScoreInfo.h +++ b/mv_machine_learning/inference/include/ScoreInfo.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2021 - 2022 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,103 +30,130 @@ namespace mediavision { namespace inference { - struct DeQuantization +struct DeQuantization +{ + double scale; + double zeropoint; + + DeQuantization(double s, double z) : scale(s), zeropoint(z) + {} +}; + +class ScoreInfo +{ +private: + std::string name; + DimInfo dimInfo; + double threshold; + int topNumber; + inference_score_type_e type; + std::shared_ptr<DeQuantization> deQuantization; + std::map<std::string, inference_score_type_e> supportedScoreTypes; + +public: + ScoreInfo() + : name() + , dimInfo() + , threshold(0.0) + , topNumber(1) + , type(INFERENCE_SCORE_TYPE_NORMAL) + , deQuantization(nullptr) { - double scale; - double zeropoint; + // Score type + supportedScoreTypes.insert({ "NORMAL", INFERENCE_SCORE_TYPE_NORMAL }); + supportedScoreTypes.insert({ "SIGMOID", INFERENCE_SCORE_TYPE_SIGMOID }); + } - DeQuantization(double s, double z) : scale(s), zeropoint(z) { } - }; + ~ScoreInfo() = default; - class ScoreInfo + std::string GetName() { - private: - std::string name; - DimInfo dimInfo; - double threshold; - int topNumber; - inference_score_type_e type; - std::shared_ptr<DeQuantization> deQuantization; - std::map<std::string, inference_score_type_e> supportedScoreTypes; - - public: - ScoreInfo() : - name(), - dimInfo(), - threshold(0.0), - topNumber(1), - type(INFERENCE_SCORE_TYPE_NORMAL), - deQuantization(nullptr) - { - // Score type - supportedScoreTypes.insert({"NORMAL", INFERENCE_SCORE_TYPE_NORMAL}); - supportedScoreTypes.insert({"SIGMOID", INFERENCE_SCORE_TYPE_SIGMOID}); - } + return name; + } + DimInfo GetDimInfo() + { + return dimInfo; + } + double GetThresHold() + { + return threshold; + } + inference_score_type_e GetType() + { + return type; + } + int GetTopNumber() + { + return topNumber; + } + std::shared_ptr<DeQuantization> GetDeQuant() + { + return deQuantization; + } + double GetDeQuantScale() + { + return deQuantization->scale; + } + double GetDeQuantZeroPoint() + { + return deQuantization->zeropoint; + } - ~ScoreInfo() = default; - - std::string GetName() { return name; } - DimInfo GetDimInfo() { return dimInfo; } - double GetThresHold() { return threshold; } - inference_score_type_e GetType() { return type; } - int GetTopNumber() { return topNumber; } - std::shared_ptr<DeQuantization> GetDeQuant() { return deQuantization; } - double GetDeQuantScale() { return deQuantization->scale; } - double GetDeQuantZeroPoint() { return deQuantization->zeropoint; } - - int ParseScore(JsonObject *root) - { - LOGI("ENTER"); - - JsonArray * rootArray = json_object_get_array_member(root, "score"); - 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<int>(json_array_get_int_element(array, elem2)) == 1) - dimInfo.SetValidIndex(elem2); - } - if (json_object_has_member(pObject, "top_number")) - topNumber = static_cast<int>( - json_object_get_int_member(pObject, "top_number")); - LOGI("top number: %d", topNumber); - - if (json_object_has_member(pObject, "threshold")) - threshold = static_cast<double>( - json_object_get_double_member(pObject, "threshold")); - LOGI("threshold: %1.3f", threshold); - - try { - type = GetSupportedType(pObject, "score_type", supportedScoreTypes); - } catch (const std::exception& e) { - LOGE("Invalid %s", e.what()); - return MEDIA_VISION_ERROR_INVALID_OPERATION; - } - - if (json_object_has_member(pObject, "dequantization")) { - array = json_object_get_array_member(pObject, "dequantization"); - JsonNode *node = json_array_get_element(array, 0); - JsonObject *object = json_node_get_object(node); - - deQuantization = std::make_shared<DeQuantization>( + int ParseScore(JsonObject *root) + { + LOGI("ENTER"); + + JsonArray *rootArray = json_object_get_array_member(root, "score"); + 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<int>( + json_array_get_int_element(array, elem2)) == 1) + dimInfo.SetValidIndex(elem2); + } + if (json_object_has_member(pObject, "top_number")) + topNumber = static_cast<int>( + json_object_get_int_member(pObject, "top_number")); + LOGI("top number: %d", topNumber); + + if (json_object_has_member(pObject, "threshold")) + threshold = static_cast<double>( + json_object_get_double_member(pObject, "threshold")); + LOGI("threshold: %1.3f", threshold); + + try { + type = GetSupportedType(pObject, "score_type", + supportedScoreTypes); + } catch (const std::exception &e) { + LOGE("Invalid %s", e.what()); + return MEDIA_VISION_ERROR_INVALID_OPERATION; + } + + if (json_object_has_member(pObject, "dequantization")) { + array = json_object_get_array_member(pObject, "dequantization"); + JsonNode *node = json_array_get_element(array, 0); + JsonObject *object = json_node_get_object(node); + + deQuantization = std::make_shared<DeQuantization>( json_object_get_double_member(object, "scale"), json_object_get_double_member(object, "zeropoint")); - } } - - LOGI("LEAVE"); - return MEDIA_VISION_ERROR_NONE; } - }; + + LOGI("LEAVE"); + return MEDIA_VISION_ERROR_NONE; + } +}; } /* Inference */ } /* MediaVision */ |