mv_machine_learning:code refactoring to Inference.cpp 34/264734/3
authorInki Dae <inki.dae@samsung.com>
Mon, 27 Sep 2021 07:49:21 +0000 (16:49 +0900)
committerInki Dae <inki.dae@samsung.com>
Wed, 29 Sep 2021 05:57:58 +0000 (14:57 +0900)
Did code refactoring to Inference.cpp module for next code
refactoring work.

What this patch did are,
 - just drop all unnecessary members  of Inference class
 - and gather some spreaded code to relevant place.

Change-Id: I2fa00af5b0b8701c4bdbbf62d07a2f9f2ef2bc85
Signed-off-by: Inki Dae <inki.dae@samsung.com>
mv_machine_learning/mv_inference/inference/include/Inference.h
mv_machine_learning/mv_inference/inference/src/Inference.cpp

index ccd75bb..1b65421 100644 (file)
@@ -351,13 +351,8 @@ namespace inference
                std::map<int, std::pair<std::string, bool> > mSupportedInferenceBackend;
                cv::Size mInputSize;
                int mCh;
-               int mDim;
-               double mDeviation;
-               double mMean;
                double mThreshold;
-               int mOutputNumbers;
                cv::Size mSourceSize;
-               cv::Mat mInputBuffer;
                mv_engine_config_h engine_config;
                InferenceEngineCommon *mBackend;
                std::map<std::string, int> mModelFormats;
index 68db605..7194736 100755 (executable)
@@ -72,13 +72,8 @@ namespace inference
                        mSupportedInferenceBackend(),
                        mInputSize(cv::Size()),
                        mCh(),
-                       mDim(),
-                       mDeviation(),
-                       mMean(),
                        mThreshold(),
-                       mOutputNumbers(),
                        mSourceSize(cv::Size()),
-                       mInputBuffer(cv::Mat()),
                        engine_config(),
                        mBackend(),
                        mPoseResult(NULL),
@@ -312,17 +307,16 @@ namespace inference
                // normalize
                cv::Mat sampleNormalized;
                cv::Mat meanMat;
+               auto mean = static_cast<float>(mConfig.mMeanValue);
+
                if (mCh == 3)
-                       meanMat = cv::Mat(sampleFloat.size(), CV_32FC3,
-                                                         cv::Scalar((float) mMean, (float) mMean,
-                                                         (float) mMean));
+                       meanMat = cv::Mat(sampleFloat.size(), CV_32FC3, cv::Scalar(mean, mean, mean));
                else
-                       meanMat = cv::Mat(sampleFloat.size(), CV_32FC1,
-                                                         cv::Scalar((float) mMean));
+                       meanMat = cv::Mat(sampleFloat.size(), CV_32FC1, cv::Scalar(mean));
 
                cv::subtract(sampleFloat, meanMat, sampleNormalized);
 
-               sampleNormalized /= static_cast<float>(mDeviation);
+               sampleNormalized /= static_cast<float>(mConfig.mStdValue);
 
                sampleNormalized.convertTo(cvDst, data_type);
 
@@ -867,17 +861,11 @@ namespace inference
                LOGI("ENTER");
 
                mCh = mConfig.mTensorInfo.ch;
-               mDim = mConfig.mTensorInfo.dim;
                mInputSize =
                                cv::Size(mConfig.mTensorInfo.width, mConfig.mTensorInfo.height);
                LOGI("InputSize is %d x %d\n", mInputSize.width, mInputSize.height);
-
-               mDeviation = mConfig.mStdValue;
-               mMean = mConfig.mMeanValue;
-               LOGI("mean %.4f, deviation %.4f", mMean, mDeviation);
-
-               mOutputNumbers = mConfig.mMaxOutputNumbers;
-               LOGI("outputNumber %d", mOutputNumbers);
+               LOGI("mean %.4f, deviation %.4f", mConfig.mMeanValue,  mConfig.mStdValue);
+               LOGI("outputNumber %d", mConfig.mMaxOutputNumbers);
 
                mThreshold = mConfig.mConfidenceThresHold;
                LOGI("threshold %.4f", mThreshold);
@@ -1003,13 +991,6 @@ namespace inference
                        return MEDIA_VISION_ERROR_INVALID_OPERATION;
                }
 
-               /* convert mv_source to cv::Mat */
-               cv::Mat cvSource;
-               cv::Rect cvRoi;
-               unsigned int width = 0, height = 0;
-               unsigned int bufferSize = 0;
-               unsigned char *buffer = NULL;
-
                if (mvSources.empty()) {
                        LOGE("mvSources should contain only one cv source.");
                        return MEDIA_VISION_ERROR_INVALID_PARAMETER;
@@ -1024,8 +1005,10 @@ namespace inference
                // TODO. Consider multiple sources.
                mv_source_h mvSource = mvSources.front();
                mv_rectangle_s *roi = rects.empty() ? NULL : &(rects.front());
-
                mv_colorspace_e colorspace = MEDIA_VISION_COLORSPACE_INVALID;
+               unsigned int width = 0, height = 0;
+               unsigned int bufferSize = 0;
+               unsigned char *buffer = NULL;
 
                if (mv_source_get_width(mvSource, &width) != MEDIA_VISION_ERROR_NONE ||
                        mv_source_get_height(mvSource, &height) !=
@@ -1042,6 +1025,10 @@ namespace inference
                        return MEDIA_VISION_ERROR_NOT_SUPPORTED_FORMAT;
                }
 
+               /* convert mv_source to cv::Mat */
+               cv::Mat cvSource;
+               cv::Rect cvRoi;
+
                if (roi == NULL) {
                        cvSource = cv::Mat(cv::Size(width, height), CV_MAKETYPE(CV_8U, 3),
                                                           buffer)
@@ -1209,7 +1196,7 @@ namespace inference
                                top_result_pq.push(std::pair<float, int>(value, i));
 
                                // If at capacity, kick the smallest value out.
-                               if (top_result_pq.size() > (size_t)mOutputNumbers) {
+                               if (top_result_pq.size() > static_cast<size_t>(mConfig.mMaxOutputNumbers)) {
                                        top_result_pq.pop();
                                }
                        }