From: Inki Dae Date: Wed, 9 Aug 2023 04:04:47 +0000 (+0900) Subject: mv_machine_learning: introduce DEFAULT_MODEL_NAME for object detection X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d18d5fabacdd403287d8ecf02423fdc1646a042c;p=platform%2Fcore%2Fapi%2Fmediavision.git mv_machine_learning: introduce DEFAULT_MODEL_NAME for object detection [Issue type] : new feature Introduce DEFAULT_MODEL_NAME for object detection task group, which is a new key for object detection meta file. With this patch, a proper concreate class object will be created at the constructor of ObjectDetectionAdapter class according to the default model name which is parsed from object_detection.json file. And also this patch calls the member function, create, to create the concrete class object corresponding to the default model name instead of creating a default concrete class object directly. Finally, we can create user-desired concrete class object without rebuilding by simply modifying the meta file, object_detection.json. Change-Id: Ie159991985c4ed9a28abc5a377037110fe319be6 Signed-off-by: Inki Dae --- diff --git a/mv_machine_learning/object_detection/include/mv_object_detection_config.h b/mv_machine_learning/object_detection/include/mv_object_detection_config.h index 32d527d2..7dbf27fb 100644 --- a/mv_machine_learning/object_detection/include/mv_object_detection_config.h +++ b/mv_machine_learning/object_detection/include/mv_object_detection_config.h @@ -33,6 +33,14 @@ */ #define MV_OBJECT_DETECTION_MODEL_FILE_PATH "MODEL_FILE_NAME" +/** + * @brief Defines #MV_OBJECT_DETECTION_DEFAULT_MODEL_NAME + * to set the object detection default model name. + * + * @since_tizen 8.0 + */ +#define MV_OBJECT_DETECTION_DEFAULT_MODEL_NAME "DEFAULT_MODEL_NAME" + /** * @brief Defines #MV_OBJECT_DETECTION_3D_MODEL_META_FILE_PATH to set inference * models's metadata file attribute of the engine configuration. diff --git a/mv_machine_learning/object_detection/include/object_detection_adapter.h b/mv_machine_learning/object_detection/include/object_detection_adapter.h index 45aea8bb..1650726d 100644 --- a/mv_machine_learning/object_detection/include/object_detection_adapter.h +++ b/mv_machine_learning/object_detection/include/object_detection_adapter.h @@ -37,6 +37,7 @@ private: std::string _model_file; std::string _meta_file; std::string _label_file; + const std::string _meta_file_name = "object_detection.json"; void create(ObjectDetectionTaskType task_type); ObjectDetectionTaskType convertToTaskType(std::string model_name); diff --git a/mv_machine_learning/object_detection/meta/object_detection.json b/mv_machine_learning/object_detection/meta/object_detection.json index ed06d7a6..d1bdbf38 100644 --- a/mv_machine_learning/object_detection/meta/object_detection.json +++ b/mv_machine_learning/object_detection/meta/object_detection.json @@ -11,6 +11,11 @@ "type" : "string", "value" : "od_mobilenet_v1_ssd_postop_300x300.tflite" }, + { + "name" : "DEFAULT_MODEL_NAME", + "type" : "string", + "value" : "MOBILENET_V1_SSD" + }, { "name" : "META_FILE_NAME", "type" : "string", diff --git a/mv_machine_learning/object_detection/src/object_detection_adapter.cpp b/mv_machine_learning/object_detection/src/object_detection_adapter.cpp index de9ccbdc..4cc86b7a 100644 --- a/mv_machine_learning/object_detection/src/object_detection_adapter.cpp +++ b/mv_machine_learning/object_detection/src/object_detection_adapter.cpp @@ -17,6 +17,7 @@ #include "machine_learning_exception.h" #include "object_detection_adapter.h" #include "object_detection_external.h" +#include "mv_object_detection_config.h" using namespace std; using namespace MediaVision::Common; @@ -29,10 +30,15 @@ namespace machine_learning { template ObjectDetectionAdapter::ObjectDetectionAdapter() : _source() { - // In default, Mobilenet v1 ssd model will be used. - // If other model is set by user then strategy pattern will be used - // to create its corresponding concrete class by calling create(). - _object_detection = make_unique(ObjectDetectionTaskType::MOBILENET_V1_SSD); + auto config = make_unique(string(MV_CONFIG_PATH) + _meta_file_name); + + string defaultModelName; + + int ret = config->getStringAttribute(MV_OBJECT_DETECTION_DEFAULT_MODEL_NAME, &defaultModelName); + if (ret != MEDIA_VISION_ERROR_NONE) + throw InvalidOperation("Fail to get default model name."); + + create(convertToTaskType(defaultModelName.c_str())); } template ObjectDetectionAdapter::~ObjectDetectionAdapter() @@ -42,11 +48,15 @@ template ObjectDetectionAdapter::~ObjectDetectionA template void ObjectDetectionAdapter::create(ObjectDetectionTaskType task_type) { - // If default task type is same as a given one then skip. - if (_object_detection->getTaskType() == task_type) - return; + // If a concrete class object created already exists, reset the object + // so that other concrete class object can be created again according to a given task_type. + if (_object_detection) { + // If default task type is same as a given one then skip. + if (_object_detection->getTaskType() == task_type) + return; - _object_detection.reset(); + _object_detection.reset(); + } if (task_type == ObjectDetectionTaskType::MOBILENET_V1_SSD) _object_detection = make_unique(task_type); @@ -113,7 +123,7 @@ void ObjectDetectionAdapter::setEngineInfo(const char *engine_type, const template void ObjectDetectionAdapter::configure() { - _object_detection->configure("object_detection.json"); + _object_detection->configure(_meta_file_name); } template void ObjectDetectionAdapter::getNumberOfEngines(unsigned int *number_of_engines)