From 1cae83e2c74cefc4e5fe1cb2bd88ad984e67c39a Mon Sep 17 00:00:00 2001 From: Inki Dae Date: Tue, 28 Dec 2021 19:31:33 +0900 Subject: [PATCH] test/machine_learning: add snpe model support [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 --- packaging/capi-media-vision.spec | 2 +- .../inference/test_face_detection.cpp | 2 +- .../inference/test_image_classification.cpp | 41 ++++++++++++++++++++++ .../inference/test_inference_helper.cpp | 28 +++++++++++++-- .../inference/test_inference_helper.hpp | 7 +++- .../inference/test_pose_landmark_detection.cpp | 2 +- 6 files changed, 75 insertions(+), 7 deletions(-) diff --git a/packaging/capi-media-vision.spec b/packaging/capi-media-vision.spec index 1af9b65..00147d8 100644 --- a/packaging/capi-media-vision.spec +++ b/packaging/capi-media-vision.spec @@ -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 diff --git a/test/testsuites/machine_learning/inference/test_face_detection.cpp b/test/testsuites/machine_learning/inference/test_face_detection.cpp index 376a717..59a357f 100644 --- a/test/testsuites/machine_learning/inference/test_face_detection.cpp +++ b/test/testsuites/machine_learning/inference/test_face_detection.cpp @@ -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"; diff --git a/test/testsuites/machine_learning/inference/test_image_classification.cpp b/test/testsuites/machine_learning/inference/test_image_classification.cpp index cdda3f6..103f6df 100644 --- a/test/testsuites/machine_learning/inference/test_image_classification.cpp +++ b/test/testsuites/machine_learning/inference/test_image_classification.cpp @@ -31,6 +31,13 @@ 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), diff --git a/test/testsuites/machine_learning/inference/test_inference_helper.cpp b/test/testsuites/machine_learning/inference/test_inference_helper.cpp index 81a0380..9d5c95b 100644 --- a/test/testsuites/machine_learning/inference/test_inference_helper.cpp +++ b/test/testsuites/machine_learning/inference/test_inference_helper.cpp @@ -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); diff --git a/test/testsuites/machine_learning/inference/test_inference_helper.hpp b/test/testsuites/machine_learning/inference/test_inference_helper.hpp index a04fb00..3023d81 100644 --- a/test/testsuites/machine_learning/inference/test_inference_helper.hpp +++ b/test/testsuites/machine_learning/inference/test_inference_helper.hpp @@ -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__ diff --git a/test/testsuites/machine_learning/inference/test_pose_landmark_detection.cpp b/test/testsuites/machine_learning/inference/test_pose_landmark_detection.cpp index 58c4b43..623903a 100644 --- a/test/testsuites/machine_learning/inference/test_pose_landmark_detection.cpp +++ b/test/testsuites/machine_learning/inference/test_pose_landmark_detection.cpp @@ -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) { -- 2.7.4