From: Inki Dae Date: Mon, 7 Aug 2023 22:45:58 +0000 (+0900) Subject: mv_machine_learning: code clean to setModelInfo function X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=db3fd9f2803956e843aa19b664a9a74df9c3a5c0;p=platform%2Fcore%2Fapi%2Fmediavision.git mv_machine_learning: code clean to setModelInfo function [Issue type] : code cleanup Clean up setModelInfo function by doing function extraction. setModelInfo function converted a given model name to its corresponding task type internally so it made the function to be complicated. This patch extracts the conversion portion from setModelInfo function as another function and makes the function to be called instead. Change-Id: I93243ffba543f9c6e9a1f0d7690d8f48a1bd14e1 Signed-off-by: Inki Dae --- 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 7aa6ff40..45aea8bb 100644 --- a/mv_machine_learning/object_detection/include/object_detection_adapter.h +++ b/mv_machine_learning/object_detection/include/object_detection_adapter.h @@ -39,6 +39,7 @@ private: std::string _label_file; void create(ObjectDetectionTaskType task_type); + ObjectDetectionTaskType convertToTaskType(std::string model_name); public: ObjectDetectionAdapter(); 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 57993b31..c6bb5660 100644 --- a/mv_machine_learning/object_detection/src/object_detection_adapter.cpp +++ b/mv_machine_learning/object_detection/src/object_detection_adapter.cpp @@ -58,38 +58,36 @@ template void ObjectDetectionAdapter::create(Objec } template -void ObjectDetectionAdapter::setModelInfo(const char *model_file, const char *meta_file, const char *label_file, - const char *model_name) +ObjectDetectionTaskType ObjectDetectionAdapter::convertToTaskType(string model_name) { - string model_name_str(model_name); - - if (!model_name_str.empty()) { - transform(model_name_str.begin(), model_name_str.end(), model_name_str.begin(), ::toupper); + if (model_name.empty()) + throw InvalidParameter("model name is empty."); - ObjectDetectionTaskType task_type = ObjectDetectionTaskType::OBJECT_DETECTION_TASK_NONE; + transform(model_name.begin(), model_name.end(), model_name.begin(), ::toupper); - if (model_name_str == "OD_PLUGIN" || model_name_str == "FD_PLUGIN") { - if (model_name_str == "OD_PLUGIN") - task_type = ObjectDetectionTaskType::OD_PLUGIN; - if (model_name_str == "FD_PLUGIN") - task_type = ObjectDetectionTaskType::FD_PLUGIN; + ObjectDetectionTaskType task_type = ObjectDetectionTaskType::OBJECT_DETECTION_TASK_NONE; - // In case of using plugin module, model information will be managed by the plugin module. - // Therefore, create plugin instance now. - create(task_type); - return; - } + if (model_name == "OD_PLUGIN") + return ObjectDetectionTaskType::OD_PLUGIN; + else if (model_name == "FD_PLUGIN") + return ObjectDetectionTaskType::FD_PLUGIN; + else if (model_name == string("MOBILENET_V1_SSD")) + return ObjectDetectionTaskType::MOBILENET_V1_SSD; + else if (model_name == string("MOBILENET_V2_SSD")) + return ObjectDetectionTaskType::MOBILENET_V2_SSD; + // TODO. - if (model_name_str == string("MOBILENET_V1_SSD")) { - task_type = ObjectDetectionTaskType::MOBILENET_V1_SSD; - } else if (model_name_str == string("MOBILENET_V2_SSD")) { - task_type = ObjectDetectionTaskType::MOBILENET_V2_SSD; - // TODO. - } else { - throw InvalidParameter("Invalid object detection model name."); - } + throw InvalidParameter("Invalid object detection model name."); +} - create(task_type); +template +void ObjectDetectionAdapter::setModelInfo(const char *model_file, const char *meta_file, const char *label_file, + const char *model_name) +{ + try { + create(convertToTaskType(string(model_name))); + } catch (const BaseException &e) { + LOGW("A given model name is invalid so default task type will be used."); } _model_file = string(model_file);