From: Vibhav Aggarwal Date: Fri, 26 Jan 2024 04:23:21 +0000 (+0900) Subject: mv_machine_learning: optimize preprocess for other task groups X-Git-Tag: accepted/tizen/unified/20240213.171947~2^2~13 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a651bfdbde7341edb447e6d6d55b4a38fa4fea3a;p=platform%2Fcore%2Fapi%2Fmediavision.git mv_machine_learning: optimize preprocess for other task groups [Issue type] code optimization This patch optimizes the preprocess performance for tasks other than ImageClassification. This is in continuation with this patch[1]. [1] https://review.tizen.org/gerrit/c/platform/core/api/mediavision/+/305058 Change-Id: Ibefd5e4e53bc5d91e3b86358d493dd13841a77b8 Signed-off-by: Vibhav Aggarwal --- diff --git a/mv_machine_learning/image_segmentation/include/ImageSegmentation.h b/mv_machine_learning/image_segmentation/include/ImageSegmentation.h index c16fa0d2..31095bef 100644 --- a/mv_machine_learning/image_segmentation/include/ImageSegmentation.h +++ b/mv_machine_learning/image_segmentation/include/ImageSegmentation.h @@ -50,7 +50,7 @@ private: void loadLabel(); void getEngineList(); void getDeviceList(const std::string &engine_type); - void preprocess(mv_source_h &mv_src, std::shared_ptr metaInfo, std::vector &inputVector); + void configurePreprocess(); std::shared_ptr getInputMetaInfo(); protected: diff --git a/mv_machine_learning/image_segmentation/src/ImageSegmentation.cpp b/mv_machine_learning/image_segmentation/src/ImageSegmentation.cpp index 096bc116..7fecb325 100644 --- a/mv_machine_learning/image_segmentation/src/ImageSegmentation.cpp +++ b/mv_machine_learning/image_segmentation/src/ImageSegmentation.cpp @@ -194,6 +194,8 @@ template void ImageSegmentation::prepare() ret = _inference->load(); if (ret != MEDIA_VISION_ERROR_NONE) throw InvalidOperation("Fail to load model files."); + + configurePreprocess(); } template shared_ptr ImageSegmentation::getInputMetaInfo() @@ -211,11 +213,12 @@ template shared_ptr ImageSegmentation::getInputMetaInfo return _config->getInputMetaMap()[tensor_buffer_iter->first]; } -template -void ImageSegmentation::preprocess(mv_source_h &mv_src, shared_ptr metaInfo, vector &inputVector) +template void ImageSegmentation::configurePreprocess() { LOGI("ENTER"); + shared_ptr metaInfo = getInputMetaInfo(); + PreprocessConfig config = { false, metaInfo->colorSpace, metaInfo->dataType, @@ -239,7 +242,6 @@ void ImageSegmentation::preprocess(mv_source_h &mv_src, shared_ptr } _preprocess.setConfig(config); - _preprocess.run(mv_src, inputVector); LOGI("LEAVE"); } @@ -257,12 +259,10 @@ template void ImageSegmentation::inference(vector > &in template void ImageSegmentation::perform(mv_source_h &mv_src) { - shared_ptr metaInfo = getInputMetaInfo(); - vector inputVector; + vector > inputVectors(1); - preprocess(mv_src, metaInfo, inputVector); + _preprocess.run(mv_src, inputVectors[0]); - vector > inputVectors = { inputVector }; inference(inputVectors); } @@ -281,12 +281,10 @@ template void ImageSegmentation::performAsync(ImageSegmentationIn }); } - shared_ptr metaInfo = getInputMetaInfo(); - vector inputVector; + vector > inputVectors(1); - preprocess(input.inference_src, metaInfo, inputVector); + _preprocess.run(input.inference_src, inputVectors[0]); - vector > inputVectors = { inputVector }; _async_manager->push(inputVectors); } diff --git a/mv_machine_learning/landmark_detection/include/LandmarkDetection.h b/mv_machine_learning/landmark_detection/include/LandmarkDetection.h index 01d45f08..92e062b6 100644 --- a/mv_machine_learning/landmark_detection/include/LandmarkDetection.h +++ b/mv_machine_learning/landmark_detection/include/LandmarkDetection.h @@ -47,7 +47,7 @@ private: void getEngineList(); void getDeviceList(const std::string &engine_type); - void preprocess(mv_source_h &mv_src, std::shared_ptr metaInfo, std::vector &inputVector); + void configurePreprocess(); std::shared_ptr getInputMetaInfo(); protected: diff --git a/mv_machine_learning/landmark_detection/src/LandmarkDetection.cpp b/mv_machine_learning/landmark_detection/src/LandmarkDetection.cpp index d4f179e3..3f979ccf 100644 --- a/mv_machine_learning/landmark_detection/src/LandmarkDetection.cpp +++ b/mv_machine_learning/landmark_detection/src/LandmarkDetection.cpp @@ -196,6 +196,8 @@ template void LandmarkDetection::prepare() ret = _inference->load(); if (ret != MEDIA_VISION_ERROR_NONE) throw InvalidOperation("Fail to load model files."); + + configurePreprocess(); } template shared_ptr LandmarkDetection::getInputMetaInfo() @@ -213,11 +215,12 @@ template shared_ptr LandmarkDetection::getInputMetaInfo return _config->getInputMetaMap()[tensor_buffer_iter->first]; } -template -void LandmarkDetection::preprocess(mv_source_h &mv_src, shared_ptr metaInfo, vector &inputVector) +template void LandmarkDetection::configurePreprocess() { LOGI("ENTER"); + shared_ptr metaInfo = getInputMetaInfo(); + PreprocessConfig config = { false, metaInfo->colorSpace, metaInfo->dataType, @@ -241,7 +244,6 @@ void LandmarkDetection::preprocess(mv_source_h &mv_src, shared_ptr } _preprocess.setConfig(config); - _preprocess.run(mv_src, inputVector); LOGI("LEAVE"); } @@ -259,12 +261,10 @@ template void LandmarkDetection::inference(vector > &in template void LandmarkDetection::perform(mv_source_h &mv_src) { - shared_ptr metaInfo = getInputMetaInfo(); - vector inputVector; + vector > inputVectors(1); - preprocess(mv_src, metaInfo, inputVector); + _preprocess.run(mv_src, inputVectors[0]); - vector > inputVectors = { inputVector }; inference(inputVectors); } @@ -301,12 +301,10 @@ template void LandmarkDetection::performAsync(LandmarkDetectionIn }); } - shared_ptr metaInfo = getInputMetaInfo(); - vector inputVector; + vector > inputVectors(1); - preprocess(input.inference_src, metaInfo, inputVector); + _preprocess.run(input.inference_src, inputVectors[0]); - vector > inputVectors = { inputVector }; _async_manager->push(inputVectors); } diff --git a/mv_machine_learning/object_detection/include/ObjectDetection.h b/mv_machine_learning/object_detection/include/ObjectDetection.h index 03bce201..ad3b71d8 100644 --- a/mv_machine_learning/object_detection/include/ObjectDetection.h +++ b/mv_machine_learning/object_detection/include/ObjectDetection.h @@ -51,7 +51,7 @@ private: void loadLabel(); void getEngineList(); void getDeviceList(const std::string &engine_type); - void preprocess(mv_source_h &mv_src, std::shared_ptr metaInfo, std::vector &inputVector); + void configurePreprocess(); std::shared_ptr getInputMetaInfo(); protected: diff --git a/mv_machine_learning/object_detection/src/ObjectDetection.cpp b/mv_machine_learning/object_detection/src/ObjectDetection.cpp index ea31f322..ddf9ab1b 100644 --- a/mv_machine_learning/object_detection/src/ObjectDetection.cpp +++ b/mv_machine_learning/object_detection/src/ObjectDetection.cpp @@ -196,6 +196,8 @@ template void ObjectDetection::prepare() ret = _inference->load(); if (ret != MEDIA_VISION_ERROR_NONE) throw InvalidOperation("Fail to load model files."); + + configurePreprocess(); } template shared_ptr ObjectDetection::getInputMetaInfo() @@ -213,11 +215,12 @@ template shared_ptr ObjectDetection::getInputMetaInfo() return _config->getInputMetaMap()[tensor_buffer_iter->first]; } -template -void ObjectDetection::preprocess(mv_source_h &mv_src, shared_ptr metaInfo, vector &inputVector) +template void ObjectDetection::configurePreprocess() { LOGI("ENTER"); + shared_ptr metaInfo = getInputMetaInfo(); + PreprocessConfig config = { false, metaInfo->colorSpace, metaInfo->dataType, @@ -241,7 +244,6 @@ void ObjectDetection::preprocess(mv_source_h &mv_src, shared_ptr me } _preprocess.setConfig(config); - _preprocess.run(mv_src, inputVector); LOGI("LEAVE"); } @@ -259,12 +261,10 @@ template void ObjectDetection::inference(vector > &inpu template void ObjectDetection::perform(mv_source_h &mv_src) { - shared_ptr metaInfo = getInputMetaInfo(); - vector inputVector; + vector > inputVectors(1); - preprocess(mv_src, metaInfo, inputVector); + _preprocess.run(mv_src, inputVectors[0]); - vector > inputVectors = { inputVector }; inference(inputVectors); } @@ -283,12 +283,10 @@ template void ObjectDetection::performAsync(ObjectDetectionInput }); } - shared_ptr metaInfo = getInputMetaInfo(); - vector inputVector; + vector > inputVectors(1); - preprocess(input.inference_src, metaInfo, inputVector); + _preprocess.run(input.inference_src, inputVectors[0]); - vector > inputVectors = { inputVector }; _async_manager->push(inputVectors); } diff --git a/mv_machine_learning/object_detection_3d/include/ObjectDetection3d.h b/mv_machine_learning/object_detection_3d/include/ObjectDetection3d.h index e2b347a5..fb6058dc 100644 --- a/mv_machine_learning/object_detection_3d/include/ObjectDetection3d.h +++ b/mv_machine_learning/object_detection_3d/include/ObjectDetection3d.h @@ -54,7 +54,7 @@ protected: void getOutputNames(std::vector &names); void getOutputTensor(std::string &target_name, std::vector &tensor); - void preprocess(mv_source_h &mv_src, std::shared_ptr metaInfo, std::vector &inputVector); + void configurePreprocess(); void inference(std::vector > &inputVectors); public: diff --git a/mv_machine_learning/object_detection_3d/src/ObjectDetection3d.cpp b/mv_machine_learning/object_detection_3d/src/ObjectDetection3d.cpp index 120f6476..51f1b109 100644 --- a/mv_machine_learning/object_detection_3d/src/ObjectDetection3d.cpp +++ b/mv_machine_learning/object_detection_3d/src/ObjectDetection3d.cpp @@ -186,6 +186,8 @@ template void ObjectDetection3d::prepare() ret = _inference->load(); if (ret != MEDIA_VISION_ERROR_NONE) throw InvalidOperation("Fail to load model files."); + + configurePreprocess(); } template shared_ptr ObjectDetection3d::getInputMetaInfo() @@ -203,11 +205,12 @@ template shared_ptr ObjectDetection3d::getInputMetaInfo return _config->getInputMetaMap()[tensor_buffer_iter->first]; } -template -void ObjectDetection3d::preprocess(mv_source_h &mv_src, shared_ptr metaInfo, vector &inputVector) +template void ObjectDetection3d::configurePreprocess() { LOGI("ENTER"); + shared_ptr metaInfo = getInputMetaInfo(); + PreprocessConfig config = { false, metaInfo->colorSpace, metaInfo->dataType, @@ -231,7 +234,6 @@ void ObjectDetection3d::preprocess(mv_source_h &mv_src, shared_ptr } _preprocess.setConfig(config); - _preprocess.run(mv_src, inputVector); LOGI("LEAVE"); } @@ -249,11 +251,9 @@ template void ObjectDetection3d::inference(vector > &in template void ObjectDetection3d::perform(mv_source_h &mv_src, shared_ptr metaInfo) { - vector inputVector; - - preprocess(mv_src, metaInfo, inputVector); + vector > inputVectors(1); - vector > inputVectors = { inputVector }; + _preprocess.run(mv_src, inputVectors[0]); inference(inputVectors); }