mv_machine_learning: do not convert output tensor in default 58/320758/2
authorInki Dae <inki.dae@samsung.com>
Fri, 7 Mar 2025 01:37:13 +0000 (10:37 +0900)
committerInki Dae <inki.dae@samsung.com>
Fri, 7 Mar 2025 08:18:19 +0000 (17:18 +0900)
Do not convert output tensor in default. Until now, Mediavision
converted output tensor type of quantized model to float type
in default. However, the conversion isn't mandatory and it incurs
performance degration due to unnecessary memory copy.

So this patch drops the conversion work and make each model specific
function to convert its own output tensor as a postprocessing just by
moving the conversion function call to model specific code.

This is a first step for code refactoring.

Change-Id: Icfa5bea6b432161443e19bb7b47a8cbe6f203a0b
Signed-off-by: Inki Dae <inki.dae@samsung.com>
23 files changed:
mv_machine_learning/gaze_tracking/include/L2CSNet.h
mv_machine_learning/gaze_tracking/include/L2CSNetMobileNetV2.h
mv_machine_learning/gaze_tracking/include/TinyTracker.h
mv_machine_learning/gaze_tracking/src/L2CSNet.cpp
mv_machine_learning/gaze_tracking/src/L2CSNetMobileNetV2.cpp
mv_machine_learning/gaze_tracking/src/TinyTracker.cpp
mv_machine_learning/image_classification/include/ImageClassificationDefault.h
mv_machine_learning/image_classification/src/ImageClassificationDefault.cpp
mv_machine_learning/image_segmentation/include/DeeplabV3.h
mv_machine_learning/image_segmentation/include/Stdc1.h
mv_machine_learning/inference/include/Inference.h
mv_machine_learning/inference/src/Inference.cpp
mv_machine_learning/landmark_detection/include/PldCpm.h
mv_machine_learning/landmark_detection/src/FldTweakCnn.cpp
mv_machine_learning/landmark_detection/src/FldU2net.cpp
mv_machine_learning/landmark_detection/src/HandLander.cpp
mv_machine_learning/landmark_detection/src/PldCpm.cpp
mv_machine_learning/object_detection/include/MobilenetV1Ssd.h
mv_machine_learning/object_detection/include/MobilenetV2Ssd.h
mv_machine_learning/object_detection/src/HailoYoloXs.cpp
mv_machine_learning/object_detection/src/MobilenetV1Ssd.cpp
mv_machine_learning/object_detection/src/MobilenetV2Ssd.cpp
mv_machine_learning/object_detection/src/PalmDetection.cpp

index e59e18a1bee70c47d864277124ba6ad2c97aa98a..71945f6f1e61929d2abec3bd988ca4bb3f114478 100644 (file)
@@ -33,6 +33,7 @@ template<typename T> class L2CSNet : public GazeTracking<T>
 {
        using GazeTracking<T>::_config;
        using GazeTracking<T>::_preprocess;
+       using GazeTracking<T>::_inference;
 
 private:
        GazeTrackingResult _result;
index bde679041c16dea2fe879eb7e5092245061158b3..07c834c2892503df3400f71d372fc76b9a24f79c 100644 (file)
@@ -33,6 +33,7 @@ template<typename T> class L2CSNetMobileNetv2 : public GazeTracking<T>
 {
        using GazeTracking<T>::_config;
        using GazeTracking<T>::_preprocess;
+       using GazeTracking<T>::_inference;
 
 private:
        GazeTrackingResult _result;
index 245ed74cf4da1fd77269c77005ac53c193768d0e..74c6967e7ff3c3737cff27ae224aa0f9817fb58f 100644 (file)
@@ -33,6 +33,7 @@ template<typename T> class TinyTracker : public GazeTracking<T>
 {
        using GazeTracking<T>::_config;
        using GazeTracking<T>::_preprocess;
+       using GazeTracking<T>::_inference;
 
 private:
        GazeTrackingResult _result;
index 19fc3892fb6d50565f0a1e36212341180b557907..319e956ba3fe03dfdd54836f9818f3ec3589c32a 100644 (file)
@@ -45,6 +45,7 @@ template<typename T> GazeTrackingResult &L2CSNet<T>::result()
        // Clear _result object because result() function can be called every time user wants
        // so make sure to clear existing result data before getting the data again.
        _result = GazeTrackingResult();
+       _inference->convertOutputDataTypeToFloat();
 
        vector<string> names;
 
index 9008c938e111367065b1285c79c4e52fb0b43090..41062c0b23e3e212b3d0792e00480d4111bebebd 100644 (file)
@@ -67,6 +67,7 @@ template<typename T> GazeTrackingResult &L2CSNetMobileNetv2<T>::result()
        // Clear _result object because result() function can be called every time user wants
        // so make sure to clear existing result data before getting the data again.
        _result = GazeTrackingResult();
+       _inference->convertOutputDataTypeToFloat();
 
        vector<string> names;
 
index 4bae8e6178fdbf1be549229c42375bfc126b003a..83973e96dedbc3028f328219c33d7952f47b3887 100644 (file)
@@ -45,6 +45,7 @@ template<typename T> GazeTrackingResult &TinyTracker<T>::result()
        // Clear _result object because result() function can be called every time user wants
        // so make sure to clear existing result data before getting the data again.
        _result = GazeTrackingResult();
+       _inference->convertOutputDataTypeToFloat();
 
        vector<string> names;
 
index 5538907bd10bd7e00f91e1e40a847b7b24189f04..ec0e1b2a1bb87396fd8c284ac1ad0ef083700489 100644 (file)
@@ -33,6 +33,7 @@ template<typename T> class ImageClassificationDefault : public ImageClassificati
 {
        using ImageClassification<T>::_config;
        using ImageClassification<T>::_labels;
+       using ImageClassification<T>::_inference;
 
 private:
        ImageClassificationResult _result;
index 811d921b54d32f51cd42bcd1993353b4f60706ac..d85a908ae9e52e159705e845bb6339617e26200e 100644 (file)
@@ -41,6 +41,7 @@ template<typename T> ImageClassificationDefault<T>::~ImageClassificationDefault(
 
 template<typename T> ImageClassificationResult &ImageClassificationDefault<T>::result()
 {
+       _inference->convertOutputDataTypeToFloat();
        vector<string> names;
 
        ImageClassification<T>::getOutputNames(names);
index a9a0666a3eb5da80c7ed086af9f8c2eb8d15b04f..1fc8ac5f3fb44816ac8c940628d8d36da776c7ec 100644 (file)
@@ -34,6 +34,7 @@ template<typename T> class DeeplabV3 : public ImageSegmentation<T>
        using ImageSegmentation<T>::_config;
        using ImageSegmentation<T>::_preprocess;
        using ImageSegmentation<T>::_labels;
+       using ImageSegmentation<T>::_inference;
 
 private:
        ImageSegmentationResult _result;
index 681caf90a2a28003486745a7067246a0d3a0317d..0cdeff53a4c45a9b39628db1751df12b8b510a9a 100644 (file)
@@ -34,6 +34,7 @@ template<typename T> class Stdc1 : public ImageSegmentation<T>
        using ImageSegmentation<T>::_config;
        using ImageSegmentation<T>::_preprocess;
        using ImageSegmentation<T>::_labels;
+       using ImageSegmentation<T>::_inference;
 
 private:
        ImageSegmentationResult _result;
index 50b31a4d7e478b137867ea7763b4a5e0fa3221b9..17d55da1fdbabe4a5d68b3cc69a96bd059997473 100644 (file)
@@ -347,6 +347,8 @@ public:
                return mInputSize.height;
        }
 
+       int convertOutputDataTypeToFloat();
+
 private:
        bool mCanRun = false; /**< The flag indicating ready to run Inference */
        InferenceConfig mConfig;
@@ -391,7 +393,6 @@ private:
        int convertEngineErrorToVisionError(int error);
        int convertTargetTypes(int given_types);
        int convertToCv(int given_type);
-       int convertOutputDataTypeToFloat();
        int preprocess(std::vector<mv_source_h> &mv_sources, std::vector<cv::Mat> &cv_sources);
        inference_tensor_data_type_e convertToIE(int given_type);
        int prepareTenosrBuffers(void);
index 7829e67fa8e605d74ac10bb035b62a504f090249..63bd41bdc7e88027bf7232beaea2c191f94f1c87 100644 (file)
@@ -1039,7 +1039,7 @@ template<typename T> int Inference::run(std::vector<std::vector<T> > &input_tens
        if (ret != INFERENCE_ENGINE_ERROR_NONE)
                return ret;
 
-       return convertOutputDataTypeToFloat();
+       return INFERENCE_ENGINE_ERROR_NONE;
 }
 
 int Inference::run()
index b29d954141a0b6d6db80d224cb7ac65be9c911a3..351b12bf6de0ad200bbc446c7d4309f2fe7c328a 100644 (file)
@@ -33,6 +33,7 @@ template<typename T> class PldCpm : public LandmarkDetection<T>
 {
        using LandmarkDetection<T>::_config;
        using LandmarkDetection<T>::_preprocess;
+       using LandmarkDetection<T>::_inference;
 
 private:
        LandmarkDetectionResult _result;
index 97421697a482e172afcf4c24384d584bd0455344..01262cae69480289225a8fd55d79001a3f2a46c8 100644 (file)
@@ -45,6 +45,7 @@ template<typename T> LandmarkDetectionResult &FldTweakCnn<T>::result()
        // Clear _result object because result() function can be called every time user wants
        // so make sure to clear existing result data before getting the data again.
        _result = LandmarkDetectionResult();
+       _inference->convertOutputDataTypeToFloat();
 
        vector<string> names;
 
index 5ccf95e35e1fcabbefed9cea3ed5a38dedb022f7..56e862f65725c99111345f83596b4d7c985ea74f 100644 (file)
@@ -45,6 +45,7 @@ template<typename T> LandmarkDetectionResult &FldU2net<T>::result()
        // Clear _result object because result() function can be called every time user wants
        // so make sure to clear existing result data before getting the data again.
        _result = LandmarkDetectionResult();
+       _inference->convertOutputDataTypeToFloat();
 
        vector<string> names;
 
index 422c0b9a8090bae26e10af655c299a3c8c3fe705..4b9fdf0e316a0b4b2db49dd4129ddefcded25b2f 100644 (file)
@@ -43,6 +43,7 @@ template<typename T> LandmarkDetectionResult &HandLander<T>::result()
        // Clear _result object because result() function can be called every time user wants
        // so make sure to clear existing result data before getting the data again.
        _result = LandmarkDetectionResult();
+       _inference->convertOutputDataTypeToFloat();
 
        vector<string> names;
 
index 89b0f99dd60e464bfbe90319859801fb791469c5..ad81b7c98317f14a887b7af5168c0dfeeefa5d89 100644 (file)
@@ -44,6 +44,7 @@ template<typename T> LandmarkDetectionResult &PldCpm<T>::result()
        // Clear _result object because result() function can be called every time user wants
        // so make sure to clear existing result data before getting the data again.
        _result = LandmarkDetectionResult();
+       _inference->convertOutputDataTypeToFloat();
 
        vector<string> names;
 
index b9017fd1937d655813c2690f376a60267e8b2e52..0c921cb0490f2340b7c5d082c278973d9dd7e816 100644 (file)
@@ -32,6 +32,7 @@ namespace machine_learning
 template<typename T> class MobilenetV1Ssd : public ObjectDetection<T>
 {
        using ObjectDetection<T>::_config;
+       using ObjectDetection<T>::_inference;
        using ObjectDetection<T>::_preprocess;
        using ObjectDetection<T>::_labels;
 
index 0df2bebe2bdfaa7bb9c0ace4591e7c3ba06d49bb..a019520cef4d065f2ce25ed1f4abb85a02c9f50e 100644 (file)
@@ -32,6 +32,7 @@ namespace machine_learning
 template<typename T> class MobilenetV2Ssd : public ObjectDetection<T>
 {
        using ObjectDetection<T>::_config;
+       using ObjectDetection<T>::_inference;
        using ObjectDetection<T>::_preprocess;
        using ObjectDetection<T>::_labels;
 
index 5a495d5f363196e85eaf11f27bc1217ef21f2e2c..66d633040031e062225b1d363ab8e9c24828a97a 100644 (file)
@@ -44,6 +44,7 @@ template<typename T> ObjectDetectionResult &HailoYoloXs<T>::result()
        // Clear _result object because result() function can be called every time user wants
        // so make sure to clear existing result data before getting the data again.
        _result = ObjectDetectionResult();
+       _inference->convertOutputDataTypeToFloat();
 
        vector<string> names;
 
index 60340251e5dd470c0085bcae2fa296a709be7e76..d3d09b7bb739c2b35446460c6bd8794f986a4b41 100644 (file)
@@ -44,6 +44,7 @@ template<typename T> ObjectDetectionResult &MobilenetV1Ssd<T>::result()
        // Clear _result object because result() function can be called every time user wants
        // so make sure to clear existing result data before getting the data again.
        _result = ObjectDetectionResult();
+       _inference->convertOutputDataTypeToFloat();
 
        vector<string> names;
 
index fe1c999e57e6adb9ba92d07eacd8265c537ee3b6..68b61a8bb89a9c56982f63b7c483045cdbb79a0d 100644 (file)
@@ -179,6 +179,7 @@ template<typename T> ObjectDetectionResult &MobilenetV2Ssd<T>::result()
        // Clear _result object because result() function can be called every time user wants
        // so make sure to clear existing result data before getting the data again.
        _result = ObjectDetectionResult();
+       _inference->convertOutputDataTypeToFloat();
 
        vector<string> names;
 
index 0c9db3f25ab6cd4e4491aecfb040600fcbfbf2a0..096a10c57fa863c0ab151b1cd51be3c3a05d17ef 100644 (file)
@@ -298,6 +298,7 @@ template<typename T> ObjectDetectionResult &PalmDetection<T>::result()
        // Clear _result object because result() function can be called every time user wants
        // so make sure to clear existing result data before getting the data again.
        _result = ObjectDetectionResult();
+       _inference->convertOutputDataTypeToFloat();
 
        list<Palm> palm;
        DecodeKeypoints(palm);