Add Quantize() to PreProcess 01/262701/2
authorTae-Young Chung <ty83.chung@samsung.com>
Wed, 18 Aug 2021 06:36:07 +0000 (15:36 +0900)
committerkwang son <k.son@samsung.com>
Thu, 19 Aug 2021 00:49:05 +0000 (00:49 +0000)
Change-Id: I4df22f0ec4e1bcf663459083ce77f70d91c7a600
Signed-off-by: Tae-Young Chung <ty83.chung@samsung.com>
mv_machine_learning/mv_inference/inference/include/PreProcess.h
mv_machine_learning/mv_inference/inference/src/PreProcess.cpp
packaging/capi-media-vision.spec

index f4c002b..4121557 100644 (file)
@@ -68,6 +68,8 @@ namespace inference
                int ColorConvert(cv::Mat& source, cv::Mat& dest, int sType, int dType);
                int Normalize(cv::Mat& source, cv::Mat& dest,
                                        const std::vector<double>& mean, const std::vector<double>& std);
+               int Quantize(cv::Mat& source, cv::Mat& dest,
+                                       const std::vector<double>& scale, const std::vector<double>& zeropoint);
 
        };
 
index fa65ced..6d79586 100644 (file)
@@ -83,6 +83,7 @@ namespace inference
                                                        const std::vector<double>& mean, const std::vector<double>& std)
        {
                LOGI("ENTER");
+
                try {
                        cv::subtract(source, cv::Scalar(mean[0], mean[1], mean[2]), dest);
                        source = dest;
@@ -97,6 +98,25 @@ namespace inference
                return MEDIA_VISION_ERROR_NONE;
        }
 
+       int PreProcess::Quantize(cv::Mat& source, cv::Mat& dest,
+                                                       const std::vector<double>& scale, const std::vector<double>& zeropoint)
+       {
+               LOGI("ENTER");
+
+               try {
+                       cv::subtract(source, cv::Scalar(zeropoint[0], zeropoint[1], zeropoint[2]), dest);
+                       source = dest;
+                       cv::multiply(source, cv::Scalar(scale[0], scale[1], scale[2]), dest);
+               } catch (cv::Exception& e) {
+                       LOGE("Fail to subtract/multiply with msg: %s", e.what());
+                       return MEDIA_VISION_ERROR_INVALID_OPERATION;
+               }
+
+               LOGI("LEAVE");
+
+               return MEDIA_VISION_ERROR_NONE;
+       }
+
        int PreProcess::Run(cv::Mat& source, const int colorSpace,
                                                        const int dataType, const LayerInfo& layerInfo,
                                                        const Options& options, void* buffer)
@@ -121,6 +141,10 @@ namespace inference
                        Normalize(dest, dest, options.normalization.mean, options.normalization.std);
                }
 
+               if (options.quantization.use) {
+                       Quantize(dest, dest, options.quantization.scale, options.quantization.zeropoint);
+               }
+
                LOGI("LEAVE");
 
                return MEDIA_VISION_ERROR_NONE;
index 1462ad3..e86b09c 100644 (file)
@@ -1,6 +1,6 @@
 Name:        capi-media-vision
 Summary:     Media Vision library for Tizen Native API
-Version:     0.8.7
+Version:     0.8.8
 Release:     0
 Group:       Multimedia/Framework
 License:     Apache-2.0 and BSD-3-Clause