mv_machine_learning: code cleanup to Options and LayerInfo classes
authorInki Dae <inki.dae@samsung.com>
Tue, 30 Aug 2022 04:54:46 +0000 (13:54 +0900)
committerInki Dae <inki.dae@samsung.com>
Fri, 2 Sep 2022 08:09:25 +0000 (17:09 +0900)
[Issue type] : code cleanup

Cleaned up Options and LayerInfo classes by doing,
- Change Options and LayerInfo classes to structure type.
  No reason for they are class type. It's enough with structure type.

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

index c2bf94d..77a5c71 100644 (file)
@@ -35,54 +35,55 @@ namespace mediavision
 {
 namespace inference
 {
-       class Options
-       {
-       public:
-               class Normalization
-               {
-               public:
-                       bool use;
-                       std::vector<double> mean;
-                       std::vector<double> std;
-
-                       Normalization() : use(false) {}
-                       ~Normalization() = default;
-               };
-
-               class Quantization
-               {
-               public:
-                       bool use;
-                       std::vector<double> scale;
-                       std::vector<double> zeropoint;
-
-                       Quantization() : use(false) {};
-                       ~Quantization() = default;
-               };
 
+       struct Normalization {
+               bool use { false };
+               std::vector<double> mean;
+               std::vector<double> std;
+       };
+
+       struct Quantization {
+               bool use { false };
+               std::vector<double> scale;
+               std::vector<double> zeropoint;
+       };
+
+       struct Options {
                Normalization normalization;
                Quantization  quantization;
-
-               Options() = default;
-               ~Options() = default;
        };
 
-       class LayerInfo
+       struct LayerInfo
        {
-       public:
-
                std::string name;
                std::vector<int> dims;
-               mv_colorspace_e colorSpace;
-               mv_inference_data_type_e dataType;
-               inference_tensor_shape_type_e shapeType; // TODO: define mv_inference_shape_type_e
-
-               LayerInfo() = default;
-               ~LayerInfo() = default;
-
-               int GetWidth() const;
-               int GetHeight() const;
-               int GetChannel() const;
+               mv_colorspace_e colorSpace {};
+               mv_inference_data_type_e dataType {};
+               inference_tensor_shape_type_e shapeType {}; // TODO: define mv_inference_shape_type_e
+
+               int getWidth() const {
+                       if (shapeType == INFERENCE_TENSOR_SHAPE_NCHW) {
+                               return dims[3];
+                       } else { // INFERENCE_TENSOR_SHAPE_NHWC
+                               return dims[2];
+                       }
+               }
+
+               int getHeight() const {
+                       if (shapeType == INFERENCE_TENSOR_SHAPE_NCHW) {
+                               return dims[2];
+                       } else { // INFERENCE_TENSOR_SHAPE_NHWC
+                               return dims[1];
+                       }
+               }
+
+               int getChannel() const {
+                       if (shapeType == INFERENCE_TENSOR_SHAPE_NCHW) {
+                               return dims[1];
+                       } else { // INFERENCE_TENSOR_SHAPE_NHWC
+                               return dims[3];
+                       }
+               }
        };
 
        class InputMetadata
index 0e3123e..4f426c7 100755 (executable)
@@ -963,7 +963,11 @@ namespace inference
 
                        if (mMetadata.GetInputMeta().IsParsed()) {
                                const LayerInfo& layerInfo = mMetadata.GetInputMeta().GetLayer().at(buffer.first);
-                               const Options& opt = mMetadata.GetInputMeta().GetOption().empty() ? Options() : mMetadata.GetInputMeta().GetOption().at(buffer.first);
+                               Options opt;
+
+                               if (!mMetadata.GetInputMeta().GetOption().empty())
+                                       opt = mMetadata.GetInputMeta().GetOption().at(buffer.first);
+
                                mv_colorspace_e colorspace = MEDIA_VISION_COLORSPACE_INVALID;
 
                                mv_source_get_colorspace(mvSources[src_idx], &colorspace);
@@ -1183,8 +1187,8 @@ namespace inference
                        }
 
                        ObjectDecoder objDecoder(mOutputTensorBuffers, outputMeta, boxOffset,
-                                               static_cast<float>(mMetadata.GetInputMeta().GetLayer().begin()->second.GetWidth()),
-                                               static_cast<float>(mMetadata.GetInputMeta().GetLayer().begin()->second.GetHeight()),
+                                               static_cast<float>(mMetadata.GetInputMeta().GetLayer().begin()->second.getWidth()),
+                                               static_cast<float>(mMetadata.GetInputMeta().GetLayer().begin()->second.getHeight()),
                                                numberOfObjects);
 
                        objDecoder.init();
@@ -1340,8 +1344,8 @@ namespace inference
                        }
 
                        ObjectDecoder objDecoder(mOutputTensorBuffers, outputMeta, boxOffset,
-                                               static_cast<float>(mMetadata.GetInputMeta().GetLayer().begin()->second.GetWidth()),
-                                               static_cast<float>(mMetadata.GetInputMeta().GetLayer().begin()->second.GetHeight()),
+                                               static_cast<float>(mMetadata.GetInputMeta().GetLayer().begin()->second.getWidth()),
+                                               static_cast<float>(mMetadata.GetInputMeta().GetLayer().begin()->second.getHeight()),
                                                numberOfFaces);
 
                        objDecoder.init();
@@ -1497,8 +1501,8 @@ namespace inference
                        float inputH = 1.f;
 
                        if (outputMeta.GetLandmarkCoordinate() == INFERENCE_LANDMARK_COORDINATE_TYPE_PIXEL) {
-                               inputW = static_cast<float>(mMetadata.GetInputMeta().GetLayer().begin()->second.GetWidth());
-                               inputH = static_cast<float>(mMetadata.GetInputMeta().GetLayer().begin()->second.GetHeight());
+                               inputW = static_cast<float>(mMetadata.GetInputMeta().GetLayer().begin()->second.getWidth());
+                               inputH = static_cast<float>(mMetadata.GetInputMeta().GetLayer().begin()->second.getHeight());
                        }
 
                        float thresRadius = outputMeta.GetLandmarkType() == INFERENCE_LANDMARK_TYPE_2D_SINGLE ? 0.0 :
@@ -1615,8 +1619,8 @@ namespace inference
                        float thresRadius = outputMeta.GetLandmarkType() == INFERENCE_LANDMARK_TYPE_2D_SINGLE ? 0.0 :
                                                                                                                outputMeta.GetLandmarkHeatMapInfo().nmsRadius;
                        if (outputMeta.GetLandmarkCoordinate() == INFERENCE_LANDMARK_COORDINATE_TYPE_PIXEL) {
-                               inputW = static_cast<float>(mMetadata.GetInputMeta().GetLayer().begin()->second.GetWidth());
-                               inputH = static_cast<float>(mMetadata.GetInputMeta().GetLayer().begin()->second.GetHeight());
+                               inputW = static_cast<float>(mMetadata.GetInputMeta().GetLayer().begin()->second.getWidth());
+                               inputH = static_cast<float>(mMetadata.GetInputMeta().GetLayer().begin()->second.getHeight());
                        }
 
                        poseDecoder.decode(inputW, inputH, thresRadius);
index 2ca878d..22b8383 100644 (file)
@@ -119,6 +119,7 @@ namespace inference
                // TODO: handling error
                for (unsigned int elem = 0; elem < elements; ++elem, ++iterLayer) {
                        Options opt;
+
                        JsonNode *pNode = json_array_get_element(rootArray, elem);
                        JsonObject *pObject = json_node_get_object(pNode);
 
@@ -204,29 +205,5 @@ namespace inference
                return MEDIA_VISION_ERROR_NONE;
        }
 
-       int LayerInfo::GetWidth() const {
-               if (shapeType == INFERENCE_TENSOR_SHAPE_NCHW) {
-                       return dims[3];
-               } else { // INFERENCE_TENSOR_SHAPE_NHWC
-                       return dims[2];
-               }
-       }
-
-       int LayerInfo::GetHeight() const {
-               if (shapeType == INFERENCE_TENSOR_SHAPE_NCHW) {
-                       return dims[2];
-               } else { // INFERENCE_TENSOR_SHAPE_NHWC
-                       return dims[1];
-               }
-       }
-
-       int LayerInfo::GetChannel() const {
-               if (shapeType == INFERENCE_TENSOR_SHAPE_NCHW) {
-                       return dims[1];
-               } else { // INFERENCE_TENSOR_SHAPE_NHWC
-                       return dims[3];
-               }
-       }
-
 } /* Inference */
 } /* MediaVision */
index 6d79586..0529124 100644 (file)
@@ -124,7 +124,7 @@ namespace inference
                LOGI("ENTER");
 
                // dest is a wrapper of the buffer
-               cv::Mat dest(cv::Size(layerInfo.GetWidth(), layerInfo.GetHeight()),
+               cv::Mat dest(cv::Size(layerInfo.getWidth(), layerInfo.getHeight()),
                                        dataType, buffer);
 
                cv::Mat cvSource, cvDest;