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 f4c002bb245b9535ad224a26f28346f97950855b..4121557f2606eee5208a51a6e2c1f9be627ef2e1 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 fa65ced25a8555a218816644e0824c7f1a23943e..6d79586330f0c7ca964e17d98a14643bc4265865 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 1462ad34d74872b8e269499cd3f80edb41926b51..e86b09c610e78406ffd622b171158c21c5d10f38 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