Change box name to vector in meta json
authorKwanghoon Son <k.son@samsung.com>
Mon, 29 Aug 2022 06:44:00 +0000 (02:44 -0400)
committerInki Dae <inki.dae@samsung.com>
Fri, 2 Sep 2022 08:09:25 +0000 (17:09 +0900)
outputmetadata box name was single string, but needs to change to
handle yolo models.(multiple names)
`before`
"box" :
    {
        "name" : "some name",
        ...
    }
`after`
"box" :
    {
        "name" : ["some name"],
        ...
    }

Change-Id: Ia76001c2670c0a1fae272c31ba56dfc0cbc591de
Signed-off-by: Kwanghoon Son <k.son@samsung.com>
mv_machine_learning/inference/include/BoxInfo.h
mv_machine_learning/inference/src/BoxInfo.cpp

index 783342a..d4d6c6a 100644 (file)
@@ -51,7 +51,7 @@ struct Number
 class BoxInfo
 {
 private:
-       std::string name;
+       std::vector<std::string> names;
        DimInfo dimInfo;
        inference_box_type_e type; // 0:L-T-R-B, 1: Cx-Cy-W-H
        std::vector<int> order; // Order based on box type
@@ -69,7 +69,7 @@ private:
 
 public:
        BoxInfo()
-                       : name()
+                       : names()
                        , dimInfo()
                        , type(INFERENCE_BOX_TYPE_ORIGIN_LEFTTOP)
                        , order()
@@ -98,10 +98,8 @@ public:
 
        ~BoxInfo() = default;
 
-       std::string GetName()
-       {
-               return name;
-       }
+       std::string GetName();
+
        DimInfo GetDimInfo()
        {
                return dimInfo;
index 2c44757..1e57a19 100644 (file)
  */
 
 #include <BoxInfo.h>
+#include <mv_private.h>
 
 using namespace mediavision::inference::box;
 
+std::string BoxInfo::GetName()
+{
+       // OutputMetadata needs empty sting
+       if (names.empty())
+               return "";
+
+       return names[0];
+}
+
 int BoxInfo::ParseBox(JsonObject *root)
 {
        LOGI("ENTER");
@@ -30,10 +40,19 @@ int BoxInfo::ParseBox(JsonObject *root)
 
        JsonObject *pObject = json_object_get_object_member(root, "box");
 
-       name = json_object_get_string_member(pObject, "name");
-       LOGI("layer: %s", name.c_str());
+       JsonArray *array = json_object_get_array_member(pObject, "name");
+       MEDIA_VISION_NULL_ARG_CHECK(array);
+
+       unsigned int elements1 = json_array_get_length(array);
+       MEDIA_VISION_CHECK_CONDITION(elements1 > 0,
+                                                                MEDIA_VISION_ERROR_INVALID_PARAMETER,
+                                                                "No name on meta file");
+
+       for (unsigned int elem1 = 0; elem1 < elements1; ++elem1) {
+               names.push_back(json_array_get_string_element(array, elem1));
+       }
 
-       JsonArray *array = json_object_get_array_member(pObject, "index");
+       array = json_object_get_array_member(pObject, "index");
        unsigned int elements2 = json_array_get_length(array);
 
        LOGI("range dim: size[%u]", elements2);