From: Tae-Young Chung Date: Wed, 18 Aug 2021 06:36:07 +0000 (+0900) Subject: Add Quantize() to PreProcess X-Git-Tag: submit/tizen/20210820.005508~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e72aa182aadb43c77060331b582da76c48fb8ea9;p=platform%2Fcore%2Fapi%2Fmediavision.git Add Quantize() to PreProcess Change-Id: I4df22f0ec4e1bcf663459083ce77f70d91c7a600 Signed-off-by: Tae-Young Chung --- diff --git a/mv_machine_learning/mv_inference/inference/include/PreProcess.h b/mv_machine_learning/mv_inference/inference/include/PreProcess.h index f4c002bb..4121557f 100644 --- a/mv_machine_learning/mv_inference/inference/include/PreProcess.h +++ b/mv_machine_learning/mv_inference/inference/include/PreProcess.h @@ -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& mean, const std::vector& std); + int Quantize(cv::Mat& source, cv::Mat& dest, + const std::vector& scale, const std::vector& zeropoint); }; diff --git a/mv_machine_learning/mv_inference/inference/src/PreProcess.cpp b/mv_machine_learning/mv_inference/inference/src/PreProcess.cpp index fa65ced2..6d795863 100644 --- a/mv_machine_learning/mv_inference/inference/src/PreProcess.cpp +++ b/mv_machine_learning/mv_inference/inference/src/PreProcess.cpp @@ -83,6 +83,7 @@ namespace inference const std::vector& mean, const std::vector& 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& scale, const std::vector& 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; diff --git a/packaging/capi-media-vision.spec b/packaging/capi-media-vision.spec index 1462ad34..e86b09c6 100644 --- a/packaging/capi-media-vision.spec +++ b/packaging/capi-media-vision.spec @@ -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