test/machine_learning: add snpe model support 41/268641/1
authorInki Dae <inki.dae@samsung.com>
Tue, 28 Dec 2021 10:31:33 +0000 (19:31 +0900)
committerInki Dae <inki.dae@samsung.com>
Tue, 28 Dec 2021 10:31:33 +0000 (19:31 +0900)
[Version] : 0.10.0-0
[Issue type] : new feature

Added a test case for SNPE engnie with dlc model.

Change-Id: I7d20f9974300130ddeaf4e8eb77482d89dee0b9d
Signed-off-by: Inki Dae <inki.dae@samsung.com>
packaging/capi-media-vision.spec
test/testsuites/machine_learning/inference/test_face_detection.cpp
test/testsuites/machine_learning/inference/test_image_classification.cpp
test/testsuites/machine_learning/inference/test_inference_helper.cpp
test/testsuites/machine_learning/inference/test_inference_helper.hpp
test/testsuites/machine_learning/inference/test_pose_landmark_detection.cpp

index 1af9b655bb55cb91f00dcea87641b76d395e8508..00147d81850abd39a8f751c2629f6ede118c8836 100644 (file)
@@ -1,6 +1,6 @@
 Name:        capi-media-vision
 Summary:     Media Vision library for Tizen Native API
-Version:     0.9.0
+Version:     0.10.0
 Release:     0
 Group:       Multimedia/Framework
 License:     Apache-2.0 and BSD-3-Clause
index 376a7173f392dbbc439a441b432e4618004bbd7c..59a357fc8205e2d3945eaffa98548a39b310e6db 100644 (file)
@@ -40,7 +40,7 @@ public:
 
 TEST_P(TestFaceDetection, CPU_TFLITE_MobilenetV1_SSD)
 {
-       engine_config_hosted_cpu_tflite(engine_cfg,
+       engine_config_hosted_model_config(engine_cfg,
                                                                        FD_TFLITE_WEIGHT_MOBILENET_V1_SSD_300_PATH, _use_json_parser);
        if (!_use_json_parser) {
                const char *inputNodeName = "normalized_input_image_tensor";
index cdda3f63051599f9a18e484fa7f696a74871bb19..103f6df13530a6862114b803925ee1f67d7b1b37 100644 (file)
        MV_CONFIG_PATH                                   \
        "/models/IC/tflite/quant_mobilenet_v1_224x224.tflite"
 
+#define IC_LABEL_INCEPTION_V3_299_PATH \
+       MV_CONFIG_PATH                     \
+       "/models/IC_Q/snpe/imagenet_slim_labels.txt"
+#define IC_SNPE_WEIGHT_QUANT_INCEPTION_V3_299_PATH \
+       MV_CONFIG_PATH                                   \
+       "/models/IC_Q/snpe/inception_v3_quantized.dlc"
+
 void _image_classified_cb(mv_source_h source, const int number_of_classes,
                                                  const int *indices, const char **names,
                                                  const float *confidences, void *user_data)
@@ -286,6 +293,40 @@ TEST_P(TestImageClassification, CPU_TFLITE_QUANT_MobilenetV1)
        inferenceBanana();
 }
 
+TEST_P(TestImageClassification, SNPE_InceptionV3_Quantized)
+{
+       engine_config_hosted_cpu_snpe_user_model(
+                       engine_cfg, IC_SNPE_WEIGHT_QUANT_INCEPTION_V3_299_PATH,
+                       IC_LABEL_INCEPTION_V3_299_PATH,
+                       _use_json_parser);
+
+       if (!_use_json_parser) {
+               const char *inputNodeName = "input";
+               const char *outputNodeName[] = { "output" };
+
+               ASSERT_EQ(mv_engine_config_set_int_attribute(engine_cfg, MV_INFERENCE_INPUT_DATA_TYPE, MV_INFERENCE_DATA_UINT8),
+                                       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_double_attribute(engine_cfg, MV_INFERENCE_CONFIDENCE_THRESHOLD, 0.0),
+                                       MEDIA_VISION_ERROR_NONE);
+               ASSERT_EQ(mv_engine_config_set_int_attribute(engine_cfg, MV_INFERENCE_INPUT_TENSOR_WIDTH, 299),
+                                       MEDIA_VISION_ERROR_NONE);
+               ASSERT_EQ(mv_engine_config_set_int_attribute(engine_cfg, MV_INFERENCE_INPUT_TENSOR_HEIGHT, 299),
+                                       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);
+       }
+
+       inferenceBanana();
+}
+
 INSTANTIATE_TEST_CASE_P(Prefix, TestImageClassification,
                                                ::testing::Values(
                                                        ParamTypeOne(false),
index 81a0380b90dc8c8650369fb221d3bd8be3e1af65..9d5c95b9151668f34ee5f909b63ab118d2bdb273 100644 (file)
@@ -15,7 +15,7 @@ TestInference::~TestInference()
        EXPECT_EQ(mv_destroy_engine_config(engine_cfg), MEDIA_VISION_ERROR_NONE);
 }
 
-void engine_config_hosted_cpu_tflite(mv_engine_config_h handle,
+void engine_config_hosted_model_config(mv_engine_config_h handle,
                                                                         const char *tf_weight,
                                                                         const bool use_json_parser)
 {
@@ -32,6 +32,14 @@ void engine_config_hosted_cpu_tflite(mv_engine_config_h handle,
                                                handle, MV_INFERENCE_MODEL_META_FILE_PATH , meta_file_path.c_str()),
                                MEDIA_VISION_ERROR_NONE);
        }
+}
+
+void engine_config_hosted_cpu_tflite_user_model(mv_engine_config_h handle,
+                                                                                               const char *tf_weight,
+                                                                                               const char *user_file,
+                                                                                               const bool use_json_parser)
+{
+       engine_config_hosted_model_config(handle, tf_weight, use_json_parser);
 
        EXPECT_EQ(mv_engine_config_set_int_attribute(handle,
                                                                                                 MV_INFERENCE_BACKEND_TYPE,
@@ -41,14 +49,28 @@ void engine_config_hosted_cpu_tflite(mv_engine_config_h handle,
                                                                                                 MV_INFERENCE_TARGET_TYPE,
                                                                                                 MV_INFERENCE_TARGET_CPU),
                          MEDIA_VISION_ERROR_NONE);
+
+       EXPECT_EQ(mv_engine_config_set_string_attribute(
+                                         handle, MV_INFERENCE_MODEL_USER_FILE_PATH, user_file),
+                         MEDIA_VISION_ERROR_NONE);
 }
 
-void engine_config_hosted_cpu_tflite_user_model(mv_engine_config_h handle,
+void engine_config_hosted_cpu_snpe_user_model(mv_engine_config_h handle,
                                                                                                const char *tf_weight,
                                                                                                const char *user_file,
                                                                                                const bool use_json_parser)
 {
-       engine_config_hosted_cpu_tflite(handle, tf_weight, use_json_parser);
+       engine_config_hosted_model_config(handle, tf_weight, use_json_parser);
+
+       EXPECT_EQ(mv_engine_config_set_int_attribute(handle,
+                                                                                                MV_INFERENCE_BACKEND_TYPE,
+                                                                                                MV_INFERENCE_BACKEND_SNPE),
+                         MEDIA_VISION_ERROR_NONE);
+       EXPECT_EQ(mv_engine_config_set_int_attribute(handle,
+                                                                                                MV_INFERENCE_TARGET_TYPE,
+                                                                                                MV_INFERENCE_TARGET_CPU),
+                         MEDIA_VISION_ERROR_NONE);
+
        EXPECT_EQ(mv_engine_config_set_string_attribute(
                                          handle, MV_INFERENCE_MODEL_USER_FILE_PATH, user_file),
                          MEDIA_VISION_ERROR_NONE);
index a04fb000090bce007bc4ee0702d0b9ecbf4d7162..3023d81cfdc114e3734903acd8eebd09963e1e5e 100644 (file)
@@ -23,7 +23,7 @@ public:
        mv_source_h mv_source;
 };
 
-void engine_config_hosted_cpu_tflite(mv_engine_config_h handle,
+void engine_config_hosted_model_config(mv_engine_config_h handle,
                                                                         const char *tf_weight,
                                                                         const bool use_json_parser);
 
@@ -32,4 +32,9 @@ void engine_config_hosted_cpu_tflite_user_model(mv_engine_config_h handle,
                                                                                                const char *user_file,
                                                                                                const bool use_json_parser);
 
+void engine_config_hosted_cpu_snpe_user_model(mv_engine_config_h handle,
+                                                                                               const char *tf_weight,
+                                                                                               const char *user_file,
+                                                                                               const bool use_json_parser);
+
 #endif //__TEST_INFERENCE_HELPER_HPP__
index 58c4b43a6dba91aa131fc8a9a8e8c26ba2166f49..623903a9ecb44b4a68524ff5ce764553ea670dbe 100644 (file)
@@ -39,7 +39,7 @@ public:
 
 TEST_P(TestPoseLandmarkDetection, CPU_TFLITE_MobilenetV1)
 {
-       engine_config_hosted_cpu_tflite(
+       engine_config_hosted_model_config(
                        engine_cfg, PLD_TFLITE_WEIGHT_MOBILENET_V1_POSENET_257_PATH, _use_json_parser);
 
        if (!_use_json_parser) {