mv_machine_learning: drop setTaskType member function
authorInki Dae <inki.dae@samsung.com>
Wed, 8 Nov 2023 06:23:38 +0000 (15:23 +0900)
committerInki Dae <inki.dae@samsung.com>
Tue, 14 Nov 2023 07:41:01 +0000 (16:41 +0900)
[Issue type] : code refactoring

Drop setTaskType member function from MetaParser and its child classes.

The setTaskType member function was used to give model specific parser object
to MetaParser class so that the MetaParser can parse model specific meta
information which describes how to parse the postprocess node of each model
specific meta file.

However, we can give the specific parser object when task group specific
parser class is created so drop the setTaskType member function and update
the object at constructor of task group specific parser class.

As of now, only object detection task group will set the specific task type
for various models support. For other task groups, 0 is used in default.

Change-Id: I7156660481f1e42daf89093f0fb1097943bbae05
Signed-off-by: Inki Dae <inki.dae@samsung.com>
22 files changed:
mv_machine_learning/common/include/machine_learning_config.h
mv_machine_learning/common/src/machine_learning_config.cpp
mv_machine_learning/face_recognition/include/facenet_parser.h
mv_machine_learning/face_recognition/src/facenet_parser.cpp
mv_machine_learning/image_classification/include/ImageClassificationParser.h
mv_machine_learning/image_classification/src/ImageClassificationParser.cpp
mv_machine_learning/image_segmentation/include/image_segmentation_parser.h
mv_machine_learning/image_segmentation/src/image_segmentation.cpp
mv_machine_learning/image_segmentation/src/image_segmentation_parser.cpp
mv_machine_learning/landmark_detection/include/LandmarkDetectionParser.h
mv_machine_learning/landmark_detection/include/landmark_detection_config.h
mv_machine_learning/landmark_detection/src/LandmarkDetectionParser.cpp
mv_machine_learning/landmark_detection/src/facial_landmark_adapter.cpp
mv_machine_learning/landmark_detection/src/landmark_detection_config.cpp
mv_machine_learning/landmark_detection/src/pose_landmark_adapter.cpp
mv_machine_learning/meta/include/MetaParser.h
mv_machine_learning/object_detection/include/ObjectDetectionParser.h
mv_machine_learning/object_detection/src/ObjectDetectionParser.cpp
mv_machine_learning/object_detection/src/object_detection.cpp
mv_machine_learning/object_detection/src/object_detection_config.cpp
mv_machine_learning/object_detection_3d/include/ObjectDetection3dParser.h
mv_machine_learning/object_detection_3d/src/ObjectDetection3dParser.cpp

index 1767e79..ba39029 100644 (file)
@@ -57,7 +57,7 @@ public:
        double getConfidenceThreshold() const;
        int getBackendType() const;
        int getTargetDeviceType() const;
-       void loadMetaFile();
+       void loadMetaFile(int task_type = 0);
 };
 
 } // machine_learning
index fb08c41..08d6be4 100644 (file)
@@ -145,9 +145,9 @@ template<typename ParserType> void MachineLearningConfig<ParserType>::parseConfi
        LOGI("meta file path = %s", _modelMetaFilePath.c_str());
 }
 
-template<typename ParserType> void MachineLearningConfig<ParserType>::loadMetaFile()
+template<typename ParserType> void MachineLearningConfig<ParserType>::loadMetaFile(int task_type)
 {
-       _parser = make_unique<ParserType>();
+       _parser = make_unique<ParserType>(task_type);
        _parser->load(_modelMetaFilePath);
 }
 
index 849fcc6..09a2c43 100644 (file)
@@ -33,10 +33,8 @@ protected:
        void parsePostprocess(std::shared_ptr<MetaInfo> meta_info, JsonObject *in_obj) override;
 
 public:
-       FacenetParser();
+       FacenetParser(int task_type = 0);
        ~FacenetParser();
-
-       void setTaskType(int type) override;
 };
 
 }
index 3915eae..2ce236f 100644 (file)
@@ -24,7 +24,7 @@ namespace mediavision
 {
 namespace machine_learning
 {
-FacenetParser::FacenetParser()
+FacenetParser::FacenetParser(int task_type)
 {
        LOGI("ENTER");
        LOGI("LEAVE");
@@ -33,11 +33,6 @@ FacenetParser::FacenetParser()
 FacenetParser::~FacenetParser()
 {}
 
-void FacenetParser::setTaskType(int type)
-{
-       throw InvalidOperation("setTaskType interface not supported yet.");
-}
-
 void FacenetParser::parsePostprocess(shared_ptr<MetaInfo> meta_info, JsonObject *in_obj)
 {
        LOGI("ENTER");
index 78c0b01..26f1f5c 100644 (file)
@@ -33,10 +33,8 @@ protected:
        void parsePostprocess(std::shared_ptr<MetaInfo> meta_info, JsonObject *in_obj) override;
 
 public:
-       ImageClassificationParser();
+       ImageClassificationParser(int task_type = 0);
        ~ImageClassificationParser();
-
-       void setTaskType(int type) override;
 };
 
 }
index cceed09..72f681f 100644 (file)
@@ -24,7 +24,7 @@ namespace mediavision
 {
 namespace machine_learning
 {
-ImageClassificationParser::ImageClassificationParser()
+ImageClassificationParser::ImageClassificationParser(int task_type)
 {
        LOGI("ENTER");
        LOGI("LEAVE");
@@ -33,11 +33,6 @@ ImageClassificationParser::ImageClassificationParser()
 ImageClassificationParser::~ImageClassificationParser()
 {}
 
-void ImageClassificationParser::setTaskType(int type)
-{
-       throw InvalidOperation("setTaskType interface not supported yet.");
-}
-
 void ImageClassificationParser::parsePostprocess(shared_ptr<MetaInfo> meta_info, JsonObject *in_obj)
 {
        LOGI("ENTER");
index f9f4927..c6c9cde 100644 (file)
@@ -33,10 +33,8 @@ protected:
        void parsePostprocess(std::shared_ptr<MetaInfo> meta_info, JsonObject *in_obj) override;
 
 public:
-       ImageSegmentationParser();
+       ImageSegmentationParser(int task_type = 0);
        ~ImageSegmentationParser();
-
-       void setTaskType(int type) override;
 };
 
 }
index 7f7e1a1..8709d53 100644 (file)
@@ -228,7 +228,6 @@ void ImageSegmentation::parseMetaFile(string meta_file_name)
        _modelMetaFilePath = _modelDefaultPath + _modelMetaFilePath;
        LOGI("meta file path = %s", _modelMetaFilePath.c_str());
 
-       _parser->setTaskType(static_cast<int>(_task_type));
        _parser->load(_modelMetaFilePath);
 
        if (_modelLabelFilePath.empty()) {
index f987e50..f3ea0b6 100644 (file)
@@ -26,7 +26,7 @@ namespace mediavision
 {
 namespace machine_learning
 {
-ImageSegmentationParser::ImageSegmentationParser()
+ImageSegmentationParser::ImageSegmentationParser(int task_type)
 {
        LOGI("ENTER");
        LOGI("LEAVE");
@@ -38,12 +38,6 @@ ImageSegmentationParser::~ImageSegmentationParser()
        LOGI("LEAVE");
 }
 
-void ImageSegmentationParser::setTaskType(int type)
-{
-       LOGI("ENTER");
-       LOGI("LEAVE");
-}
-
 void ImageSegmentationParser::parsePostprocess(shared_ptr<MetaInfo> meta_info, JsonObject *in_obj)
 {
        LOGI("ENTER");
index f536e7b..6fbd941 100644 (file)
@@ -33,10 +33,8 @@ protected:
        void parsePostprocess(std::shared_ptr<MetaInfo> meta_info, JsonObject *in_obj) override;
 
 public:
-       LandmarkDetectionParser();
+       LandmarkDetectionParser(int task_type = 0);
        ~LandmarkDetectionParser();
-
-       void setTaskType(int type) override;
 };
 
 }
index 4aa4d9e..5e1f143 100644 (file)
@@ -58,7 +58,7 @@ public:
        double getConfidenceThreshold() const;
        int getBackendType() const;
        int getTargetDeviceType() const;
-       void loadMetaFile(LandmarkDetectionTaskType task_type);
+       void loadMetaFile();
 };
 
 } // machine_learning
index 614aa26..2321ffa 100644 (file)
@@ -26,7 +26,7 @@ namespace mediavision
 {
 namespace machine_learning
 {
-LandmarkDetectionParser::LandmarkDetectionParser()
+LandmarkDetectionParser::LandmarkDetectionParser(int task_type)
 {
        LOGI("ENTER");
        LOGI("LEAVE");
@@ -35,11 +35,6 @@ LandmarkDetectionParser::LandmarkDetectionParser()
 LandmarkDetectionParser::~LandmarkDetectionParser()
 {}
 
-void LandmarkDetectionParser::setTaskType(int type)
-{
-       // TODO.
-}
-
 void LandmarkDetectionParser::parsePostprocess(shared_ptr<MetaInfo> meta_info, JsonObject *in_obj)
 {
        LOGI("ENTER");
index 60a8f85..c81ff52 100644 (file)
@@ -50,7 +50,7 @@ template<typename T, typename V> void FacialLandmarkAdapter<T, V>::create(Landma
        }
 
        // if model name is changed by user then reallocate the parser and reload the meta file corresponding to the model name.
-       _config->loadMetaFile(task_type);
+       _config->loadMetaFile();
 
        if (task_type == LandmarkDetectionTaskType::FLD_TWEAK_CNN)
                _landmark_detection = make_unique<FldTweakCnn>(task_type, _config);
index 5974432..0221fba 100644 (file)
@@ -157,10 +157,9 @@ void LandmarkDetectionConfig::parseConfigFile(const std::string &configFilePath)
        LOGI("label file path = %s", _modelLabelFilePath.c_str());
 }
 
-void LandmarkDetectionConfig::loadMetaFile(LandmarkDetectionTaskType task_type)
+void LandmarkDetectionConfig::loadMetaFile()
 {
        _parser = make_unique<LandmarkDetectionParser>();
-       _parser->setTaskType(static_cast<int>(task_type));
        _parser->load(_modelMetaFilePath);
 }
 
index aee6adb..4703fbf 100644 (file)
@@ -52,7 +52,7 @@ template<typename T, typename V> void PoseLandmarkAdapter<T, V>::create(Landmark
        }
 
        // if model name is changed by user then reallocate the parser and reload the meta file corresponding to the model name.
-       _config->loadMetaFile(task_type);
+       _config->loadMetaFile();
 
        if (task_type == LandmarkDetectionTaskType::PLD_CPM)
                _landmark_detection = make_unique<PldCpm>(task_type, _config);
index 8a10927..6e9dc02 100644 (file)
@@ -74,8 +74,6 @@ public:
        MetaParser();
        virtual ~MetaParser();
 
-       virtual void setTaskType(int type) = 0;
-
        /**
         * @brief Invoke the parsing work to a given meta file.
         */
index b9c3913..5e50819 100644 (file)
@@ -33,10 +33,8 @@ protected:
        void parsePostprocess(std::shared_ptr<MetaInfo> meta_info, JsonObject *in_obj) override;
 
 public:
-       ObjectDetectionParser();
+       ObjectDetectionParser(int task_type = 0);
        ~ObjectDetectionParser();
-
-       void setTaskType(int type) override;
 };
 
 }
index 027b374..4505297 100644 (file)
@@ -27,23 +27,19 @@ namespace mediavision
 {
 namespace machine_learning
 {
-ObjectDetectionParser::ObjectDetectionParser()
+ObjectDetectionParser::ObjectDetectionParser(int task_type)
 {
        LOGI("ENTER");
+
+       if ((static_cast<ObjectDetectionTaskType>(task_type)) == ObjectDetectionTaskType::MOBILENET_V2_SSD)
+               _postprocessParser.SetTaskAnchorParser(make_shared<MobilenetV2AnchorParser>());
+
        LOGI("LEAVE");
 }
 
 ObjectDetectionParser::~ObjectDetectionParser()
 {}
 
-void ObjectDetectionParser::setTaskType(int type)
-{
-       ObjectDetectionTaskType task_type = static_cast<ObjectDetectionTaskType>(type);
-
-       if (task_type == ObjectDetectionTaskType::MOBILENET_V2_SSD)
-               _postprocessParser.SetTaskAnchorParser(make_shared<MobilenetV2AnchorParser>());
-}
-
 void ObjectDetectionParser::parsePostprocess(shared_ptr<MetaInfo> meta_info, JsonObject *in_obj)
 {
        LOGI("ENTER");
index 3c9622e..eebb74e 100644 (file)
@@ -376,4 +376,4 @@ template void ObjectDetection::perform<unsigned char>(mv_source_h &mv_src, share
 template void ObjectDetection::performAsync<unsigned char>(ObjectDetectionInput &input, shared_ptr<MetaInfo> metaInfo);
 
 }
-}
\ No newline at end of file
+}
index 073cfef..eb23f08 100644 (file)
@@ -150,8 +150,7 @@ void ObjectDetectionConfig::parseConfigFile(const std::string &configFilePath)
 
 void ObjectDetectionConfig::loadMetaFile(ObjectDetectionTaskType task_type)
 {
-       _parser = make_unique<ObjectDetectionParser>();
-       _parser->setTaskType(static_cast<int>(task_type));
+       _parser = make_unique<ObjectDetectionParser>(static_cast<int>(task_type));
        _parser->load(_modelMetaFilePath);
 }
 
index 27ea4ca..b64788c 100644 (file)
@@ -33,10 +33,8 @@ protected:
        void parsePostprocess(std::shared_ptr<MetaInfo> meta_info, JsonObject *in_obj) override;
 
 public:
-       ObjectDetection3dParser();
+       ObjectDetection3dParser(int task_type = 0);
        ~ObjectDetection3dParser();
-
-       void setTaskType(int type) override;
 };
 
 }
index 20a6e6d..373ef5c 100644 (file)
@@ -25,7 +25,7 @@ namespace mediavision
 {
 namespace machine_learning
 {
-ObjectDetection3dParser::ObjectDetection3dParser()
+ObjectDetection3dParser::ObjectDetection3dParser(int task_type)
 {
        LOGI("ENTER");
        LOGI("LEAVE");
@@ -34,11 +34,6 @@ ObjectDetection3dParser::ObjectDetection3dParser()
 ObjectDetection3dParser::~ObjectDetection3dParser()
 {}
 
-void ObjectDetection3dParser::setTaskType(int type)
-{
-       throw InvalidOperation("setTaskType interface not supported yet.");
-}
-
 void ObjectDetection3dParser::parsePostprocess(shared_ptr<MetaInfo> meta_info, JsonObject *in_obj)
 {
        LOGI("ENTER");