Apply code lint and update copyright year
authorKwanghoon Son <k.son@samsung.com>
Fri, 26 Aug 2022 02:00:57 +0000 (22:00 -0400)
committerInki Dae <inki.dae@samsung.com>
Fri, 2 Sep 2022 08:09:25 +0000 (17:09 +0900)
Change-Id: I53fd18c3c5b3961b8c7e8fb903199e4150bf03e3
Signed-off-by: Kwanghoon Son <k.son@samsung.com>
mv_machine_learning/inference/include/ScoreInfo.h

index 2004002..096a120 100644 (file)
@@ -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 */