test: Add TestFaceLandmarkDetection 40/264240/2
authorKwang Son <k.son@samsung.com>
Wed, 15 Sep 2021 01:29:16 +0000 (21:29 -0400)
committerkwang son <k.son@samsung.com>
Thu, 16 Sep 2021 03:24:49 +0000 (03:24 +0000)
Change-Id: Ia54e4183c0a50044441b96fb991abe19741f8b3a
Signed-off-by: Kwang Son <k.son@samsung.com>
test/CMakeLists.txt
test/testsuites/machine_learning/inference/test_face_landmark_detection.cpp [new file with mode: 0644]

index 9a33829..ae209ce 100644 (file)
@@ -10,6 +10,7 @@ add_executable(${PROJECT_NAME}
     testsuites/machine_learning/inference/test_image_classification.cpp
     testsuites/machine_learning/inference/test_object_detection.cpp
     testsuites/machine_learning/inference/test_face_detection.cpp
+    testsuites/machine_learning/inference/test_face_landmark_detection.cpp
 )
 target_link_libraries(${PROJECT_NAME} gtest gtest_main mv_inference mv_image_helper mv_barcode_detector)
 install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR})
\ No newline at end of file
diff --git a/test/testsuites/machine_learning/inference/test_face_landmark_detection.cpp b/test/testsuites/machine_learning/inference/test_face_landmark_detection.cpp
new file mode 100644 (file)
index 0000000..6d4ada9
--- /dev/null
@@ -0,0 +1,88 @@
+#include <gtest/gtest.h>
+#include <ImageHelper.h>
+#include "test_inference_helper.hpp"
+
+#define FLD_OPENCV_WEIGHT_CAFFE_PATH \
+       MV_CONFIG_PATH                   \
+       "/models/FLD/caffe/fld_caffe_model_tweak.caffemodel"
+#define FLD_OPENCV_CONFIG_CAFFE_PATH \
+       MV_CONFIG_PATH                   \
+       "models/FLD/caffe/fld_caffe_model_tweak.prototxt"
+#define IMG_FACE_LANDMARK \
+       MV_CONFIG_PATH        \
+       "/res/inference/images/faceLandmark.jpg"
+
+void _facial_landmark_detected_cb(mv_source_h source,
+                                                                 const int number_of_landmarks,
+                                                                 const mv_point_s *locations, void *user_data)
+{
+       EXPECT_GT(number_of_landmarks, 0);
+}
+
+class TestFaceLandmarkDetection : public TestInference
+{
+public:
+       void inferenceFaceLandmark()
+       {
+               ASSERT_EQ(mv_inference_configure(infer, engine_cfg),
+                                 MEDIA_VISION_ERROR_NONE);
+               ASSERT_EQ(mv_inference_prepare(infer), MEDIA_VISION_ERROR_NONE);
+               ASSERT_EQ(MediaVision::Common::ImageHelper::loadImageToSource(
+                                                 IMG_FACE_LANDMARK, mv_source),
+                                 MEDIA_VISION_ERROR_NONE);
+               ASSERT_EQ(mv_inference_facial_landmark_detect(
+                                                 mv_source, infer, NULL, _facial_landmark_detected_cb,
+                                                 NULL),
+                                 MEDIA_VISION_ERROR_NONE);
+       }
+};
+
+TEST_F(TestFaceLandmarkDetection, CPU_OPENCV_CAFFE_CNNCASCADE)
+{
+       const char *inputNodeName = "data";
+       const char *outputNodeName[] = { "Sigmoid_fc2" };
+
+       ASSERT_EQ(mv_engine_config_set_string_attribute(
+                                         engine_cfg, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH,
+                                         FLD_OPENCV_WEIGHT_CAFFE_PATH),
+                         MEDIA_VISION_ERROR_NONE);
+       ASSERT_EQ(mv_engine_config_set_int_attribute(engine_cfg,
+                                                                                                MV_INFERENCE_INPUT_DATA_TYPE,
+                                                                                                MV_INFERENCE_DATA_FLOAT32),
+                         MEDIA_VISION_ERROR_NONE);
+       ASSERT_EQ(mv_engine_config_set_string_attribute(
+                                         engine_cfg, MV_INFERENCE_MODEL_CONFIGURATION_FILE_PATH,
+                                         FLD_OPENCV_CONFIG_CAFFE_PATH),
+                         MEDIA_VISION_ERROR_NONE);
+       ASSERT_EQ(mv_engine_config_set_double_attribute(
+                                         engine_cfg, MV_INFERENCE_MODEL_MEAN_VALUE, 127.5),
+                         MEDIA_VISION_ERROR_NONE);
+       ASSERT_EQ(mv_engine_config_set_double_attribute(
+                                         engine_cfg, MV_INFERENCE_MODEL_STD_VALUE, 127.5),
+                         MEDIA_VISION_ERROR_NONE);
+       ASSERT_EQ(mv_engine_config_set_int_attribute(engine_cfg,
+                                                                                                MV_INFERENCE_BACKEND_TYPE,
+                                                                                                MV_INFERENCE_BACKEND_OPENCV),
+                         MEDIA_VISION_ERROR_NONE);
+       ASSERT_EQ(mv_engine_config_set_int_attribute(engine_cfg,
+                                                                                                MV_INFERENCE_TARGET_TYPE,
+                                                                                                MV_INFERENCE_TARGET_CPU),
+                         MEDIA_VISION_ERROR_NONE);
+       ASSERT_EQ(mv_engine_config_set_int_attribute(
+                                         engine_cfg, MV_INFERENCE_INPUT_TENSOR_WIDTH, 128),
+                         MEDIA_VISION_ERROR_NONE);
+       ASSERT_EQ(mv_engine_config_set_int_attribute(
+                                         engine_cfg, MV_INFERENCE_INPUT_TENSOR_HEIGHT, 128),
+                         MEDIA_VISION_ERROR_NONE);
+       ASSERT_EQ(mv_engine_config_set_int_attribute(
+                                         engine_cfg, MV_INFERENCE_INPUT_TENSOR_CHANNELS, 3),
+                         MEDIA_VISION_ERROR_NONE);
+       ASSERT_EQ(mv_engine_config_set_string_attribute(
+                                         engine_cfg, MV_INFERENCE_INPUT_NODE_NAME, inputNodeName),
+                         MEDIA_VISION_ERROR_NONE);
+       ASSERT_EQ(mv_engine_config_set_array_string_attribute(
+                                         engine_cfg, MV_INFERENCE_OUTPUT_NODE_NAMES,
+                                         outputNodeName, 1),
+                         MEDIA_VISION_ERROR_NONE);
+       inferenceFaceLandmark();
+}
\ No newline at end of file