summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVibhav Aggarwal <v.aggarwal@samsung.com>2024-01-26 13:23:21 +0900
committerVibhav Aggarwal <v.aggarwal@samsung.com>2024-01-26 14:17:04 +0900
commita651bfdbde7341edb447e6d6d55b4a38fa4fea3a (patch)
treef883cac49ae9b28c6162de1be1c9611976b7a411
parent71146dc5cf9abf9b888243f452b9d596f80d55ef (diff)
downloadmediavision-a651bfdbde7341edb447e6d6d55b4a38fa4fea3a.tar.gz
mediavision-a651bfdbde7341edb447e6d6d55b4a38fa4fea3a.tar.bz2
mediavision-a651bfdbde7341edb447e6d6d55b4a38fa4fea3a.zip
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 <v.aggarwal@samsung.com>
-rw-r--r--mv_machine_learning/image_segmentation/include/ImageSegmentation.h2
-rw-r--r--mv_machine_learning/image_segmentation/src/ImageSegmentation.cpp20
-rw-r--r--mv_machine_learning/landmark_detection/include/LandmarkDetection.h2
-rw-r--r--mv_machine_learning/landmark_detection/src/LandmarkDetection.cpp20
-rw-r--r--mv_machine_learning/object_detection/include/ObjectDetection.h2
-rw-r--r--mv_machine_learning/object_detection/src/ObjectDetection.cpp20
-rw-r--r--mv_machine_learning/object_detection_3d/include/ObjectDetection3d.h2
-rw-r--r--mv_machine_learning/object_detection_3d/src/ObjectDetection3d.cpp14
8 files changed, 38 insertions, 44 deletions
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> metaInfo, std::vector<T> &inputVector);
+ void configurePreprocess();
std::shared_ptr<MetaInfo> 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<typename T> void ImageSegmentation<T>::prepare()
ret = _inference->load();
if (ret != MEDIA_VISION_ERROR_NONE)
throw InvalidOperation("Fail to load model files.");
+
+ configurePreprocess();
}
template<typename T> shared_ptr<MetaInfo> ImageSegmentation<T>::getInputMetaInfo()
@@ -211,11 +213,12 @@ template<typename T> shared_ptr<MetaInfo> ImageSegmentation<T>::getInputMetaInfo
return _config->getInputMetaMap()[tensor_buffer_iter->first];
}
-template<typename T>
-void ImageSegmentation<T>::preprocess(mv_source_h &mv_src, shared_ptr<MetaInfo> metaInfo, vector<T> &inputVector)
+template<typename T> void ImageSegmentation<T>::configurePreprocess()
{
LOGI("ENTER");
+ shared_ptr<MetaInfo> metaInfo = getInputMetaInfo();
+
PreprocessConfig config = { false,
metaInfo->colorSpace,
metaInfo->dataType,
@@ -239,7 +242,6 @@ void ImageSegmentation<T>::preprocess(mv_source_h &mv_src, shared_ptr<MetaInfo>
}
_preprocess.setConfig(config);
- _preprocess.run<T>(mv_src, inputVector);
LOGI("LEAVE");
}
@@ -257,12 +259,10 @@ template<typename T> void ImageSegmentation<T>::inference(vector<vector<T> > &in
template<typename T> void ImageSegmentation<T>::perform(mv_source_h &mv_src)
{
- shared_ptr<MetaInfo> metaInfo = getInputMetaInfo();
- vector<T> inputVector;
+ vector<vector<T> > inputVectors(1);
- preprocess(mv_src, metaInfo, inputVector);
+ _preprocess.run<T>(mv_src, inputVectors[0]);
- vector<vector<T> > inputVectors = { inputVector };
inference(inputVectors);
}
@@ -281,12 +281,10 @@ template<typename T> void ImageSegmentation<T>::performAsync(ImageSegmentationIn
});
}
- shared_ptr<MetaInfo> metaInfo = getInputMetaInfo();
- vector<T> inputVector;
+ vector<vector<T> > inputVectors(1);
- preprocess(input.inference_src, metaInfo, inputVector);
+ _preprocess.run<T>(input.inference_src, inputVectors[0]);
- vector<vector<T> > 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> metaInfo, std::vector<T> &inputVector);
+ void configurePreprocess();
std::shared_ptr<MetaInfo> 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<typename T> void LandmarkDetection<T>::prepare()
ret = _inference->load();
if (ret != MEDIA_VISION_ERROR_NONE)
throw InvalidOperation("Fail to load model files.");
+
+ configurePreprocess();
}
template<typename T> shared_ptr<MetaInfo> LandmarkDetection<T>::getInputMetaInfo()
@@ -213,11 +215,12 @@ template<typename T> shared_ptr<MetaInfo> LandmarkDetection<T>::getInputMetaInfo
return _config->getInputMetaMap()[tensor_buffer_iter->first];
}
-template<typename T>
-void LandmarkDetection<T>::preprocess(mv_source_h &mv_src, shared_ptr<MetaInfo> metaInfo, vector<T> &inputVector)
+template<typename T> void LandmarkDetection<T>::configurePreprocess()
{
LOGI("ENTER");
+ shared_ptr<MetaInfo> metaInfo = getInputMetaInfo();
+
PreprocessConfig config = { false,
metaInfo->colorSpace,
metaInfo->dataType,
@@ -241,7 +244,6 @@ void LandmarkDetection<T>::preprocess(mv_source_h &mv_src, shared_ptr<MetaInfo>
}
_preprocess.setConfig(config);
- _preprocess.run<T>(mv_src, inputVector);
LOGI("LEAVE");
}
@@ -259,12 +261,10 @@ template<typename T> void LandmarkDetection<T>::inference(vector<vector<T> > &in
template<typename T> void LandmarkDetection<T>::perform(mv_source_h &mv_src)
{
- shared_ptr<MetaInfo> metaInfo = getInputMetaInfo();
- vector<T> inputVector;
+ vector<vector<T> > inputVectors(1);
- preprocess(mv_src, metaInfo, inputVector);
+ _preprocess.run<T>(mv_src, inputVectors[0]);
- vector<vector<T> > inputVectors = { inputVector };
inference(inputVectors);
}
@@ -301,12 +301,10 @@ template<typename T> void LandmarkDetection<T>::performAsync(LandmarkDetectionIn
});
}
- shared_ptr<MetaInfo> metaInfo = getInputMetaInfo();
- vector<T> inputVector;
+ vector<vector<T> > inputVectors(1);
- preprocess(input.inference_src, metaInfo, inputVector);
+ _preprocess.run<T>(input.inference_src, inputVectors[0]);
- vector<vector<T> > 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> metaInfo, std::vector<T> &inputVector);
+ void configurePreprocess();
std::shared_ptr<MetaInfo> 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<typename T> void ObjectDetection<T>::prepare()
ret = _inference->load();
if (ret != MEDIA_VISION_ERROR_NONE)
throw InvalidOperation("Fail to load model files.");
+
+ configurePreprocess();
}
template<typename T> shared_ptr<MetaInfo> ObjectDetection<T>::getInputMetaInfo()
@@ -213,11 +215,12 @@ template<typename T> shared_ptr<MetaInfo> ObjectDetection<T>::getInputMetaInfo()
return _config->getInputMetaMap()[tensor_buffer_iter->first];
}
-template<typename T>
-void ObjectDetection<T>::preprocess(mv_source_h &mv_src, shared_ptr<MetaInfo> metaInfo, vector<T> &inputVector)
+template<typename T> void ObjectDetection<T>::configurePreprocess()
{
LOGI("ENTER");
+ shared_ptr<MetaInfo> metaInfo = getInputMetaInfo();
+
PreprocessConfig config = { false,
metaInfo->colorSpace,
metaInfo->dataType,
@@ -241,7 +244,6 @@ void ObjectDetection<T>::preprocess(mv_source_h &mv_src, shared_ptr<MetaInfo> me
}
_preprocess.setConfig(config);
- _preprocess.run<T>(mv_src, inputVector);
LOGI("LEAVE");
}
@@ -259,12 +261,10 @@ template<typename T> void ObjectDetection<T>::inference(vector<vector<T> > &inpu
template<typename T> void ObjectDetection<T>::perform(mv_source_h &mv_src)
{
- shared_ptr<MetaInfo> metaInfo = getInputMetaInfo();
- vector<T> inputVector;
+ vector<vector<T> > inputVectors(1);
- preprocess(mv_src, metaInfo, inputVector);
+ _preprocess.run<T>(mv_src, inputVectors[0]);
- vector<vector<T> > inputVectors = { inputVector };
inference(inputVectors);
}
@@ -283,12 +283,10 @@ template<typename T> void ObjectDetection<T>::performAsync(ObjectDetectionInput
});
}
- shared_ptr<MetaInfo> metaInfo = getInputMetaInfo();
- vector<T> inputVector;
+ vector<vector<T> > inputVectors(1);
- preprocess(input.inference_src, metaInfo, inputVector);
+ _preprocess.run<T>(input.inference_src, inputVectors[0]);
- vector<vector<T> > 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<std::string> &names);
void getOutputTensor(std::string &target_name, std::vector<float> &tensor);
- void preprocess(mv_source_h &mv_src, std::shared_ptr<MetaInfo> metaInfo, std::vector<T> &inputVector);
+ void configurePreprocess();
void inference(std::vector<std::vector<T> > &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<typename T> void ObjectDetection3d<T>::prepare()
ret = _inference->load();
if (ret != MEDIA_VISION_ERROR_NONE)
throw InvalidOperation("Fail to load model files.");
+
+ configurePreprocess();
}
template<typename T> shared_ptr<MetaInfo> ObjectDetection3d<T>::getInputMetaInfo()
@@ -203,11 +205,12 @@ template<typename T> shared_ptr<MetaInfo> ObjectDetection3d<T>::getInputMetaInfo
return _config->getInputMetaMap()[tensor_buffer_iter->first];
}
-template<typename T>
-void ObjectDetection3d<T>::preprocess(mv_source_h &mv_src, shared_ptr<MetaInfo> metaInfo, vector<T> &inputVector)
+template<typename T> void ObjectDetection3d<T>::configurePreprocess()
{
LOGI("ENTER");
+ shared_ptr<MetaInfo> metaInfo = getInputMetaInfo();
+
PreprocessConfig config = { false,
metaInfo->colorSpace,
metaInfo->dataType,
@@ -231,7 +234,6 @@ void ObjectDetection3d<T>::preprocess(mv_source_h &mv_src, shared_ptr<MetaInfo>
}
_preprocess.setConfig(config);
- _preprocess.run<T>(mv_src, inputVector);
LOGI("LEAVE");
}
@@ -249,11 +251,9 @@ template<typename T> void ObjectDetection3d<T>::inference(vector<vector<T> > &in
template<typename T> void ObjectDetection3d<T>::perform(mv_source_h &mv_src, shared_ptr<MetaInfo> metaInfo)
{
- vector<T> inputVector;
-
- preprocess(mv_src, metaInfo, inputVector);
+ vector<vector<T> > inputVectors(1);
- vector<vector<T> > inputVectors = { inputVector };
+ _preprocess.run<T>(mv_src, inputVectors[0]);
inference(inputVectors);
}