test: Introduce GetModelString function
authorInki Dae <inki.dae@samsung.com>
Thu, 4 Feb 2021 04:49:04 +0000 (13:49 +0900)
committerInki Dae <inki.dae@samsung.com>
Thu, 25 Mar 2021 02:11:40 +0000 (11:11 +0900)
Added GetModelString function to avoid code duplication.

Converting a given model type to its corresponding string
was duplicated in several test cases. We can share the code
by introducing GetModelString function which returns
a string corresponding to a given test model type.

Change-Id: Iba325074aff6fa40ac5621b4c6b519a75774d3dc
Signed-off-by: Inki Dae <inki.dae@samsung.com>
test/src/inference_engine_profiler.cpp
test/src/inference_engine_test_common.cpp
test/src/inference_engine_test_common.h

index 41c83ec..0a4cb8f 100644 (file)
@@ -93,30 +93,8 @@ TEST_P(InferenceEngineTfliteTest, Inference)
                return;
        }
 
-       std::string test_name;
-       switch (test_type) {
-       case TEST_IMAGE_CLASSIFICATION:
-               test_name.append("Image classification");
-               break;
-       case TEST_OBJECT_DETECTION:
-               test_name.append("Object detection");
-               break;
-       case TEST_FACE_DETECTION:
-               test_name.append("Face detection");
-               break;
-       case TEST_FACIAL_LANDMARK_DETECTION:
-               test_name.append("Facial landmark detection");
-               break;
-       case TEST_POSE_ESTIMATION:
-               test_name.append("Pose estimation");
-               break;
-       case TEST_AIC_HAND_GESTURE_1:
-               test_name.append("AIC Hand Gesture detection 1");
-               break;
-       case TEST_AIC_HAND_GESTURE_2:
-               test_name.append("AIC Hand Gesture detection 2");
-               break;
-       }
+       std::string test_name = GetModelString(test_type);
+       ASSERT_NE(test_name, "");
 
        std::cout << test_name << " inference test : backend = " << backend_name
                          << ", target device = " << Target_Formats[target_devices]
@@ -295,30 +273,8 @@ TEST_P(InferenceEngineTfliteCLTunerTest, Inference)
                return;
        }
 
-       std::string test_name;
-       switch (test_type) {
-       case TEST_IMAGE_CLASSIFICATION:
-               test_name.append("Image classification");
-               break;
-       case TEST_OBJECT_DETECTION:
-               test_name.append("Object detection");
-               break;
-       case TEST_FACE_DETECTION:
-               test_name.append("Face detection");
-               break;
-       case TEST_FACIAL_LANDMARK_DETECTION:
-               test_name.append("Facial landmark detection");
-               break;
-       case TEST_POSE_ESTIMATION:
-               test_name.append("Pose estimation");
-               break;
-       case TEST_AIC_HAND_GESTURE_1:
-               test_name.append("AIC Hand Gesture detection 1");
-               break;
-       case TEST_AIC_HAND_GESTURE_2:
-               test_name.append("AIC Hand Gesture detection 2");
-               break;
-       }
+       std::string test_name = GetModelString(test_type);
+       ASSERT_NE(test_name, "");
 
        std::cout << test_name << " inference test : backend = " << backend_name
                          << ", target device = " << Target_Formats[target_devices]
@@ -502,24 +458,8 @@ TEST_P(InferenceEngineCaffeTest, Inference)
                return;
        }
 
-       std::string test_name;
-       switch (test_type) {
-       case TEST_IMAGE_CLASSIFICATION:
-               test_name.append("Image classification");
-               break;
-       case TEST_OBJECT_DETECTION:
-               test_name.append("Object detection");
-               break;
-       case TEST_FACE_DETECTION:
-               test_name.append("Face detection");
-               break;
-       case TEST_FACIAL_LANDMARK_DETECTION:
-               test_name.append("Facial landmark detection");
-               break;
-       case TEST_POSE_ESTIMATION:
-               test_name.append("Pose estimation");
-               break;
-       }
+       std::string test_name = GetModelString(test_type);
+       ASSERT_NE(test_name, "");
 
        std::cout << test_name << " inference test : backend = " << backend_name
                          << ", target device = " << Target_Formats[target_devices]
@@ -675,24 +615,8 @@ TEST_P(InferenceEngineDldtTest, Inference)
                return;
        }
 
-       std::string test_name;
-       switch (test_type) {
-       case TEST_IMAGE_CLASSIFICATION:
-               test_name.append("Image classification");
-               break;
-       case TEST_OBJECT_DETECTION:
-               test_name.append("Object detection");
-               break;
-       case TEST_FACE_DETECTION:
-               test_name.append("Face detection");
-               break;
-       case TEST_FACIAL_LANDMARK_DETECTION:
-               test_name.append("Facial landmark detection");
-               break;
-       case TEST_POSE_ESTIMATION:
-               test_name.append("Pose estimation");
-               break;
-       }
+       std::string test_name = GetModelString(test_type);
+       ASSERT_NE(test_name, "");
 
        std::cout << test_name << " inference test : backend = " << backend_name
                          << ", target device = " << Target_Formats[target_devices]
index e25f2a1..de97a74 100644 (file)
@@ -62,6 +62,17 @@ static std::map<std::string, int> Machine_Idx = {
        // TODO.
 };
 
+static const std::string sTestModelStr[TEST_MODEL_MAX] = {
+       "Image classification",
+       "Object detection",
+       "Face detection",
+       "AIC Hand Gesture detection 1",
+       "AIC Hand Gesture detection 2",
+       "Facial landmark detection",
+       "Pose estimation"
+       // TODO.
+};
+
 MachineCapacity *GetMachineCapacity(void)
 {
        std::ifstream readFile;
@@ -122,6 +133,14 @@ int GetModelInfo(std::vector<std::string> &model_paths,
        return ret;
 }
 
+std::string GetModelString(const int model_type)
+{
+       if (model_type <= TEST_MODEL_MIN || model_type >= TEST_MODEL_MAX)
+               return "";
+
+       return sTestModelStr[model_type];
+}
+
 int PrepareTensorBuffers(InferenceEngineCommon *engine,
                                                 std::vector<inference_engine_tensor_buffer> &inputs,
                                                 std::vector<inference_engine_tensor_buffer> &outputs)
index b95e164..bd49314 100644 (file)
@@ -39,13 +39,15 @@ enum {
 };
 
 enum {
-       TEST_IMAGE_CLASSIFICATION = 0,
+       TEST_MODEL_MIN = -1,
+       TEST_IMAGE_CLASSIFICATION,
        TEST_OBJECT_DETECTION,
        TEST_FACE_DETECTION,
        TEST_AIC_HAND_GESTURE_1,
        TEST_AIC_HAND_GESTURE_2,
        TEST_FACIAL_LANDMARK_DETECTION,
-       TEST_POSE_ESTIMATION
+       TEST_POSE_ESTIMATION,
+       TEST_MODEL_MAX
 };
 
 typedef struct _MachineCapacity {
@@ -60,6 +62,8 @@ MachineCapacity *GetMachineCapacity(void);
 int GetModelInfo(std::vector<std::string> &model_paths,
                                 std::vector<std::string> &models);
 
+std::string GetModelString(const int model_type);
+
 int PrepareTensorBuffers(InferenceEngineCommon *engine,
                                                 std::vector<inference_engine_tensor_buffer> &inputs,
                                                 std::vector<inference_engine_tensor_buffer> &outputs);