summaryrefslogtreecommitdiff
path: root/mv_common
diff options
context:
space:
mode:
authorInki Dae <inki.dae@samsung.com>2023-01-19 10:25:49 +0900
committerKwanghoon Son <k.son@samsung.com>2023-02-13 11:31:48 +0900
commitd3767875a124f792cec21e3124c4d9ca9a0a405c (patch)
treeeb88558189e86af9ccae7d5a3382265d7103ab70 /mv_common
parent4db04cd262dfd5b593b90f03b561641af20b4c41 (diff)
downloadmediavision-d3767875a124f792cec21e3124c4d9ca9a0a405c.tar.gz
mediavision-d3767875a124f792cec21e3124c4d9ca9a0a405c.tar.bz2
mediavision-d3767875a124f792cec21e3124c4d9ca9a0a405c.zip
mv_machine_learning: drop backbone model code dependency
[Issue type] code refactoring Did code refactoring by dropping backbone model code dependency. With this patch, we can change facenet to other without code modification. Only what we have to do for the use of new backbone model is to update each "value" attribute of two types of face_recognition.json file, "name" : "FACE_RECOGNITION_INPUT_TENSOR_SHAPE", "type" : "array", "subtype" : "integer", "value" : [ 512, 1 ] <- input tensor shape of training model which is same as output tensor shape of backbone model. "name" : "FACENET_OUTPUT_TENSOR_NAME", "type" : "string", "value" : "normalize/l2_normalize" <- output tensor name of backbone model. Change-Id: I9e32c73e029d67a1c86e8b2c7b424cb09d614463 Signed-off-by: Inki Dae <inki.dae@samsung.com>
Diffstat (limited to 'mv_common')
-rw-r--r--mv_common/include/EngineConfig.h18
-rw-r--r--mv_common/src/EngineConfig.cpp51
2 files changed, 60 insertions, 9 deletions
diff --git a/mv_common/include/EngineConfig.h b/mv_common/include/EngineConfig.h
index 9be5ed66..29183b4b 100644
--- a/mv_common/include/EngineConfig.h
+++ b/mv_common/include/EngineConfig.h
@@ -39,6 +39,7 @@ using DictIntConstIter = std::map<std::string, int>::const_iterator;
using DictBoolConstIter = std::map<std::string, bool>::const_iterator;
using DictStrConstIter = std::map<std::string, std::string>::const_iterator;
using DictVecStrConstIter = std::map<std::string, std::vector<std::string> >::const_iterator;
+using DictVecIntConstIter = std::map<std::string, std::vector<int> >::const_iterator;
class EngineConfig
{
@@ -119,7 +120,7 @@ public:
*
* @since_tizen @if MOBILE 2.4 @else 3.0 @endif
* @param [in] key The string name of the attribute
- * @param [out] value r The double attribute value to be obtained
+ * @param [out] value The double attribute value to be obtained
* @return @c MEDIA_VISION_ERROR_NONE on success,\n
* otherwise a negative error value
* @retval #MEDIA_VISION_ERROR_KEY_NOT_AVAILABLE If attribute with name @a key
@@ -141,6 +142,19 @@ public:
int getIntegerAttribute(const std::string &key, int *value) const;
/**
+ * @brief Gets integer attribute value by attribute name.
+ *
+ * @since_tizen 7.5
+ * @param [in] key The string name of the attribute
+ * @param [out] value The vector attribute value of integer to be obtained
+ * @return @c MEDIA_VISION_ERROR_NONE on success,\n
+ * otherwise a negative error value
+ * @retval #MEDIA_VISION_ERROR_KEY_NOT_AVAILABLE If attribute with name @a key
+ * doesn't exist in the engine configuration dictionary
+ */
+ int getIntegerAttribute(const std::string &key, std::vector<int> *value) const;
+
+ /**
* @brief Gets boolean attribute value by attribute name.
*
* @since_tizen @if MOBILE 2.4 @else 3.0 @endif
@@ -184,6 +198,7 @@ public:
const std::map<std::string, bool> &getDefaultBoolDict();
const std::map<std::string, std::string> &getDefaultStrDict();
const std::map<std::string, std::vector<std::string> > &getDefaultVecStrDict();
+ const std::map<std::string, std::vector<int> > &getDefaultVecIntDict();
private:
std::map<std::string, double> __dblDict;
@@ -191,6 +206,7 @@ private:
std::map<std::string, bool> __boolDict;
std::map<std::string, std::string> __strDict;
std::map<std::string, std::vector<std::string> > __vecStrDict;
+ std::map<std::string, std::vector<int> > __vecIntDict;
int loadDictionaries(std::string &config_file_path);
};
diff --git a/mv_common/src/EngineConfig.cpp b/mv_common/src/EngineConfig.cpp
index 212be17d..19a42f1c 100644
--- a/mv_common/src/EngineConfig.cpp
+++ b/mv_common/src/EngineConfig.cpp
@@ -149,6 +149,24 @@ int EngineConfig::getIntegerAttribute(const std::string &key, int *value) const
return MEDIA_VISION_ERROR_NONE;
}
+int EngineConfig::getIntegerAttribute(const std::string &key, std::vector<int> *value) const
+{
+ DictVecIntConstIter dictIter = __vecIntDict.find(key);
+ if (dictIter == __vecIntDict.end()) {
+ LOGE("Attempt to access to the unsupported vector attribute [%s] of integer "
+ "of the engine config %p",
+ key.c_str(), this);
+ return MEDIA_VISION_ERROR_KEY_NOT_AVAILABLE;
+ }
+
+ LOGD("Get vector attribute of integer from the engine config %p. [%s] = [%d,...]", this, dictIter->first.c_str(),
+ dictIter->second[0]);
+
+ *value = dictIter->second;
+
+ return MEDIA_VISION_ERROR_NONE;
+}
+
int EngineConfig::getBooleanAttribute(const std::string &key, bool *value) const
{
DictBoolConstIter dictIter = __boolDict.find(key);
@@ -229,6 +247,11 @@ const std::map<std::string, std::vector<std::string> > &EngineConfig::getDefault
return __vecStrDict;
}
+const std::map<std::string, std::vector<int> > &EngineConfig::getDefaultVecIntDict()
+{
+ return __vecIntDict;
+}
+
int EngineConfig::loadDictionaries(std::string &config_file_path)
{
LOGI("Start to cache default attributes from engine configuration file.");
@@ -238,6 +261,7 @@ int EngineConfig::loadDictionaries(std::string &config_file_path)
__boolDict.clear();
__strDict.clear();
__vecStrDict.clear();
+ __vecIntDict.clear();
const char *conf_file = config_file_path.c_str();
GError *error = NULL;
@@ -297,10 +321,10 @@ int EngineConfig::loadDictionaries(std::string &config_file_path)
continue;
}
- const char *nameStr = (const char *) json_object_get_string_member(attr_obj, "name");
+ const std::string nameStr = (const char *) json_object_get_string_member(attr_obj, "name");
const char *typeStr = (const char *) json_object_get_string_member(attr_obj, "type");
- if (NULL == nameStr || NULL == typeStr) {
+ if (nameStr.empty() || NULL == typeStr) {
LOGW("Attribute %i wasn't parsed from json file. name and/or "
"type of the attribute are parsed as NULL.",
attrInd);
@@ -308,13 +332,13 @@ int EngineConfig::loadDictionaries(std::string &config_file_path)
}
if (0 == strcmp("double", typeStr)) {
- __dblDict[std::string(nameStr)] = (double) json_object_get_double_member(attr_obj, "value");
+ __dblDict[nameStr] = (double) json_object_get_double_member(attr_obj, "value");
} else if (0 == strcmp("integer", typeStr)) {
- __intDict[std::string(nameStr)] = (int) json_object_get_int_member(attr_obj, "value");
+ __intDict[nameStr] = (int) json_object_get_int_member(attr_obj, "value");
} else if (0 == strcmp("boolean", typeStr)) {
- __boolDict[std::string(nameStr)] = json_object_get_boolean_member(attr_obj, "value") ? true : false;
+ __boolDict[nameStr] = json_object_get_boolean_member(attr_obj, "value") ? true : false;
} else if (0 == strcmp("string", typeStr)) {
- __strDict[std::string(nameStr)] = (char *) json_object_get_string_member(attr_obj, "value");
+ __strDict[nameStr] = (char *) json_object_get_string_member(attr_obj, "value");
} else if (0 == strcmp("array", typeStr)) {
const char *subTypeStr = (const char *) json_object_get_string_member(attr_obj, "subtype");
@@ -328,13 +352,24 @@ int EngineConfig::loadDictionaries(std::string &config_file_path)
for (unsigned int item = 0; item < json_array_get_length(attr_array); ++item) {
defaultVecStr.push_back(std::string(json_array_get_string_element(attr_array, item)));
}
- __vecStrDict[std::string(nameStr)] = defaultVecStr;
+ __vecStrDict[nameStr] = defaultVecStr;
}
+
+ if (0 == strcmp("integer", subTypeStr)) {
+ JsonArray *attr_array = json_object_get_array_member(attr_obj, "value");
+ std::vector<int> defaultVecInt;
+
+ for (unsigned int item = 0; item < json_array_get_length(attr_array); ++item) {
+ defaultVecInt.push_back(static_cast<int>(json_array_get_int_element(attr_array, item)));
+ }
+ __vecIntDict[nameStr] = defaultVecInt;
+ }
+
//TO-DO: add other subtypes
} else {
LOGW("Attribute %i:%s wasn't parsed from json file. "
"Type isn't supported.",
- attrInd, nameStr);
+ attrInd, nameStr.c_str());
continue;
}
}