From 0a7ab1f50e641c4937d2ca87ab0950067688860b Mon Sep 17 00:00:00 2001 From: Kwang Son Date: Mon, 2 Aug 2021 03:37:46 -0400 Subject: [PATCH 01/16] test: Seperate resource allocation perform_pose_landmark_detection alloactate mv_source, mv_engine, mv_infer in a function so makes hard to deallocate resource and error handling. Change-Id: I80df947730b734e9cb4f95bc238d66cccbe0ca7d Signed-off-by: Kwang Son --- .../inference/inference_test_suite.c | 559 ++++++++------------- 1 file changed, 212 insertions(+), 347 deletions(-) diff --git a/test/testsuites/machine_learning/inference/inference_test_suite.c b/test/testsuites/machine_learning/inference/inference_test_suite.c index 5053cea..e2df147 100644 --- a/test/testsuites/machine_learning/inference/inference_test_suite.c +++ b/test/testsuites/machine_learning/inference/inference_test_suite.c @@ -194,6 +194,12 @@ #define PLD_TFLITE_WEIGHT_INT8_MOVENET_PATH \ "/usr/share/capi-media-vision/models/PLD/tflite/pld_int8_movenet.tflite" +#define TASK_IC 0 +#define TASK_OD 1 +#define TASK_FD 2 +#define TASK_FLD 3 +#define TASK_PLD 4 + /****** * Public model: * IC: mobilenet caffe, tf? @@ -332,6 +338,113 @@ void _image_classified_cb(mv_source_h source, const int number_of_classes, } } +int infer_task_with_img(char *img_file_name, mv_inference_h infer, int task_id) +{ + mv_source_h mvSource = NULL; + struct timespec s_tspec; + struct timespec e_tspec; + + int err = mv_create_source(&mvSource); + if (err != MEDIA_VISION_ERROR_NONE) { + printf("Fail to create mvSource.\n"); + return err; + } + + err = load_mv_source_from_file(img_file_name, mvSource); + if (err != MEDIA_VISION_ERROR_NONE) { + printf("Fail to load mvSource err: %d.\n", err); + return err; + } + + clock_gettime(CLOCK_MONOTONIC, &s_tspec); + + switch (task_id) { + case TASK_IC: + err = mv_inference_image_classify(mvSource, infer, NULL, + _image_classified_cb, NULL); + break; + case TASK_OD: + err = mv_inference_object_detect(mvSource, infer, _object_detected_cb, + NULL); + break; + case TASK_FD: + err = mv_inference_face_detect(mvSource, infer, _face_detected_cb, + NULL); + break; + case TASK_FLD: + err = mv_inference_facial_landmark_detect( + mvSource, infer, NULL, _facial_landmark_detected_cb, NULL); + break; + case TASK_PLD: + err = mv_inference_pose_landmark_detect( + mvSource, infer, NULL, _pose_landmark_detected_cb, NULL); + break; + default: + err = MEDIA_VISION_ERROR_INVALID_PARAMETER; + break; + } + if (err != MEDIA_VISION_ERROR_NONE) + printf("Fail to infer task [err:%i]\n", err); + + clock_gettime(CLOCK_MONOTONIC, &e_tspec); + struct timespec diffspec = diff(s_tspec, e_tspec); + unsigned long timeDiff = gettotalmillisec(diffspec); + printf("elapsed time : %lu(ms)\n", timeDiff); + + err = mv_destroy_source(mvSource); + if (err != MEDIA_VISION_ERROR_NONE) + printf("Fail to destroy mvSource [err:%i]\n", err); + + return err; +} + +int infer_task(mv_inference_h infer, int task_id) +{ + char *in_file_name = NULL; + /* Load media source */ + while (input_string("Input file name to be inferred:", 1024, + &(in_file_name)) == -1) + printf("Incorrect input! Try again.\n"); + + int err = infer_task_with_img(in_file_name, infer, task_id); + free(in_file_name); + return err; +} + +int mv_inference_task_helper(mv_engine_config_h engine_cfg, int task_id) +{ + mv_inference_h infer = NULL; + + int err = mv_inference_create(&infer); + if (err != MEDIA_VISION_ERROR_NONE) { + printf("Fail to create inference handle [err:%i]\n", err); + return err; + } + + err = mv_inference_configure(infer, engine_cfg); + if (err != MEDIA_VISION_ERROR_NONE) { + printf("Fail to configure inference handle [err:%i]\n", err); + goto clean_mv_inference; + } + + err = mv_inference_prepare(infer); + if (err != MEDIA_VISION_ERROR_NONE) { + printf("Fail to prepare inference handle"); + goto clean_mv_inference; + } + + err = infer_task(infer, task_id); + if (err != MEDIA_VISION_ERROR_NONE) { + printf("Fail to infer task"); + } + +clean_mv_inference: + err = mv_inference_destroy(infer); + if (err != MEDIA_VISION_ERROR_NONE) + printf("Fail to destroy inference handle [err:%i]\n", err); + return err; +} + int perform_configure_set_model_config_path(mv_engine_config_h engine_cfg) { int err = MEDIA_VISION_ERROR_NONE; @@ -3172,398 +3285,150 @@ int perform_facial_landmark_detection() return MEDIA_VISION_ERROR_NONE; } -int perform_armnn_cpm_config(mv_engine_config_h *engine_cfg) +int engine_config_hosted_tflite_cpu(mv_engine_config_h handle, + const char *tf_weight) { - int err = MEDIA_VISION_ERROR_NONE; - - mv_engine_config_h handle = NULL; - err = mv_create_engine_config(&handle); + int err = mv_engine_config_set_string_attribute( + handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH, tf_weight); if (err != MEDIA_VISION_ERROR_NONE) { - printf("Fail to create engine configuration handle.\n"); - if (handle) { - int err2 = mv_destroy_engine_config(handle); - if (err2 != MEDIA_VISION_ERROR_NONE) { - printf("Fail to destroy engine configuration.\n"); - } - } return err; } - const char *inputNodeName = "image"; - const char *outputNodeName[] = { "Convolutional_Pose_Machine/stage_5_out" }; - - mv_engine_config_set_string_attribute( - handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH, PLD_TFLITE_WEIGHT_PATH); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_DATA_TYPE, - MV_INFERENCE_DATA_FLOAT32); - - mv_engine_config_set_string_attribute( - handle, MV_INFERENCE_MODEL_USER_FILE_PATH, PLD_POSE_LABEL_PATH); - - mv_engine_config_set_double_attribute(handle, MV_INFERENCE_MODEL_MEAN_VALUE, - 0.0); - - mv_engine_config_set_double_attribute(handle, MV_INFERENCE_MODEL_STD_VALUE, - 1.0); - - mv_engine_config_set_double_attribute( - handle, MV_INFERENCE_CONFIDENCE_THRESHOLD, 0.3); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_BACKEND_TYPE, - MV_INFERENCE_BACKEND_TFLITE); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_TARGET_TYPE, - MV_INFERENCE_TARGET_CPU); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_TENSOR_WIDTH, - 192); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_TENSOR_HEIGHT, - 192); - - mv_engine_config_set_int_attribute(handle, - MV_INFERENCE_INPUT_TENSOR_CHANNELS, 3); - - mv_engine_config_set_string_attribute(handle, MV_INFERENCE_INPUT_NODE_NAME, - inputNodeName); - - mv_engine_config_set_array_string_attribute( - handle, MV_INFERENCE_OUTPUT_NODE_NAMES, outputNodeName, 1); - - *engine_cfg = handle; - return err; -} - -int perform_hosted_tflite_cpm_192_config(mv_engine_config_h *engine_cfg) -{ - int err = MEDIA_VISION_ERROR_NONE; - - mv_engine_config_h handle = NULL; - err = mv_create_engine_config(&handle); + err = mv_engine_config_set_int_attribute(handle, MV_INFERENCE_BACKEND_TYPE, + MV_INFERENCE_BACKEND_TFLITE); if (err != MEDIA_VISION_ERROR_NONE) { - printf("Fail to create engine configuration handle.\n"); - if (handle) { - int err2 = mv_destroy_engine_config(handle); - if (err2 != MEDIA_VISION_ERROR_NONE) { - printf("Fail to destroy engine configuration.\n"); - } - } return err; } - mv_engine_config_set_string_attribute( - handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH, - PLD_TFLITE_WEIGHT_CPM_192_PATH); - - mv_engine_config_set_int_attribute( - handle, MV_INFERENCE_BACKEND_TYPE, - MV_INFERENCE_BACKEND_TFLITE); - - mv_engine_config_set_int_attribute( - handle, MV_INFERENCE_TARGET_TYPE, - MV_INFERENCE_TARGET_CPU); - - *engine_cfg = handle; + err = mv_engine_config_set_int_attribute(handle, MV_INFERENCE_TARGET_TYPE, + MV_INFERENCE_TARGET_CPU); return err; } -int perform_hosted_tflite_mobilenet_v1_posenet_257_config(mv_engine_config_h *engine_cfg) +int perform_armnn_cpm_config(mv_engine_config_h handle) { - int err = MEDIA_VISION_ERROR_NONE; + const char *inputNodeName = "image"; + const char *outputNodeName[] = { "Convolutional_Pose_Machine/stage_5_out" }; - mv_engine_config_h handle = NULL; - err = mv_create_engine_config(&handle); + int err = engine_config_hosted_tflite_cpu(handle, PLD_TFLITE_WEIGHT_PATH); if (err != MEDIA_VISION_ERROR_NONE) { - printf("Fail to create engine configuration handle.\n"); - if (handle) { - int err2 = mv_destroy_engine_config(handle); - if (err2 != MEDIA_VISION_ERROR_NONE) { - printf("Fail to destroy engine configuration.\n"); - } - } return err; } - mv_engine_config_set_string_attribute( - handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH, - PLD_TFLITE_WEIGHT_MOBILENET_V1_POSENET_257_PATH); + err = mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_INPUT_DATA_TYPE, MV_INFERENCE_DATA_FLOAT32); + if (err != MEDIA_VISION_ERROR_NONE) { + return err; + } -/* - mv_engine_config_set_string_attribute( - handle, MV_INFERENCE_MODEL_USER_FILE_PATH, - PLD_LABEL_MOBILENET_V1_POSENET_257_PATH); -*/ - mv_engine_config_set_int_attribute( - handle, MV_INFERENCE_BACKEND_TYPE, - MV_INFERENCE_BACKEND_TFLITE); + err = mv_engine_config_set_string_attribute( + handle, MV_INFERENCE_MODEL_USER_FILE_PATH, PLD_POSE_LABEL_PATH); + if (err != MEDIA_VISION_ERROR_NONE) { + return err; + } - mv_engine_config_set_int_attribute( - handle, MV_INFERENCE_TARGET_TYPE, - MV_INFERENCE_TARGET_CPU); + err = mv_engine_config_set_double_attribute( + handle, MV_INFERENCE_MODEL_MEAN_VALUE, 0.0); + if (err != MEDIA_VISION_ERROR_NONE) { + return err; + } - *engine_cfg = handle; - return err; -} + err = mv_engine_config_set_double_attribute( + handle, MV_INFERENCE_MODEL_STD_VALUE, 1.0); + if (err != MEDIA_VISION_ERROR_NONE) { + return err; + } -int perform_hosted_tflite_int8_movenet(mv_engine_config_h *engine_cfg) -{ - int err = MEDIA_VISION_ERROR_NONE; + err = mv_engine_config_set_double_attribute( + handle, MV_INFERENCE_CONFIDENCE_THRESHOLD, 0.3); + if (err != MEDIA_VISION_ERROR_NONE) { + return err; + } - mv_engine_config_h handle = NULL; - err = mv_create_engine_config(&handle); + err = mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_INPUT_TENSOR_WIDTH, 192); if (err != MEDIA_VISION_ERROR_NONE) { - printf("Fail to create engine configuration handle.\n"); - if (handle) { - int err2 = mv_destroy_engine_config(handle); - if (err2 != MEDIA_VISION_ERROR_NONE) { - printf("Fail to destroy engine configuration.\n"); - } - } return err; } - mv_engine_config_set_string_attribute( - handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH, - PLD_TFLITE_WEIGHT_INT8_MOVENET_PATH); + err = mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_INPUT_TENSOR_HEIGHT, 192); + if (err != MEDIA_VISION_ERROR_NONE) { + return err; + } - mv_engine_config_set_int_attribute( - handle, MV_INFERENCE_BACKEND_TYPE, - MV_INFERENCE_BACKEND_TFLITE); + err = mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_INPUT_TENSOR_CHANNELS, 3); + if (err != MEDIA_VISION_ERROR_NONE) { + return err; + } - mv_engine_config_set_int_attribute( - handle, MV_INFERENCE_TARGET_TYPE, - MV_INFERENCE_TARGET_CPU); + err = mv_engine_config_set_string_attribute( + handle, MV_INFERENCE_INPUT_NODE_NAME, inputNodeName); + if (err != MEDIA_VISION_ERROR_NONE) { + return err; + } - *engine_cfg = handle; + err = mv_engine_config_set_array_string_attribute( + handle, MV_INFERENCE_OUTPUT_NODE_NAMES, outputNodeName, 1); return err; } int perform_pose_landmark_detection() { int err = MEDIA_VISION_ERROR_NONE; - - int sel_opt = 0; - const char *names[] = { "Configuration", - "TFLITE(CPU) + CPM", - "Hosted: TFLITE(CPU) + CPM", - "Hosted: TFLITE(CPU) + MOBILENET_V1_POSENET", - "Hosted: TFLITE(CPU) + INT8_MOVENET", - "Prepare", - "Run", - "Back" }; - mv_engine_config_h engine_cfg = NULL; - mv_inference_h infer = NULL; - mv_source_h mvSource = NULL; + const char *names[] = { + "TFLITE(CPU) + CPM", + "Hosted: TFLITE(CPU) + CPM", + "Hosted: TFLITE(CPU) + MOBILENET_V1_POSENET", + "Hosted: TFLITE(CPU) + INT8_MOVENET", + }; - while (sel_opt == 0) { - sel_opt = show_menu_linear("Select Action:", names, ARRAY_SIZE(names)); - switch (sel_opt) { - case 1: { - //perform configuration - if (engine_cfg) { - int err2 = mv_destroy_engine_config(engine_cfg); - if (err2 != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy engine_cfg [err:%i]\n", err2); - engine_cfg = NULL; - } - - err = perform_configuration(&engine_cfg); - } break; - case 2: { - //perform TweakCNN config - if (engine_cfg) { - int err2 = mv_destroy_engine_config(engine_cfg); - if (err2 != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy engine_cfg [err:%i]\n", err2); - engine_cfg = NULL; - } - err = perform_armnn_cpm_config(&engine_cfg); - } break; - case 3: { - //perform cpm config - if (engine_cfg) { - int err2 = mv_destroy_engine_config(engine_cfg); - if (err2 != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy engine_cfg [err:%i]\n", err2); - engine_cfg = NULL; - } - err = perform_hosted_tflite_cpm_192_config(&engine_cfg); - } break; - case 4: { - //perform mobilenet-v1 posenet config - if (engine_cfg) { - int err2 = mv_destroy_engine_config(engine_cfg); - if (err2 != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy engine_cfg [err:%i]\n", err2); - engine_cfg = NULL; - } - err = perform_hosted_tflite_mobilenet_v1_posenet_257_config(&engine_cfg); - } break; - case 5: { - //perform int8 movenet - if (engine_cfg) { - int err2 = mv_destroy_engine_config(engine_cfg); - if (err2 != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy engine_cfg [err:%i]\n", err2); - engine_cfg = NULL; - } - err = perform_hosted_tflite_mobilenet_v1_posenet_257_config(&engine_cfg); - } break; - case 6: { - // create - configure - prepare - if (infer) { - int err2 = mv_inference_destroy(infer); - if (err2 != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy inference handle [err:%i]\n", err2); - infer = NULL; - } - - // inference - // create handle - err = mv_inference_create(&infer); - if (err != MEDIA_VISION_ERROR_NONE) { - printf("Fail to create inference handle [err:%i]\n", err); - break; - } - - //configure - err = mv_inference_configure(infer, engine_cfg); - if (err != MEDIA_VISION_ERROR_NONE) { - printf("Fail to configure inference handle [err:%i]\n", err); - break; - } - - //prepare - err = mv_inference_prepare(infer); - if (err != MEDIA_VISION_ERROR_NONE) { - printf("Fail to prepare inference handle"); - break; - } - } break; - case 7: { - if (mvSource) { - int err2 = mv_destroy_source(mvSource); - if (err2 != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy mvSource\n"); - mvSource = NULL; - } - - char *in_file_name = NULL; - /* Load media source */ - while (input_string("Input file name to be inferred:", 1024, - &(in_file_name)) == -1) - printf("Incorrect input! Try again.\n"); - - err = mv_create_source(&mvSource); - if (err != MEDIA_VISION_ERROR_NONE) { - printf("Fail to create mvSource.\n"); - free(in_file_name); - break; - } - - err = load_mv_source_from_file(in_file_name, mvSource); - if (err != MEDIA_VISION_ERROR_NONE) { - int err2 = mv_destroy_source(mvSource); - if (err2 != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy mvSource err: %d.\n", err2); - mvSource = NULL; - free(in_file_name); - break; - } - free(in_file_name); - - struct timespec s_tspec; - struct timespec e_tspec; - - clock_gettime(CLOCK_MONOTONIC, &s_tspec); - - // Object Detect - err = mv_inference_pose_landmark_detect( - mvSource, infer, NULL, _pose_landmark_detected_cb, NULL); - - clock_gettime(CLOCK_MONOTONIC, &e_tspec); - - struct timespec diffspec = diff(s_tspec, e_tspec); - unsigned long timeDiff = gettotalmillisec(diffspec); - printf("elapsed time : %lu(ms)\n", timeDiff); - } break; - case 8: { - //perform destroy - if (engine_cfg) { - err = mv_destroy_engine_config(engine_cfg); - if (err != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy engine_cfg [err:%i]\n", err); - engine_cfg = NULL; - } - - if (infer) { - err = mv_inference_destroy(infer); - if (err != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy inference handle [err:%i]\n", err); - infer = NULL; - } - - if (mvSource) { - err = mv_destroy_source(mvSource); - if (err != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy mvSource [err:%i]\n", err); - mvSource = NULL; - } - } break; - default: - printf("Invalid option.\n"); - sel_opt = 0; - continue; - } - - int do_another = 0; - if (err != MEDIA_VISION_ERROR_NONE) { - printf("ERROR: Action is finished with error code: %i\n", err); - } - - sel_opt = 0; - while (sel_opt == 0) { - sel_opt = show_menu_yes_or_no("Run Pose Landmark Detection again?:"); - switch (sel_opt) { - case 1: - do_another = 1; - break; - case 2: - do_another = 0; - break; - default: - printf("Invalid option.\n"); - sel_opt = 0; - } - } - - sel_opt = (do_another == 1) ? 0 : 1; + int sel_opt = show_menu_linear("Select Action:", names, ARRAY_SIZE(names)); + if (sel_opt <= 0 || sel_opt > ARRAY_SIZE(names)) { + printf("Invalid option"); + return -1; } - if (engine_cfg) { - err = mv_destroy_engine_config(engine_cfg); - if (err != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy engine_cfg [err:%i]\n", err); - engine_cfg = NULL; + err = mv_create_engine_config(&engine_cfg); + if (err != MEDIA_VISION_ERROR_NONE) { + printf("Fail to create engine configuration handle.\n"); + return err; } - if (infer) { - err = mv_inference_destroy(infer); - if (err != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy inference handle [err:%i]\n", err); - infer = NULL; + switch (sel_opt) { + case 1: { //perform TweakCNN config + err = perform_armnn_cpm_config(engine_cfg); + } break; + case 2: { //perform cpm config + err = engine_config_hosted_tflite_cpu(engine_cfg, + PLD_TFLITE_WEIGHT_CPM_192_PATH); + } break; + case 3: { //perform mobilenet-v1 posenet config + err = engine_config_hosted_tflite_cpu( + engine_cfg, PLD_TFLITE_WEIGHT_MOBILENET_V1_POSENET_257_PATH); + } break; + case 4: { //perform int8 movenet + err = engine_config_hosted_tflite_cpu( + engine_cfg, PLD_TFLITE_WEIGHT_INT8_MOVENET_PATH); + } break; } - - if (mvSource) { - err = mv_destroy_source(mvSource); - if (err != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy mvSource [err:%i]\n", err); - mvSource = NULL; + if (err != MEDIA_VISION_ERROR_NONE) { + printf("Fail to perform config [err:%i]\n", err); + goto clean_pose_engine; } - return MEDIA_VISION_ERROR_NONE; + err = mv_inference_task_helper(engine_cfg, TASK_PLD); + if (err != MEDIA_VISION_ERROR_NONE) + printf("Fail to detect with engine [err:%i]\n", err); + +clean_pose_engine: + err = mv_destroy_engine_config(engine_cfg); + if (err != MEDIA_VISION_ERROR_NONE) + printf("Fail to destroy engine_cfg [err:%i]\n", err); + + return err; } int main() -- 2.7.4 From aa3185f2252bdebbfbf48cc3dab3d4c97f54aa7c Mon Sep 17 00:00:00 2001 From: Kwang Son Date: Tue, 3 Aug 2021 21:42:19 -0400 Subject: [PATCH 02/16] test: Cleanup perform_facial_landmark_detection Base on commit 0a7ab1f50e641c4937d2ca87ab0950067688860b alloactate mv_source, mv_engine, mv_infer in a function so makes hard to deallocate resource and error handling. Change-Id: Ib242154ec33602a8a9788203cabc34e37e5f878d Signed-off-by: Kwang Son --- .../inference/inference_test_suite.c | 473 ++++----------------- 1 file changed, 90 insertions(+), 383 deletions(-) diff --git a/test/testsuites/machine_learning/inference/inference_test_suite.c b/test/testsuites/machine_learning/inference/inference_test_suite.c index e2df147..5fa02f2 100644 --- a/test/testsuites/machine_learning/inference/inference_test_suite.c +++ b/test/testsuites/machine_learning/inference/inference_test_suite.c @@ -200,6 +200,15 @@ #define TASK_FLD 3 #define TASK_PLD 4 +#define RET_IF_FAIL(exp) \ + do { \ + int err = (exp); \ + if (err != MEDIA_VISION_ERROR_NONE) { \ + printf("[%s] %s failed\n", __func__, #exp); \ + return err; \ + } \ + } while (0) + /****** * Public model: * IC: mobilenet caffe, tf? @@ -2876,413 +2885,111 @@ int perform_face_detection() return MEDIA_VISION_ERROR_NONE; } -int perform_tflite_TweakCNN(mv_engine_config_h *engine_cfg) +int perform_tflite_TweakCNN(mv_engine_config_h handle) { - int err = MEDIA_VISION_ERROR_NONE; - - mv_engine_config_h handle = NULL; - err = mv_create_engine_config(&handle); - if (err != MEDIA_VISION_ERROR_NONE) { - printf("Fail to create engine configuration handle.\n"); - if (handle) { - int err2 = mv_destroy_engine_config(handle); - if (err2 != MEDIA_VISION_ERROR_NONE) { - printf("Fail to destroy engine configuration.\n"); - } - } - return err; - } - const char *inputNodeName = "INPUT_TENSOR_NAME"; const char *outputNodeName[] = { "OUTPUT_TENSOR_NAME" }; - mv_engine_config_set_string_attribute(handle, - MV_INFERENCE_MODEL_WEIGHT_FILE_PATH, - FLD_TFLITE_WEIGHT_PATH); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_DATA_TYPE, - MV_INFERENCE_DATA_FLOAT32); - - mv_engine_config_set_double_attribute(handle, MV_INFERENCE_MODEL_MEAN_VALUE, - 0.0); - - mv_engine_config_set_double_attribute(handle, MV_INFERENCE_MODEL_STD_VALUE, - 1.0); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_BACKEND_TYPE, - MV_INFERENCE_BACKEND_TFLITE); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_TARGET_TYPE, - MV_INFERENCE_TARGET_CPU); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_TENSOR_WIDTH, - 128); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_TENSOR_HEIGHT, - 128); - - mv_engine_config_set_int_attribute(handle, - MV_INFERENCE_INPUT_TENSOR_CHANNELS, 3); - - mv_engine_config_set_string_attribute(handle, MV_INFERENCE_INPUT_NODE_NAME, - inputNodeName); - - mv_engine_config_set_array_string_attribute( - handle, MV_INFERENCE_OUTPUT_NODE_NAMES, outputNodeName, 1); - - *engine_cfg = handle; - return err; + RET_IF_FAIL( + engine_config_hosted_tflite_cpu(handle, FLD_TFLITE_WEIGHT_PATH)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_INPUT_DATA_TYPE, MV_INFERENCE_DATA_FLOAT32)); + RET_IF_FAIL(mv_engine_config_set_double_attribute( + handle, MV_INFERENCE_MODEL_MEAN_VALUE, 0.0)); + RET_IF_FAIL(mv_engine_config_set_double_attribute( + handle, MV_INFERENCE_MODEL_STD_VALUE, 1.0)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_INPUT_TENSOR_WIDTH, 128)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_INPUT_TENSOR_HEIGHT, 128)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_INPUT_TENSOR_CHANNELS, 3)); + RET_IF_FAIL(mv_engine_config_set_string_attribute( + handle, MV_INFERENCE_INPUT_NODE_NAME, inputNodeName)); + RET_IF_FAIL(mv_engine_config_set_array_string_attribute( + handle, MV_INFERENCE_OUTPUT_NODE_NAMES, outputNodeName, 1)); + return MEDIA_VISION_ERROR_NONE; } -int perform_opencv_cnncascade(mv_engine_config_h *engine_cfg) +int perform_opencv_cnncascade(mv_engine_config_h handle) { - int err = MEDIA_VISION_ERROR_NONE; - - mv_engine_config_h handle = NULL; - err = mv_create_engine_config(&handle); - if (err != MEDIA_VISION_ERROR_NONE) { - printf("Fail to create engine configuration handle.\n"); - if (handle) { - int err2 = mv_destroy_engine_config(handle); - if (err2 != MEDIA_VISION_ERROR_NONE) { - printf("Fail to destroy engine configuration.\n"); - } - } - return err; - } - const char *inputNodeName = "data"; const char *outputNodeName[] = { "Sigmoid_fc2" }; - mv_engine_config_set_string_attribute(handle, - MV_INFERENCE_MODEL_WEIGHT_FILE_PATH, - FLD_OPENCV_WEIGHT_CAFFE_PATH); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_DATA_TYPE, - MV_INFERENCE_DATA_FLOAT32); - - mv_engine_config_set_string_attribute( + RET_IF_FAIL(mv_engine_config_set_string_attribute( + handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH, + FLD_OPENCV_WEIGHT_CAFFE_PATH)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_INPUT_DATA_TYPE, MV_INFERENCE_DATA_FLOAT32)); + RET_IF_FAIL(mv_engine_config_set_string_attribute( handle, MV_INFERENCE_MODEL_CONFIGURATION_FILE_PATH, - FLD_OPENCV_CONFIG_CAFFE_PATH); - - mv_engine_config_set_double_attribute(handle, MV_INFERENCE_MODEL_MEAN_VALUE, - 127.5); - - mv_engine_config_set_double_attribute(handle, MV_INFERENCE_MODEL_STD_VALUE, - 127.5); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_BACKEND_TYPE, - MV_INFERENCE_BACKEND_OPENCV); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_TARGET_TYPE, - MV_INFERENCE_TARGET_CPU); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_TENSOR_WIDTH, - 128); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_TENSOR_HEIGHT, - 128); - - mv_engine_config_set_int_attribute(handle, - MV_INFERENCE_INPUT_TENSOR_CHANNELS, 3); - - mv_engine_config_set_string_attribute(handle, MV_INFERENCE_INPUT_NODE_NAME, - inputNodeName); - - mv_engine_config_set_array_string_attribute( - handle, MV_INFERENCE_OUTPUT_NODE_NAMES, outputNodeName, 1); - - *engine_cfg = handle; - return err; -} - - -int perform_hosted_tflite_tweakCNN_128_config(mv_engine_config_h *engine_cfg) -{ - int err = MEDIA_VISION_ERROR_NONE; - - mv_engine_config_h handle = NULL; - err = mv_create_engine_config(&handle); - if (err != MEDIA_VISION_ERROR_NONE) { - printf("Fail to create engine configuration handle.\n"); - if (handle) { - int err2 = mv_destroy_engine_config(handle); - if (err2 != MEDIA_VISION_ERROR_NONE) { - printf("Fail to destroy engine configuration.\n"); - } - } - return err; - } - - mv_engine_config_set_string_attribute(handle, - MV_INFERENCE_MODEL_WEIGHT_FILE_PATH, - FLD_TFLITE_WIEGHT_TWEAKCNN_128_PATH); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_BACKEND_TYPE, - MV_INFERENCE_BACKEND_TFLITE); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_TARGET_TYPE, - MV_INFERENCE_TARGET_CPU); - - *engine_cfg = handle; - return err; -} - -int perform_hosted_tflite_mediapipe_192_config(mv_engine_config_h *engine_cfg) -{ - int err = MEDIA_VISION_ERROR_NONE; - - mv_engine_config_h handle = NULL; - err = mv_create_engine_config(&handle); - if (err != MEDIA_VISION_ERROR_NONE) { - printf("Fail to create engine configuration handle.\n"); - if (handle) { - int err2 = mv_destroy_engine_config(handle); - if (err2 != MEDIA_VISION_ERROR_NONE) { - printf("Fail to destroy engine configuration.\n"); - } - } - return err; - } - - mv_engine_config_set_string_attribute(handle, - MV_INFERENCE_MODEL_WEIGHT_FILE_PATH, - FLD_TFLITE_WIEGHT_MEDIAPIPE_192_PATH); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_BACKEND_TYPE, - MV_INFERENCE_BACKEND_TFLITE); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_TARGET_TYPE, - MV_INFERENCE_TARGET_CPU); - - *engine_cfg = handle; - return err; + FLD_OPENCV_CONFIG_CAFFE_PATH)); + RET_IF_FAIL(mv_engine_config_set_double_attribute( + handle, MV_INFERENCE_MODEL_MEAN_VALUE, 127.5)); + RET_IF_FAIL(mv_engine_config_set_double_attribute( + handle, MV_INFERENCE_MODEL_STD_VALUE, 127.5)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_BACKEND_TYPE, MV_INFERENCE_BACKEND_OPENCV)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_TARGET_TYPE, MV_INFERENCE_TARGET_CPU)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_INPUT_TENSOR_WIDTH, 128)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_INPUT_TENSOR_HEIGHT, 128)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_INPUT_TENSOR_CHANNELS, 3)); + RET_IF_FAIL(mv_engine_config_set_string_attribute( + handle, MV_INFERENCE_INPUT_NODE_NAME, inputNodeName)); + RET_IF_FAIL(mv_engine_config_set_array_string_attribute( + handle, MV_INFERENCE_OUTPUT_NODE_NAMES, outputNodeName, 1)); + return MEDIA_VISION_ERROR_NONE; } int perform_facial_landmark_detection() { int err = MEDIA_VISION_ERROR_NONE; - - int sel_opt = 0; - const char *names[] = { "Configuration", - "Tflite(CPU) + TweakCNN", - "OPENCV(CPU) + TweakCNN", - "Hosted: TFLite(TweakCNN)", - "Hosted: TFLite(MediaPipe)", - "Prepare", - "Run", - "Back" }; - mv_engine_config_h engine_cfg = NULL; - mv_inference_h infer = NULL; - mv_source_h mvSource = NULL; - - while (sel_opt == 0) { - sel_opt = show_menu_linear("Select Action:", names, ARRAY_SIZE(names)); - switch (sel_opt) { - case 1: { - //perform configuration - if (engine_cfg) { - int err2 = mv_destroy_engine_config(engine_cfg); - if (err2 != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy engine_cfg [err:%i]\n", err2); - engine_cfg = NULL; - } - - err = perform_configuration(&engine_cfg); - } break; - case 2: { - //perform SRID TweakCNN config - if (engine_cfg) { - int err2 = mv_destroy_engine_config(engine_cfg); - if (err2 != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy engine_cfg [err:%i]\n", err2); - engine_cfg = NULL; - } - err = perform_tflite_TweakCNN(&engine_cfg); - } break; - case 3: { - //perform CNN cascade - if (engine_cfg) { - int err2 = mv_destroy_engine_config(engine_cfg); - if (err2 != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy engine_cfg [err:%i]\n", err2); - } - err = perform_opencv_cnncascade(&engine_cfg); - } break; - case 4: { - //perform Hosted TweakCNN config - if (engine_cfg) { - int err2 = mv_destroy_engine_config(engine_cfg); - if (err2 != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy engine_cfg [err:%i]\n", err2); - engine_cfg = NULL; - } - err = perform_hosted_tflite_tweakCNN_128_config(&engine_cfg); - } break; - case 5: { - //perform Hosted MediaPipe config - if (engine_cfg) { - int err2 = mv_destroy_engine_config(engine_cfg); - if (err2 != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy engine_cfg [err:%i]\n", err2); - engine_cfg = NULL; - } - err = perform_hosted_tflite_mediapipe_192_config(&engine_cfg); - } break; - case 6: { - // create - configure - prepare - if (infer) { - int err2 = mv_inference_destroy(infer); - if (err2 != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy inference handle [err:%i]\n", err2); - infer = NULL; - } - - // inference - // create handle - err = mv_inference_create(&infer); - if (err != MEDIA_VISION_ERROR_NONE) { - printf("Fail to create inference handle [err:%i]\n", err); - break; - } - - //configure - err = mv_inference_configure(infer, engine_cfg); - if (err != MEDIA_VISION_ERROR_NONE) { - printf("Fail to configure inference handle [err:%i]\n", err); - break; - } - - //prepare - err = mv_inference_prepare(infer); - if (err != MEDIA_VISION_ERROR_NONE) { - printf("Fail to prepare inference handle"); - break; - } - } break; - case 7: { - if (mvSource) { - int err2 = mv_destroy_source(mvSource); - if (err2 != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy mvSource\n"); - mvSource = NULL; - } - - char *in_file_name = NULL; - /* Load media source */ - while (input_string("Input file name to be inferred:", 1024, - &(in_file_name)) == -1) - printf("Incorrect input! Try again.\n"); - - err = mv_create_source(&mvSource); - if (err != MEDIA_VISION_ERROR_NONE) { - printf("Fail to create mvSource.\n"); - free(in_file_name); - break; - } - - err = load_mv_source_from_file(in_file_name, mvSource); - if (err != MEDIA_VISION_ERROR_NONE) { - int err2 = mv_destroy_source(mvSource); - if (err2 != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy mvSource. error code:%i\n", err2); - mvSource = NULL; - free(in_file_name); - break; - } - free(in_file_name); - - struct timespec s_tspec; - struct timespec e_tspec; - - clock_gettime(CLOCK_MONOTONIC, &s_tspec); - - // Object Detect - err = mv_inference_facial_landmark_detect( - mvSource, infer, NULL, _facial_landmark_detected_cb, NULL); - - clock_gettime(CLOCK_MONOTONIC, &e_tspec); - - struct timespec diffspec = diff(s_tspec, e_tspec); - unsigned long timeDiff = gettotalmillisec(diffspec); - printf("elapsed time : %lu(ms)\n", timeDiff); - } break; - case 8: { - //perform destroy - if (engine_cfg) { - err = mv_destroy_engine_config(engine_cfg); - if (err != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy engine_cfg [err:%i]\n", err); - engine_cfg = NULL; - } - - if (infer) { - err = mv_inference_destroy(infer); - if (err != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy inference handle [err:%i]\n", err); - infer = NULL; - } - - if (mvSource) { - err = mv_destroy_source(mvSource); - if (err != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy mvSource [err:%i]\n", err); - mvSource = NULL; - } - } break; - default: - printf("Invalid option.\n"); - sel_opt = 0; - continue; - } - - int do_another = 0; - if (err != MEDIA_VISION_ERROR_NONE) { - printf("ERROR: Action is finished with error code:%i\n", err); - } - - sel_opt = 0; - while (sel_opt == 0) { - sel_opt = show_menu_yes_or_no("Run Facial Landmark Detection again?:"); - switch (sel_opt) { - case 1: - do_another = 1; - break; - case 2: - do_another = 0; - break; - default: - printf("Invalid option.\n"); - sel_opt = 0; - } - } + const char *names[] = { + "Tflite(CPU) + TweakCNN", + "OPENCV(CPU) + TweakCNN", + "Hosted: TFLite(TweakCNN)", + "Hosted: TFLite(MediaPipe)", + }; - sel_opt = (do_another == 1) ? 0 : 1; + int sel_opt = show_menu_linear("Select Action:", names, ARRAY_SIZE(names)); + if (sel_opt <= 0 || sel_opt > ARRAY_SIZE(names)) { + printf("Invalid option"); + return -1; } - if (engine_cfg) { - err = mv_destroy_engine_config(engine_cfg); - if (err != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy engine_cfg [err:%i]\n", err); - engine_cfg = NULL; - } + RET_IF_FAIL(mv_create_engine_config(&engine_cfg)); - if (infer) { - err = mv_inference_destroy(infer); - if (err != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy inference handle [err:%i]\n", err); - infer = NULL; + switch (sel_opt) { + case 1: { + err = perform_tflite_TweakCNN(engine_cfg); + } break; + case 2: { + err = perform_opencv_cnncascade(engine_cfg); + } break; + case 3: { + err = engine_config_hosted_tflite_cpu( + engine_cfg, FLD_TFLITE_WIEGHT_TWEAKCNN_128_PATH); + } break; + case 4: { + err = engine_config_hosted_tflite_cpu( + engine_cfg, FLD_TFLITE_WIEGHT_MEDIAPIPE_192_PATH); + } break; } - - if (mvSource) { - err = mv_destroy_source(mvSource); - if (err != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy mvSource [err:%i]\n", err); - mvSource = NULL; + if (err != MEDIA_VISION_ERROR_NONE) { + printf("Fail to perform config [err:%i]\n", err); + goto clean_facial_landmark_engine; } - return MEDIA_VISION_ERROR_NONE; + RET_IF_FAIL(mv_inference_task_helper(engine_cfg, TASK_FLD)); + +clean_facial_landmark_engine: + RET_IF_FAIL(mv_destroy_engine_config(engine_cfg)); + return err; } int engine_config_hosted_tflite_cpu(mv_engine_config_h handle, -- 2.7.4 From 9b045d0c27ad4dd8b5a51e90dd1bdefb90b1b4c1 Mon Sep 17 00:00:00 2001 From: Kwang Son Date: Wed, 4 Aug 2021 03:06:26 -0400 Subject: [PATCH 03/16] test: Cleanup perform_face_detection Base on commit 0a7ab1f50e641c4937d2ca87ab0950067688860b alloactate mv_source, mv_engine, mv_infer in a function so makes hard to deallocate resource and error handling. Change-Id: Iaf1124821e39c7785955bc9b06a49b5997bb0430 Signed-off-by: Kwang Son --- .../inference/inference_test_suite.c | 741 +++++---------------- 1 file changed, 175 insertions(+), 566 deletions(-) diff --git a/test/testsuites/machine_learning/inference/inference_test_suite.c b/test/testsuites/machine_learning/inference/inference_test_suite.c index 5fa02f2..b47547e 100644 --- a/test/testsuites/machine_learning/inference/inference_test_suite.c +++ b/test/testsuites/machine_learning/inference/inference_test_suite.c @@ -2386,503 +2386,159 @@ int perform_object_detection() return MEDIA_VISION_ERROR_NONE; } -int perform_tflite_mobilenetv1ssd_face(mv_engine_config_h *engine_cfg) +int perform_tflite_mobilenetv1ssd_face(mv_engine_config_h handle) { - int err = MEDIA_VISION_ERROR_NONE; - - mv_engine_config_h handle = NULL; - err = mv_create_engine_config(&handle); - if (err != MEDIA_VISION_ERROR_NONE) { - printf("Fail to create engine configuration handle.\n"); - if (handle) { - int err2 = mv_destroy_engine_config(handle); - if (err2 != MEDIA_VISION_ERROR_NONE) { - printf("Fail to destroy engine configuration.\n"); - } - } - return err; - } - - const char *inputNodeName = "normalized_input_image_tensor"; - const char *outputNodeName[] = { "TFLite_Detection_PostProcess", - "TFLite_Detection_PostProcess:1", - "TFLite_Detection_PostProcess:2", - "TFLite_Detection_PostProcess:3" }; - - mv_engine_config_set_string_attribute( - handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH, FD_TFLITE_WEIGHT_PATH); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_DATA_TYPE, - MV_INFERENCE_DATA_FLOAT32); - - mv_engine_config_set_double_attribute(handle, MV_INFERENCE_MODEL_MEAN_VALUE, - 127.5); - - mv_engine_config_set_double_attribute(handle, MV_INFERENCE_MODEL_STD_VALUE, - 127.5); - - mv_engine_config_set_double_attribute( - handle, MV_INFERENCE_CONFIDENCE_THRESHOLD, 0.3); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_BACKEND_TYPE, - MV_INFERENCE_BACKEND_TFLITE); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_TARGET_TYPE, - MV_INFERENCE_TARGET_CPU); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_TENSOR_WIDTH, - 300); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_TENSOR_HEIGHT, - 300); - - mv_engine_config_set_int_attribute(handle, - MV_INFERENCE_INPUT_TENSOR_CHANNELS, 3); - - mv_engine_config_set_string_attribute(handle, MV_INFERENCE_INPUT_NODE_NAME, - inputNodeName); - - mv_engine_config_set_array_string_attribute( - handle, MV_INFERENCE_OUTPUT_NODE_NAMES, outputNodeName, 4); - - *engine_cfg = handle; - return err; -} - -int perform_opencv_resnet10ssd_face(mv_engine_config_h *engine_cfg) -{ - int err = MEDIA_VISION_ERROR_NONE; - - mv_engine_config_h handle = NULL; - err = mv_create_engine_config(&handle); - if (err != MEDIA_VISION_ERROR_NONE) { - printf("Fail to create engine configuration handle.\n"); - if (handle) { - int err2 = mv_destroy_engine_config(handle); - if (err2 != MEDIA_VISION_ERROR_NONE) { - printf("Fail to destroy engine configuration.\n"); - } - } - return err; - } - - const char *inputNodeName = "data"; - const char *outputNodeName[] = { "detection_out" }; - - mv_engine_config_set_string_attribute(handle, - MV_INFERENCE_MODEL_WEIGHT_FILE_PATH, - FD_OPENCV_WEIGHT_CAFFE_PATH); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_DATA_TYPE, - MV_INFERENCE_DATA_FLOAT32); - - mv_engine_config_set_string_attribute( - handle, MV_INFERENCE_MODEL_CONFIGURATION_FILE_PATH, - FD_OPENCV_CONFIG_CAFFE_PATH); - - mv_engine_config_set_double_attribute(handle, MV_INFERENCE_MODEL_MEAN_VALUE, - 135.7); - - mv_engine_config_set_double_attribute(handle, MV_INFERENCE_MODEL_STD_VALUE, - 1.0); - - mv_engine_config_set_double_attribute( - handle, MV_INFERENCE_CONFIDENCE_THRESHOLD, 0.3); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_BACKEND_TYPE, - MV_INFERENCE_BACKEND_OPENCV); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_TARGET_TYPE, - MV_INFERENCE_TARGET_CPU); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_TENSOR_WIDTH, - 300); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_TENSOR_HEIGHT, - 300); - - mv_engine_config_set_int_attribute(handle, - MV_INFERENCE_INPUT_TENSOR_CHANNELS, 3); - - mv_engine_config_set_string_attribute(handle, MV_INFERENCE_INPUT_NODE_NAME, - inputNodeName); - - mv_engine_config_set_array_string_attribute( - handle, MV_INFERENCE_OUTPUT_NODE_NAMES, outputNodeName, 1); - - *engine_cfg = handle; - return err; -} - -int perform_armnn_mobilenetv1ssd_face(mv_engine_config_h *engine_cfg) -{ - int err = MEDIA_VISION_ERROR_NONE; - - mv_engine_config_h handle = NULL; - err = mv_create_engine_config(&handle); - if (err != MEDIA_VISION_ERROR_NONE) { - printf("Fail to create engine configuration handle.\n"); - if (handle) { - int err2 = mv_destroy_engine_config(handle); - if (err2 != MEDIA_VISION_ERROR_NONE) { - printf("Fail to destroy engine configuration.\n"); - } - } - return err; - } - const char *inputNodeName = "normalized_input_image_tensor"; const char *outputNodeName[] = { "TFLite_Detection_PostProcess", - "TFLite_Detection_PostProcess:1", - "TFLite_Detection_PostProcess:2", - "TFLite_Detection_PostProcess:3" }; - - mv_engine_config_set_string_attribute( - handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH, FD_TFLITE_WEIGHT_PATH); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_DATA_TYPE, - MV_INFERENCE_DATA_FLOAT32); - - mv_engine_config_set_double_attribute(handle, MV_INFERENCE_MODEL_MEAN_VALUE, - 127.5); - - mv_engine_config_set_double_attribute(handle, MV_INFERENCE_MODEL_STD_VALUE, - 127.5); - - mv_engine_config_set_double_attribute( - handle, MV_INFERENCE_CONFIDENCE_THRESHOLD, 0.3); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_BACKEND_TYPE, - MV_INFERENCE_BACKEND_ARMNN); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_TARGET_TYPE, - MV_INFERENCE_TARGET_CPU); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_TENSOR_WIDTH, - 300); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_TENSOR_HEIGHT, - 300); - - mv_engine_config_set_int_attribute(handle, - MV_INFERENCE_INPUT_TENSOR_CHANNELS, 3); - - mv_engine_config_set_string_attribute(handle, MV_INFERENCE_INPUT_NODE_NAME, - inputNodeName); - - mv_engine_config_set_array_string_attribute( - handle, MV_INFERENCE_OUTPUT_NODE_NAMES, outputNodeName, 4); - - *engine_cfg = handle; - return err; -} - -int perform_hosted_tflite_mobilenetv1ssd_300_config_face(mv_engine_config_h *engine_cfg) -{ - int err = MEDIA_VISION_ERROR_NONE; - - mv_engine_config_h handle = NULL; - err = mv_create_engine_config(&handle); - if (err != MEDIA_VISION_ERROR_NONE) { - printf("Fail to create engine configuration handle.\n"); - if (handle) { - int err2 = mv_destroy_engine_config(handle); - if (err2 != MEDIA_VISION_ERROR_NONE) { - printf("Fail to destroy engine configuration.\n"); - } - } - return err; - } - - mv_engine_config_set_string_attribute( - handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH, - FD_TFLITE_WEIGHT_MOBILENET_V1_SSD_300_PATH); - - mv_engine_config_set_int_attribute( - handle, MV_INFERENCE_BACKEND_TYPE, - MV_INFERENCE_BACKEND_TFLITE); - - mv_engine_config_set_int_attribute( - handle, MV_INFERENCE_TARGET_TYPE, - MV_INFERENCE_TARGET_CPU); - - *engine_cfg = handle; - return err; -} - -int perform_hosted_tflite_blazeface_128_config_face(mv_engine_config_h *engine_cfg) -{ - int err = MEDIA_VISION_ERROR_NONE; - - mv_engine_config_h handle = NULL; - err = mv_create_engine_config(&handle); - if (err != MEDIA_VISION_ERROR_NONE) { - printf("Fail to create engine configuration handle.\n"); - if (handle) { - int err2 = mv_destroy_engine_config(handle); - if (err2 != MEDIA_VISION_ERROR_NONE) { - printf("Fail to destroy engine configuration.\n"); - } - } - return err; - } - - mv_engine_config_set_string_attribute( - handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH, - FD_TFLITE_WEIGHT_BLAZEFACE_128_PATH); - - mv_engine_config_set_int_attribute( - handle, MV_INFERENCE_BACKEND_TYPE, - MV_INFERENCE_BACKEND_TFLITE); - - mv_engine_config_set_int_attribute( - handle, MV_INFERENCE_TARGET_TYPE, - MV_INFERENCE_TARGET_CPU); - - *engine_cfg = handle; - return err; -} - -int perform_face_detection() -{ - int err = MEDIA_VISION_ERROR_NONE; - - int sel_opt = 0; - const char *names[] = { "Configuration", - "TFLite(CPU) + MobileNetV1 + SSD", - "OPENCV(CPU) + Resnet10 + SSD", - "ARMNN(CPU) + MobileNetV1 + SSD", - "Hosted: TFLite(cpu + MobilenetV1+SSD)", - "Hosted: TFLite(cpu + BlazeFace)", - "Prepare", - "Run", - "Back" }; - - mv_engine_config_h engine_cfg = NULL; - mv_inference_h infer = NULL; - mv_source_h mvSource = NULL; - - while (sel_opt == 0) { - sel_opt = - show_menu_linear("Select Action:", names, ARRAY_SIZE(names)); - switch (sel_opt) { - case 1: { - //perform configuration - if (engine_cfg) { - int err2 = mv_destroy_engine_config(engine_cfg); - if (err2 != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy engine_cfg [err:%i]\n", err2); - engine_cfg = NULL; - } - - err = perform_configuration(&engine_cfg); - } break; - case 2: { - //perform TFlit Mobilenetv1ssd config - if (engine_cfg) { - int err2 = mv_destroy_engine_config(engine_cfg); - if (err2 != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy engine_cfg [err:%i]\n", err2); - engine_cfg = NULL; - } - - err = perform_tflite_mobilenetv1ssd_face(&engine_cfg); - } break; - case 3: { - //perform Opencv resenet10ssd config - if (engine_cfg) { - int err2 = mv_destroy_engine_config(engine_cfg); - if (err2 != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy engine_cfg [err:%i]\n", err2); - } - - err = perform_opencv_resnet10ssd_face(&engine_cfg); - } break; - case 4: { - //perform Armnn Mobilenetv1ssd config - if (engine_cfg) { - int err2 = mv_destroy_engine_config(engine_cfg); - if (err2 != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy engine_cfg [err:%i]\n", err2); - } - - err = perform_armnn_mobilenetv1ssd_face(&engine_cfg); - } break; - case 5: { - //perform hosted TFlite Mobilenetv1ssd config - if (engine_cfg) { - int err2 = mv_destroy_engine_config(engine_cfg); - if (err2 != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy engine_cfg [err:%i]\n", err2); - engine_cfg = NULL; - } - - err = perform_hosted_tflite_mobilenetv1ssd_300_config_face(&engine_cfg); - } break; - case 6: { - //perform hosted TFlite blazeface config - if (engine_cfg) { - int err2 = mv_destroy_engine_config(engine_cfg); - if (err2 != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy engine_cfg [err:%i]\n", err2); - engine_cfg = NULL; - } - - err = perform_hosted_tflite_blazeface_128_config_face(&engine_cfg); - } break; - case 7: { - // create - configure - prepare - if (infer) { - int err2 = mv_inference_destroy(infer); - if (err2 != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy inference handle [err:%i]\n", err2); - infer = NULL; - } - - // inference - // create handle - err = mv_inference_create(&infer); - if (err != MEDIA_VISION_ERROR_NONE) { - printf("Fail to create inference handle [err:%i]\n", err); - break; - } - - //configure - err = mv_inference_configure(infer, engine_cfg); - if (err != MEDIA_VISION_ERROR_NONE) { - printf("Fail to configure inference handle [err:%i]\n", err); - break; - } + "TFLite_Detection_PostProcess:1", + "TFLite_Detection_PostProcess:2", + "TFLite_Detection_PostProcess:3" }; - //prepare - err = mv_inference_prepare(infer); - if (err != MEDIA_VISION_ERROR_NONE) { - printf("Fail to prepare inference handle"); - break; - } - } break; - case 8: { - if (mvSource) { - int err2 = mv_destroy_source(mvSource); - if (err2 != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy mvSource\n"); - mvSource = NULL; - } - - char *in_file_name = NULL; - /* Load media source */ - while (input_string("Input file name to be inferred:", 1024, - &(in_file_name)) == -1) - printf("Incorrect input! Try again.\n"); - - err = mv_create_source(&mvSource); - if (err != MEDIA_VISION_ERROR_NONE) { - printf("Fail to create mvSource.\n"); - free(in_file_name); - break; - } - - err = load_mv_source_from_file(in_file_name, mvSource); - if (err != MEDIA_VISION_ERROR_NONE) { - int err2 = mv_destroy_source(mvSource); - if (err2 != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy mvSource. error code:%i\n", err2); - mvSource = NULL; - free(in_file_name); - break; - } - free(in_file_name); - - struct timespec s_tspec; - struct timespec e_tspec; - - clock_gettime(CLOCK_MONOTONIC, &s_tspec); - - // Object Detect - err = mv_inference_face_detect(mvSource, infer, _face_detected_cb, - NULL); - - clock_gettime(CLOCK_MONOTONIC, &e_tspec); + RET_IF_FAIL(engine_config_hosted_tflite_cpu(handle, FD_TFLITE_WEIGHT_PATH)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_INPUT_DATA_TYPE, MV_INFERENCE_DATA_FLOAT32)); + RET_IF_FAIL(mv_engine_config_set_double_attribute( + handle, MV_INFERENCE_MODEL_MEAN_VALUE, 127.5)); + RET_IF_FAIL(mv_engine_config_set_double_attribute( + handle, MV_INFERENCE_MODEL_STD_VALUE, 127.5)); + RET_IF_FAIL(mv_engine_config_set_double_attribute( + handle, MV_INFERENCE_CONFIDENCE_THRESHOLD, 0.3)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_INPUT_TENSOR_WIDTH, 300)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_INPUT_TENSOR_HEIGHT, 300)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_INPUT_TENSOR_CHANNELS, 3)); + RET_IF_FAIL(mv_engine_config_set_string_attribute( + handle, MV_INFERENCE_INPUT_NODE_NAME, inputNodeName)); + RET_IF_FAIL(mv_engine_config_set_array_string_attribute( + handle, MV_INFERENCE_OUTPUT_NODE_NAMES, outputNodeName, 4)); + return MEDIA_VISION_ERROR_NONE; +} - struct timespec diffspec = diff(s_tspec, e_tspec); - unsigned long timeDiff = gettotalmillisec(diffspec); - printf("elapsed time : %lu(ms)\n", timeDiff); - } break; - case 9: { - //perform destroy - if (engine_cfg) { - err = mv_destroy_engine_config(engine_cfg); - if (err != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy engine_cfg [err:%i]\n", err); - engine_cfg = NULL; - } +int perform_opencv_resnet10ssd_face(mv_engine_config_h handle) +{ + const char *inputNodeName = "data"; + const char *outputNodeName[] = { "detection_out" }; - if (infer) { - err = mv_inference_destroy(infer); - if (err != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy inference handle [err:%i]\n", err); - infer = NULL; - } + RET_IF_FAIL(mv_engine_config_set_string_attribute( + handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH, + FD_OPENCV_WEIGHT_CAFFE_PATH)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_INPUT_DATA_TYPE, MV_INFERENCE_DATA_FLOAT32)); + RET_IF_FAIL(mv_engine_config_set_string_attribute( + handle, MV_INFERENCE_MODEL_CONFIGURATION_FILE_PATH, + FD_OPENCV_CONFIG_CAFFE_PATH)); + RET_IF_FAIL(mv_engine_config_set_double_attribute( + handle, MV_INFERENCE_MODEL_MEAN_VALUE, 135.7)); + RET_IF_FAIL(mv_engine_config_set_double_attribute( + handle, MV_INFERENCE_MODEL_STD_VALUE, 1.0)); + RET_IF_FAIL(mv_engine_config_set_double_attribute( + handle, MV_INFERENCE_CONFIDENCE_THRESHOLD, 0.3)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_BACKEND_TYPE, MV_INFERENCE_BACKEND_OPENCV)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_TARGET_TYPE, MV_INFERENCE_TARGET_CPU)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_INPUT_TENSOR_WIDTH, 300)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_INPUT_TENSOR_HEIGHT, 300)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_INPUT_TENSOR_CHANNELS, 3)); + RET_IF_FAIL(mv_engine_config_set_string_attribute( + handle, MV_INFERENCE_INPUT_NODE_NAME, inputNodeName)); + RET_IF_FAIL(mv_engine_config_set_array_string_attribute( + handle, MV_INFERENCE_OUTPUT_NODE_NAMES, outputNodeName, 1)); + return MEDIA_VISION_ERROR_NONE; +} - if (mvSource) { - err = mv_destroy_source(mvSource); - if (err != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy mvSource [err:%i]\n", err); - mvSource = NULL; - } - } break; - default: - printf("Invalid option.\n"); - sel_opt = 0; - continue; - } +int perform_armnn_mobilenetv1ssd_face(mv_engine_config_h handle) +{ + const char *inputNodeName = "normalized_input_image_tensor"; + const char *outputNodeName[] = { "TFLite_Detection_PostProcess", + "TFLite_Detection_PostProcess:1", + "TFLite_Detection_PostProcess:2", + "TFLite_Detection_PostProcess:3" }; - int do_another = 0; - if (err != MEDIA_VISION_ERROR_NONE) { - printf("ERROR: Action is finished with error code:%i\n", err); - } + RET_IF_FAIL(mv_engine_config_set_string_attribute( + handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH, + FD_TFLITE_WEIGHT_PATH)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_INPUT_DATA_TYPE, MV_INFERENCE_DATA_FLOAT32)); + RET_IF_FAIL(mv_engine_config_set_double_attribute( + handle, MV_INFERENCE_MODEL_MEAN_VALUE, 127.5)); + RET_IF_FAIL(mv_engine_config_set_double_attribute( + handle, MV_INFERENCE_MODEL_STD_VALUE, 127.5)); + RET_IF_FAIL(mv_engine_config_set_double_attribute( + handle, MV_INFERENCE_CONFIDENCE_THRESHOLD, 0.3)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_BACKEND_TYPE, MV_INFERENCE_BACKEND_ARMNN)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_TARGET_TYPE, MV_INFERENCE_TARGET_CPU)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_INPUT_TENSOR_WIDTH, 300)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_INPUT_TENSOR_HEIGHT, 300)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_INPUT_TENSOR_CHANNELS, 3)); + RET_IF_FAIL(mv_engine_config_set_string_attribute( + handle, MV_INFERENCE_INPUT_NODE_NAME, inputNodeName)); + RET_IF_FAIL(mv_engine_config_set_array_string_attribute( + handle, MV_INFERENCE_OUTPUT_NODE_NAMES, outputNodeName, 4)); + return MEDIA_VISION_ERROR_NONE; +} - sel_opt = 0; - while (sel_opt == 0) { - sel_opt = show_menu_yes_or_no("Run Face Detection again?:"); - switch (sel_opt) { - case 1: - do_another = 1; - break; - case 2: - do_another = 0; - break; - default: - printf("Invalid option.\n"); - sel_opt = 0; - } - } +int perform_face_detection() +{ + int err = MEDIA_VISION_ERROR_NONE; + mv_engine_config_h engine_cfg = NULL; + const char *names[] = { + "TFLite(CPU) + MobileNetV1 + SSD", + "OPENCV(CPU) + Resnet10 + SSD", + "ARMNN(CPU) + MobileNetV1 + SSD", + "Hosted: TFLite(cpu + MobilenetV1+SSD)", + "Hosted: TFLite(cpu + BlazeFace)", + }; - sel_opt = (do_another == 1) ? 0 : 1; + int sel_opt = show_menu_linear("Select Action:", names, ARRAY_SIZE(names)); + if (sel_opt <= 0 || sel_opt > ARRAY_SIZE(names)) { + printf("Invalid option"); + return -1; } - if (engine_cfg) { - err = mv_destroy_engine_config(engine_cfg); - if (err != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy engine_cfg [err:%i]\n", err); - engine_cfg = NULL; - } + RET_IF_FAIL(mv_create_engine_config(&engine_cfg)); - if (infer) { - err = mv_inference_destroy(infer); - if (err != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy inference handle [err:%i]\n", err); - infer = NULL; + switch (sel_opt) { + case 1: { + err = perform_tflite_mobilenetv1ssd_face(engine_cfg); + } break; + case 2: { + err = perform_opencv_resnet10ssd_face(engine_cfg); + } break; + case 3: { + err = perform_armnn_mobilenetv1ssd_face(engine_cfg); + } break; + case 4: { + err = engine_config_hosted_tflite_cpu( + engine_cfg, FD_TFLITE_WEIGHT_MOBILENET_V1_SSD_300_PATH); + } break; + case 5: { + err = engine_config_hosted_tflite_cpu( + engine_cfg, FD_TFLITE_WEIGHT_BLAZEFACE_128_PATH); + } break; } - - if (mvSource) { - err = mv_destroy_source(mvSource); - if (err != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy mvSource [err:%i]\n", err); - mvSource = NULL; + if (err != MEDIA_VISION_ERROR_NONE) { + printf("Fail to perform config [err:%i]\n", err); + goto clean_face_engine; } - return MEDIA_VISION_ERROR_NONE; + err = mv_inference_task_helper(engine_cfg, TASK_FD); + if (err != MEDIA_VISION_ERROR_NONE) + printf("Fail to detect with engine [err:%i]\n", err); + +clean_face_engine: + RET_IF_FAIL(mv_destroy_engine_config(engine_cfg)); + return err; } int perform_tflite_TweakCNN(mv_engine_config_h handle) @@ -2985,7 +2641,9 @@ int perform_facial_landmark_detection() goto clean_facial_landmark_engine; } - RET_IF_FAIL(mv_inference_task_helper(engine_cfg, TASK_FLD)); + err = mv_inference_task_helper(engine_cfg, TASK_FLD); + if (err != MEDIA_VISION_ERROR_NONE) + printf("Fail to detect with engine [err:%i]\n", err); clean_facial_landmark_engine: RET_IF_FAIL(mv_destroy_engine_config(engine_cfg)); @@ -2995,21 +2653,13 @@ clean_facial_landmark_engine: int engine_config_hosted_tflite_cpu(mv_engine_config_h handle, const char *tf_weight) { - int err = mv_engine_config_set_string_attribute( - handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH, tf_weight); - if (err != MEDIA_VISION_ERROR_NONE) { - return err; - } - - err = mv_engine_config_set_int_attribute(handle, MV_INFERENCE_BACKEND_TYPE, - MV_INFERENCE_BACKEND_TFLITE); - if (err != MEDIA_VISION_ERROR_NONE) { - return err; - } - - err = mv_engine_config_set_int_attribute(handle, MV_INFERENCE_TARGET_TYPE, - MV_INFERENCE_TARGET_CPU); - return err; + RET_IF_FAIL(mv_engine_config_set_string_attribute( + handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH, tf_weight)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_BACKEND_TYPE, MV_INFERENCE_BACKEND_TFLITE)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_TARGET_TYPE, MV_INFERENCE_TARGET_CPU)); + return MEDIA_VISION_ERROR_NONE; } int perform_armnn_cpm_config(mv_engine_config_h handle) @@ -3017,68 +2667,29 @@ int perform_armnn_cpm_config(mv_engine_config_h handle) const char *inputNodeName = "image"; const char *outputNodeName[] = { "Convolutional_Pose_Machine/stage_5_out" }; - int err = engine_config_hosted_tflite_cpu(handle, PLD_TFLITE_WEIGHT_PATH); - if (err != MEDIA_VISION_ERROR_NONE) { - return err; - } - - err = mv_engine_config_set_int_attribute( - handle, MV_INFERENCE_INPUT_DATA_TYPE, MV_INFERENCE_DATA_FLOAT32); - if (err != MEDIA_VISION_ERROR_NONE) { - return err; - } - - err = mv_engine_config_set_string_attribute( - handle, MV_INFERENCE_MODEL_USER_FILE_PATH, PLD_POSE_LABEL_PATH); - if (err != MEDIA_VISION_ERROR_NONE) { - return err; - } - - err = mv_engine_config_set_double_attribute( - handle, MV_INFERENCE_MODEL_MEAN_VALUE, 0.0); - if (err != MEDIA_VISION_ERROR_NONE) { - return err; - } - - err = mv_engine_config_set_double_attribute( - handle, MV_INFERENCE_MODEL_STD_VALUE, 1.0); - if (err != MEDIA_VISION_ERROR_NONE) { - return err; - } - - err = mv_engine_config_set_double_attribute( - handle, MV_INFERENCE_CONFIDENCE_THRESHOLD, 0.3); - if (err != MEDIA_VISION_ERROR_NONE) { - return err; - } - - err = mv_engine_config_set_int_attribute( - handle, MV_INFERENCE_INPUT_TENSOR_WIDTH, 192); - if (err != MEDIA_VISION_ERROR_NONE) { - return err; - } - - err = mv_engine_config_set_int_attribute( - handle, MV_INFERENCE_INPUT_TENSOR_HEIGHT, 192); - if (err != MEDIA_VISION_ERROR_NONE) { - return err; - } - - err = mv_engine_config_set_int_attribute( - handle, MV_INFERENCE_INPUT_TENSOR_CHANNELS, 3); - if (err != MEDIA_VISION_ERROR_NONE) { - return err; - } - - err = mv_engine_config_set_string_attribute( - handle, MV_INFERENCE_INPUT_NODE_NAME, inputNodeName); - if (err != MEDIA_VISION_ERROR_NONE) { - return err; - } - - err = mv_engine_config_set_array_string_attribute( - handle, MV_INFERENCE_OUTPUT_NODE_NAMES, outputNodeName, 1); - return err; + RET_IF_FAIL( + engine_config_hosted_tflite_cpu(handle, PLD_TFLITE_WEIGHT_PATH)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_INPUT_DATA_TYPE, MV_INFERENCE_DATA_FLOAT32)); + RET_IF_FAIL(mv_engine_config_set_string_attribute( + handle, MV_INFERENCE_MODEL_USER_FILE_PATH, PLD_POSE_LABEL_PATH)); + RET_IF_FAIL(mv_engine_config_set_double_attribute( + handle, MV_INFERENCE_MODEL_MEAN_VALUE, 0.0)); + RET_IF_FAIL(mv_engine_config_set_double_attribute( + handle, MV_INFERENCE_MODEL_STD_VALUE, 1.0)); + RET_IF_FAIL(mv_engine_config_set_double_attribute( + handle, MV_INFERENCE_CONFIDENCE_THRESHOLD, 0.3)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_INPUT_TENSOR_WIDTH, 192)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_INPUT_TENSOR_HEIGHT, 192)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_INPUT_TENSOR_CHANNELS, 3)); + RET_IF_FAIL(mv_engine_config_set_string_attribute( + handle, MV_INFERENCE_INPUT_NODE_NAME, inputNodeName)); + RET_IF_FAIL(mv_engine_config_set_array_string_attribute( + handle, MV_INFERENCE_OUTPUT_NODE_NAMES, outputNodeName, 1)); + return MEDIA_VISION_ERROR_NONE; } int perform_pose_landmark_detection() @@ -3105,18 +2716,18 @@ int perform_pose_landmark_detection() } switch (sel_opt) { - case 1: { //perform TweakCNN config + case 1: { err = perform_armnn_cpm_config(engine_cfg); } break; - case 2: { //perform cpm config + case 2: { err = engine_config_hosted_tflite_cpu(engine_cfg, PLD_TFLITE_WEIGHT_CPM_192_PATH); } break; - case 3: { //perform mobilenet-v1 posenet config + case 3: { err = engine_config_hosted_tflite_cpu( engine_cfg, PLD_TFLITE_WEIGHT_MOBILENET_V1_POSENET_257_PATH); } break; - case 4: { //perform int8 movenet + case 4: { err = engine_config_hosted_tflite_cpu( engine_cfg, PLD_TFLITE_WEIGHT_INT8_MOVENET_PATH); } break; @@ -3131,9 +2742,7 @@ int perform_pose_landmark_detection() printf("Fail to detect with engine [err:%i]\n", err); clean_pose_engine: - err = mv_destroy_engine_config(engine_cfg); - if (err != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy engine_cfg [err:%i]\n", err); + RET_IF_FAIL(mv_destroy_engine_config(engine_cfg)); return err; } -- 2.7.4 From a24a8343bc410d7eab3decacf99d217d08aa7168 Mon Sep 17 00:00:00 2001 From: Kwang Son Date: Wed, 4 Aug 2021 22:28:39 -0400 Subject: [PATCH 04/16] test: Cleanup image, object detection Base on commit 0a7ab1f50e641c4937d2ca87ab0950067688860b alloactate mv_source, mv_engine, mv_infer in a function so makes hard to deallocate resource and error handling. Change-Id: Ibd9586fe5e999e3013ab989643f47b6a4547f3fa Signed-off-by: Kwang Son --- .../inference/inference_test_suite.c | 1971 +++++--------------- 1 file changed, 420 insertions(+), 1551 deletions(-) diff --git a/test/testsuites/machine_learning/inference/inference_test_suite.c b/test/testsuites/machine_learning/inference/inference_test_suite.c index b47547e..f0e7c80 100644 --- a/test/testsuites/machine_learning/inference/inference_test_suite.c +++ b/test/testsuites/machine_learning/inference/inference_test_suite.c @@ -769,1621 +769,480 @@ int perform_configuration(mv_engine_config_h *engine_cfg) return err; } -int perform_tflite_mobilenetv1_config(mv_engine_config_h *engine_cfg) +int perform_tflite_mobilenetv1_config(mv_engine_config_h handle) { - int err = MEDIA_VISION_ERROR_NONE; - - mv_engine_config_h handle = NULL; - err = mv_create_engine_config(&handle); - if (err != MEDIA_VISION_ERROR_NONE) { - printf("Fail to create engine configuration handle.\n"); - if (handle) { - int err2 = mv_destroy_engine_config(handle); - if (err2 != MEDIA_VISION_ERROR_NONE) { - printf("Fail to destroy engine configuration.\n"); - } - } - return err; - } - const char *inputNodeName = "input_2"; const char *outputNodeName[] = { "dense_3/Softmax" }; - mv_engine_config_set_string_attribute( - handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH, IC_TFLITE_WEIGHT_PATH); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_DATA_TYPE, - MV_INFERENCE_DATA_FLOAT32); - - mv_engine_config_set_string_attribute( - handle, MV_INFERENCE_MODEL_USER_FILE_PATH, IC_LABEL_PATH); - - mv_engine_config_set_double_attribute(handle, MV_INFERENCE_MODEL_MEAN_VALUE, - 127.0); - - mv_engine_config_set_double_attribute(handle, MV_INFERENCE_MODEL_STD_VALUE, - 127.0); - - mv_engine_config_set_double_attribute( - handle, MV_INFERENCE_CONFIDENCE_THRESHOLD, 0.6); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_BACKEND_TYPE, - MV_INFERENCE_BACKEND_TFLITE); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_TARGET_TYPE, - MV_INFERENCE_TARGET_CPU); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_TENSOR_WIDTH, - 224); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_TENSOR_HEIGHT, - 224); - - mv_engine_config_set_int_attribute(handle, - MV_INFERENCE_INPUT_TENSOR_CHANNELS, 3); - - mv_engine_config_set_string_attribute(handle, MV_INFERENCE_INPUT_NODE_NAME, - inputNodeName); - - mv_engine_config_set_array_string_attribute( - handle, MV_INFERENCE_OUTPUT_NODE_NAMES, outputNodeName, 1); - - *engine_cfg = handle; - return err; + RET_IF_FAIL(mv_engine_config_set_string_attribute( + handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH, + IC_TFLITE_WEIGHT_PATH)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_INPUT_DATA_TYPE, MV_INFERENCE_DATA_FLOAT32)); + RET_IF_FAIL(mv_engine_config_set_string_attribute( + handle, MV_INFERENCE_MODEL_USER_FILE_PATH, IC_LABEL_PATH)); + RET_IF_FAIL(mv_engine_config_set_double_attribute( + handle, MV_INFERENCE_MODEL_MEAN_VALUE, 127.0)); + RET_IF_FAIL(mv_engine_config_set_double_attribute( + handle, MV_INFERENCE_MODEL_STD_VALUE, 127.0)); + RET_IF_FAIL(mv_engine_config_set_double_attribute( + handle, MV_INFERENCE_CONFIDENCE_THRESHOLD, 0.6)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_BACKEND_TYPE, MV_INFERENCE_BACKEND_TFLITE)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_TARGET_TYPE, MV_INFERENCE_TARGET_CPU)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_INPUT_TENSOR_WIDTH, 224)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_INPUT_TENSOR_HEIGHT, 224)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_INPUT_TENSOR_CHANNELS, 3)); + RET_IF_FAIL(mv_engine_config_set_string_attribute( + handle, MV_INFERENCE_INPUT_NODE_NAME, inputNodeName)); + RET_IF_FAIL(mv_engine_config_set_array_string_attribute( + handle, MV_INFERENCE_OUTPUT_NODE_NAMES, outputNodeName, 1)); + return MEDIA_VISION_ERROR_NONE; } -int perform_armnn_mobilenetv1_config(mv_engine_config_h *engine_cfg) +int perform_armnn_mobilenetv1_config(mv_engine_config_h handle) { - int err = MEDIA_VISION_ERROR_NONE; - - mv_engine_config_h handle = NULL; - err = mv_create_engine_config(&handle); - if (err != MEDIA_VISION_ERROR_NONE) { - printf("Fail to create engine configuration handle.\n"); - if (handle) { - int err2 = mv_destroy_engine_config(handle); - if (err2 != MEDIA_VISION_ERROR_NONE) { - printf("Fail to destroy engine configuration.\n"); - } - } - return err; - } - const char *inputNodeName = "input_2"; const char *outputNodeName[] = { "dense_3/Softmax" }; - mv_engine_config_set_string_attribute( - handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH, IC_TFLITE_WEIGHT_PATH); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_DATA_TYPE, - MV_INFERENCE_DATA_FLOAT32); - - mv_engine_config_set_string_attribute( - handle, MV_INFERENCE_MODEL_USER_FILE_PATH, IC_LABEL_PATH); - - mv_engine_config_set_double_attribute(handle, MV_INFERENCE_MODEL_MEAN_VALUE, - 127.0); - - mv_engine_config_set_double_attribute(handle, MV_INFERENCE_MODEL_STD_VALUE, - 127.0); - - mv_engine_config_set_double_attribute( - handle, MV_INFERENCE_CONFIDENCE_THRESHOLD, 0.6); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_BACKEND_TYPE, - MV_INFERENCE_BACKEND_ARMNN); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_TARGET_TYPE, - MV_INFERENCE_TARGET_CPU); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_TENSOR_WIDTH, - 224); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_TENSOR_HEIGHT, - 224); - - mv_engine_config_set_int_attribute(handle, - MV_INFERENCE_INPUT_TENSOR_CHANNELS, 3); - - mv_engine_config_set_string_attribute(handle, MV_INFERENCE_INPUT_NODE_NAME, - inputNodeName); - - mv_engine_config_set_array_string_attribute( - handle, MV_INFERENCE_OUTPUT_NODE_NAMES, outputNodeName, 1); - - *engine_cfg = handle; - return err; + RET_IF_FAIL(mv_engine_config_set_string_attribute( + handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH, + IC_TFLITE_WEIGHT_PATH)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_INPUT_DATA_TYPE, MV_INFERENCE_DATA_FLOAT32)); + RET_IF_FAIL(mv_engine_config_set_string_attribute( + handle, MV_INFERENCE_MODEL_USER_FILE_PATH, IC_LABEL_PATH)); + RET_IF_FAIL(mv_engine_config_set_double_attribute( + handle, MV_INFERENCE_MODEL_MEAN_VALUE, 127.0)); + RET_IF_FAIL(mv_engine_config_set_double_attribute( + handle, MV_INFERENCE_MODEL_STD_VALUE, 127.0)); + RET_IF_FAIL(mv_engine_config_set_double_attribute( + handle, MV_INFERENCE_CONFIDENCE_THRESHOLD, 0.6)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_BACKEND_TYPE, MV_INFERENCE_BACKEND_ARMNN)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_TARGET_TYPE, MV_INFERENCE_TARGET_CPU)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_INPUT_TENSOR_WIDTH, 224)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_INPUT_TENSOR_HEIGHT, 224)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_INPUT_TENSOR_CHANNELS, 3)); + RET_IF_FAIL(mv_engine_config_set_string_attribute( + handle, MV_INFERENCE_INPUT_NODE_NAME, inputNodeName)); + RET_IF_FAIL(mv_engine_config_set_array_string_attribute( + handle, MV_INFERENCE_OUTPUT_NODE_NAMES, outputNodeName, 1)); + return MEDIA_VISION_ERROR_NONE; } -int perform_one_mobilenetv1_quant_config(mv_engine_config_h *engine_cfg) +int perform_one_mobilenetv1_quant_config(mv_engine_config_h handle) { - int err = MEDIA_VISION_ERROR_NONE; - - mv_engine_config_h handle = NULL; - err = mv_create_engine_config(&handle); - if (err != MEDIA_VISION_ERROR_NONE) { - printf("Fail to create engine configuration handle.\n"); - if (handle) { - int err2 = mv_destroy_engine_config(handle); - if (err2 != MEDIA_VISION_ERROR_NONE) { - printf("Fail to destroy engine configuration.\n"); - } - } - return err; - } - const char *inputNodeName = "input"; const char *outputNodeName[] = { "MobilenetV1/Predictions/Reshape_1" }; - mv_engine_config_set_string_attribute( - handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH, IC_Q_TFLITE_WEIGHT_PATH); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_DATA_TYPE, - MV_INFERENCE_DATA_UINT8); - - mv_engine_config_set_string_attribute( - handle, MV_INFERENCE_MODEL_USER_FILE_PATH, IC_Q_LABEL_PATH); - - mv_engine_config_set_double_attribute(handle, MV_INFERENCE_MODEL_MEAN_VALUE, - 0.0); - - mv_engine_config_set_double_attribute(handle, MV_INFERENCE_MODEL_STD_VALUE, - 1.0); - - mv_engine_config_set_double_attribute( - handle, MV_INFERENCE_CONFIDENCE_THRESHOLD, 0.6); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_BACKEND_TYPE, - MV_INFERENCE_BACKEND_ONE); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_TARGET_TYPE, - MV_INFERENCE_TARGET_CPU); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_TENSOR_WIDTH, - 224); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_TENSOR_HEIGHT, - 224); - - mv_engine_config_set_int_attribute(handle, - MV_INFERENCE_INPUT_TENSOR_CHANNELS, 3); - - mv_engine_config_set_string_attribute(handle, MV_INFERENCE_INPUT_NODE_NAME, - inputNodeName); - - mv_engine_config_set_array_string_attribute( - handle, MV_INFERENCE_OUTPUT_NODE_NAMES, outputNodeName, 1); - - *engine_cfg = handle; - return err; + RET_IF_FAIL(mv_engine_config_set_string_attribute( + handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH, + IC_Q_TFLITE_WEIGHT_PATH)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_INPUT_DATA_TYPE, MV_INFERENCE_DATA_UINT8)); + RET_IF_FAIL(mv_engine_config_set_string_attribute( + handle, MV_INFERENCE_MODEL_USER_FILE_PATH, IC_Q_LABEL_PATH)); + RET_IF_FAIL(mv_engine_config_set_double_attribute( + handle, MV_INFERENCE_MODEL_MEAN_VALUE, 0.0)); + RET_IF_FAIL(mv_engine_config_set_double_attribute( + handle, MV_INFERENCE_MODEL_STD_VALUE, 1.0)); + RET_IF_FAIL(mv_engine_config_set_double_attribute( + handle, MV_INFERENCE_CONFIDENCE_THRESHOLD, 0.6)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_BACKEND_TYPE, MV_INFERENCE_BACKEND_ONE)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_TARGET_TYPE, MV_INFERENCE_TARGET_CPU)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_INPUT_TENSOR_WIDTH, 224)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_INPUT_TENSOR_HEIGHT, 224)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_INPUT_TENSOR_CHANNELS, 3)); + RET_IF_FAIL(mv_engine_config_set_string_attribute( + handle, MV_INFERENCE_INPUT_NODE_NAME, inputNodeName)); + RET_IF_FAIL(mv_engine_config_set_array_string_attribute( + handle, MV_INFERENCE_OUTPUT_NODE_NAMES, outputNodeName, 1)); + return MEDIA_VISION_ERROR_NONE; } -int perform_vivante_inceptionv3_config(mv_engine_config_h *engine_cfg) +int perform_vivante_inceptionv3_config(mv_engine_config_h handle) { - int err = MEDIA_VISION_ERROR_NONE; - - mv_engine_config_h handle = NULL; - err = mv_create_engine_config(&handle); - if (err != MEDIA_VISION_ERROR_NONE) { - printf("Fail to create engine configuration handle.\n"); - if (handle) { - int err2 = mv_destroy_engine_config(handle); - if (err2 != MEDIA_VISION_ERROR_NONE) { - printf("Fail to destroy engine configuration.\n"); - } - } - return err; - } - const char *inputNodeName = "input"; const char *outputNodeName[] = { "InceptionV3/Predictions/Peshape_1" }; - mv_engine_config_set_string_attribute(handle, - MV_INFERENCE_MODEL_WEIGHT_FILE_PATH, - IC_VIVANTE_WEIGHT_PATH); + RET_IF_FAIL(mv_engine_config_set_string_attribute( + handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH, + IC_VIVANTE_WEIGHT_PATH)); - mv_engine_config_set_string_attribute( + RET_IF_FAIL(mv_engine_config_set_string_attribute( handle, MV_INFERENCE_MODEL_CONFIGURATION_FILE_PATH, - IC_VIVANTE_CONFIG_PATH); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_DATA_TYPE, - MV_INFERENCE_DATA_UINT8); - - mv_engine_config_set_string_attribute( - handle, MV_INFERENCE_MODEL_USER_FILE_PATH, IC_VIVANTE_LABEL_PATH); - - mv_engine_config_set_double_attribute(handle, MV_INFERENCE_MODEL_MEAN_VALUE, - 0.0); - - mv_engine_config_set_double_attribute(handle, MV_INFERENCE_MODEL_STD_VALUE, - 1.0); - - mv_engine_config_set_double_attribute( - handle, MV_INFERENCE_CONFIDENCE_THRESHOLD, 0.6); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_BACKEND_TYPE, - MV_INFERENCE_BACKEND_MLAPI); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_TARGET_DEVICE_TYPE, - MV_INFERENCE_TARGET_DEVICE_CUSTOM); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_TENSOR_WIDTH, - 299); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_TENSOR_HEIGHT, - 299); - - mv_engine_config_set_int_attribute(handle, - MV_INFERENCE_INPUT_TENSOR_CHANNELS, 3); - - mv_engine_config_set_string_attribute(handle, MV_INFERENCE_INPUT_NODE_NAME, - inputNodeName); - - mv_engine_config_set_array_string_attribute( - handle, MV_INFERENCE_OUTPUT_NODE_NAMES, outputNodeName, 1); - - *engine_cfg = handle; - return err; + IC_VIVANTE_CONFIG_PATH)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_INPUT_DATA_TYPE, MV_INFERENCE_DATA_UINT8)); + RET_IF_FAIL(mv_engine_config_set_string_attribute( + handle, MV_INFERENCE_MODEL_USER_FILE_PATH, IC_VIVANTE_LABEL_PATH)); + RET_IF_FAIL(mv_engine_config_set_double_attribute( + handle, MV_INFERENCE_MODEL_MEAN_VALUE, 0.0)); + RET_IF_FAIL(mv_engine_config_set_double_attribute( + handle, MV_INFERENCE_MODEL_STD_VALUE, 1.0)); + RET_IF_FAIL(mv_engine_config_set_double_attribute( + handle, MV_INFERENCE_CONFIDENCE_THRESHOLD, 0.6)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_BACKEND_TYPE, MV_INFERENCE_BACKEND_MLAPI)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_TARGET_DEVICE_TYPE, + MV_INFERENCE_TARGET_DEVICE_CUSTOM)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_INPUT_TENSOR_WIDTH, 299)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_INPUT_TENSOR_HEIGHT, 299)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_INPUT_TENSOR_CHANNELS, 3)); + RET_IF_FAIL(mv_engine_config_set_string_attribute( + handle, MV_INFERENCE_INPUT_NODE_NAME, inputNodeName)); + RET_IF_FAIL(mv_engine_config_set_array_string_attribute( + handle, MV_INFERENCE_OUTPUT_NODE_NAMES, outputNodeName, 1)); + return MEDIA_VISION_ERROR_NONE; } -int perform_opencv_caffe_squeezenet_config(mv_engine_config_h *engine_cfg) +int perform_opencv_caffe_squeezenet_config(mv_engine_config_h handle) { - int err = MEDIA_VISION_ERROR_NONE; - - mv_engine_config_h handle = NULL; - err = mv_create_engine_config(&handle); - if (err != MEDIA_VISION_ERROR_NONE) { - printf("Fail to create engine configuration handle.\n"); - if (handle) { - int err2 = mv_destroy_engine_config(handle); - if (err2 != MEDIA_VISION_ERROR_NONE) { - printf("Fail to destroy engine configuration.\n"); - } - } - return err; - } - const char *inputNodeName = "data"; const char *outputNodeName[] = { "prob" }; - mv_engine_config_set_string_attribute(handle, - MV_INFERENCE_MODEL_WEIGHT_FILE_PATH, - IC_OPENCV_WEIGHT_CAFFE_PATH); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_DATA_TYPE, - MV_INFERENCE_DATA_FLOAT32); - - mv_engine_config_set_string_attribute( + RET_IF_FAIL(mv_engine_config_set_string_attribute( + handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH, + IC_OPENCV_WEIGHT_CAFFE_PATH)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_INPUT_DATA_TYPE, MV_INFERENCE_DATA_FLOAT32)); + RET_IF_FAIL(mv_engine_config_set_string_attribute( handle, MV_INFERENCE_MODEL_CONFIGURATION_FILE_PATH, - IC_OPENCV_CONFIG_CAFFE_PATH); - - mv_engine_config_set_string_attribute(handle, - MV_INFERENCE_MODEL_USER_FILE_PATH, - IC_OPENCV_LABEL_CAFFE_PATH); - - mv_engine_config_set_double_attribute(handle, MV_INFERENCE_MODEL_MEAN_VALUE, - 0.0); - - mv_engine_config_set_double_attribute(handle, MV_INFERENCE_MODEL_STD_VALUE, - 1.0); - - mv_engine_config_set_double_attribute( - handle, MV_INFERENCE_CONFIDENCE_THRESHOLD, 0.3); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_BACKEND_TYPE, - MV_INFERENCE_BACKEND_OPENCV); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_TARGET_TYPE, - MV_INFERENCE_TARGET_CPU); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_TENSOR_WIDTH, - 227); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_TENSOR_HEIGHT, - 227); - - mv_engine_config_set_int_attribute(handle, - MV_INFERENCE_INPUT_TENSOR_CHANNELS, 3); - - mv_engine_config_set_string_attribute(handle, MV_INFERENCE_INPUT_NODE_NAME, - inputNodeName); - - mv_engine_config_set_array_string_attribute( - handle, MV_INFERENCE_OUTPUT_NODE_NAMES, outputNodeName, 1); - - *engine_cfg = handle; - return err; -} - - -int perform_hosted_tflite_mobilenetv1_224_config(mv_engine_config_h *engine_cfg) -{ - int err = MEDIA_VISION_ERROR_NONE; - - mv_engine_config_h handle = NULL; - err = mv_create_engine_config(&handle); - if (err != MEDIA_VISION_ERROR_NONE) { - printf("Fail to create engine configuration handle.\n"); - if (handle) { - int err2 = mv_destroy_engine_config(handle); - if (err2 != MEDIA_VISION_ERROR_NONE) { - printf("Fail to destroy engine configuration.\n"); - } - } - return err; - } - - mv_engine_config_set_string_attribute( - handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH, - IC_TFLITE_WEIGHT_MOBILENET_V1_224_PATH); - - mv_engine_config_set_string_attribute( - handle, MV_INFERENCE_MODEL_USER_FILE_PATH, - IC_LABEL_MOBILENET_V1_224_PATH); - - mv_engine_config_set_int_attribute( - handle, MV_INFERENCE_BACKEND_TYPE, - MV_INFERENCE_BACKEND_TFLITE); - - mv_engine_config_set_int_attribute( - handle, MV_INFERENCE_TARGET_TYPE, - MV_INFERENCE_TARGET_CPU); - - *engine_cfg = handle; - return err; -} - -int perform_hosted_tflite_mobilenetv2_224_config(mv_engine_config_h *engine_cfg) -{ - int err = MEDIA_VISION_ERROR_NONE; - - mv_engine_config_h handle = NULL; - err = mv_create_engine_config(&handle); - if (err != MEDIA_VISION_ERROR_NONE) { - printf("Fail to create engine configuration handle.\n"); - if (handle) { - int err2 = mv_destroy_engine_config(handle); - if (err2 != MEDIA_VISION_ERROR_NONE) { - printf("Fail to destroy engine configuration.\n"); - } - } - return err; - } - - mv_engine_config_set_string_attribute( - handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH, - IC_TFLITE_WEIGHT_MOBILENET_V2_224_PATH); - - mv_engine_config_set_string_attribute( - handle, MV_INFERENCE_MODEL_USER_FILE_PATH, - IC_LABEL_MOBILENET_V2_224_PATH); - - mv_engine_config_set_int_attribute( - handle, MV_INFERENCE_BACKEND_TYPE, - MV_INFERENCE_BACKEND_TFLITE); - - mv_engine_config_set_int_attribute( - handle, MV_INFERENCE_TARGET_TYPE, - MV_INFERENCE_TARGET_CPU); - - *engine_cfg = handle; - return err; -} - -int perform_hosted_tflite_densenet_224_config(mv_engine_config_h *engine_cfg) -{ - int err = MEDIA_VISION_ERROR_NONE; - - mv_engine_config_h handle = NULL; - err = mv_create_engine_config(&handle); - if (err != MEDIA_VISION_ERROR_NONE) { - printf("Fail to create engine configuration handle.\n"); - if (handle) { - int err2 = mv_destroy_engine_config(handle); - if (err2 != MEDIA_VISION_ERROR_NONE) { - printf("Fail to destroy engine configuration.\n"); - } - } - return err; - } - - mv_engine_config_set_string_attribute( - handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH, - IC_TFLITE_WEIGHT_DENSENET_224_PATH); - - mv_engine_config_set_string_attribute( - handle, MV_INFERENCE_MODEL_USER_FILE_PATH, - IC_LABEL_DENSENET_224_PATH); - - mv_engine_config_set_int_attribute( - handle, MV_INFERENCE_BACKEND_TYPE, - MV_INFERENCE_BACKEND_TFLITE); - - mv_engine_config_set_int_attribute( - handle, MV_INFERENCE_TARGET_TYPE, - MV_INFERENCE_TARGET_CPU); - - *engine_cfg = handle; - return err; -} - -int perform_hosted_tflite_inception_resnet_299_config(mv_engine_config_h *engine_cfg) -{ - int err = MEDIA_VISION_ERROR_NONE; - - mv_engine_config_h handle = NULL; - err = mv_create_engine_config(&handle); - if (err != MEDIA_VISION_ERROR_NONE) { - printf("Fail to create engine configuration handle.\n"); - if (handle) { - int err2 = mv_destroy_engine_config(handle); - if (err2 != MEDIA_VISION_ERROR_NONE) { - printf("Fail to destroy engine configuration.\n"); - } - } - return err; - } - - mv_engine_config_set_string_attribute( - handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH, - IC_TFLITE_WEIGHT_INCEPTION_RESENET_299_PATH); - - mv_engine_config_set_string_attribute( - handle, MV_INFERENCE_MODEL_USER_FILE_PATH, - IC_LABEL_INCEPTION_RESENET_299_PATH); - - mv_engine_config_set_int_attribute( - handle, MV_INFERENCE_BACKEND_TYPE, - MV_INFERENCE_BACKEND_TFLITE); - - mv_engine_config_set_int_attribute( - handle, MV_INFERENCE_TARGET_TYPE, - MV_INFERENCE_TARGET_CPU); - - *engine_cfg = handle; - return err; -} - -int perform_hosted_tflite_inception_v3_config(mv_engine_config_h *engine_cfg) -{ - int err = MEDIA_VISION_ERROR_NONE; - - mv_engine_config_h handle = NULL; - err = mv_create_engine_config(&handle); - if (err != MEDIA_VISION_ERROR_NONE) { - printf("Fail to create engine configuration handle.\n"); - if (handle) { - int err2 = mv_destroy_engine_config(handle); - if (err2 != MEDIA_VISION_ERROR_NONE) { - printf("Fail to destroy engine configuration.\n"); - } - } - return err; - } - - mv_engine_config_set_string_attribute( - handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH, - IC_TFLITE_WEIGHT_INCEPTION_V3_299_PATH); - - mv_engine_config_set_string_attribute( - handle, MV_INFERENCE_MODEL_USER_FILE_PATH, - IC_LABEL_INCEPTION_V3_299_PATH); - - mv_engine_config_set_int_attribute( - handle, MV_INFERENCE_BACKEND_TYPE, - MV_INFERENCE_BACKEND_TFLITE); - - mv_engine_config_set_int_attribute( - handle, MV_INFERENCE_TARGET_TYPE, - MV_INFERENCE_TARGET_CPU); - - *engine_cfg = handle; - return err; -} - -int perform_hosted_tflite_inception_v4_config(mv_engine_config_h *engine_cfg) -{ - int err = MEDIA_VISION_ERROR_NONE; - - mv_engine_config_h handle = NULL; - err = mv_create_engine_config(&handle); - if (err != MEDIA_VISION_ERROR_NONE) { - printf("Fail to create engine configuration handle.\n"); - if (handle) { - int err2 = mv_destroy_engine_config(handle); - if (err2 != MEDIA_VISION_ERROR_NONE) { - printf("Fail to destroy engine configuration.\n"); - } - } - return err; - } - - mv_engine_config_set_string_attribute( - handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH, - IC_TFLITE_WEIGHT_INCEPTION_V4_299_PATH); - - mv_engine_config_set_string_attribute( - handle, MV_INFERENCE_MODEL_USER_FILE_PATH, - IC_LABEL_INCEPTION_V4_299_PATH); - - mv_engine_config_set_int_attribute( - handle, MV_INFERENCE_BACKEND_TYPE, - MV_INFERENCE_BACKEND_TFLITE); - - mv_engine_config_set_int_attribute( - handle, MV_INFERENCE_TARGET_TYPE, - MV_INFERENCE_TARGET_CPU); - - *engine_cfg = handle; - return err; -} - -int perform_hosted_tflite_nasnet_config(mv_engine_config_h *engine_cfg) -{ - int err = MEDIA_VISION_ERROR_NONE; - - mv_engine_config_h handle = NULL; - err = mv_create_engine_config(&handle); - if (err != MEDIA_VISION_ERROR_NONE) { - printf("Fail to create engine configuration handle.\n"); - if (handle) { - int err2 = mv_destroy_engine_config(handle); - if (err2 != MEDIA_VISION_ERROR_NONE) { - printf("Fail to destroy engine configuration.\n"); - } - } - return err; - } - - mv_engine_config_set_string_attribute( - handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH, - IC_TFLITE_WEIGHT_NASNET_224_PATH); - - mv_engine_config_set_string_attribute( - handle, MV_INFERENCE_MODEL_USER_FILE_PATH, - IC_LABEL_NASNET_224_PATH); - - mv_engine_config_set_int_attribute( - handle, MV_INFERENCE_BACKEND_TYPE, - MV_INFERENCE_BACKEND_TFLITE); - - mv_engine_config_set_int_attribute( - handle, MV_INFERENCE_TARGET_TYPE, - MV_INFERENCE_TARGET_CPU); - - *engine_cfg = handle; - return err; -} - -int perform_hosted_tflite_mnasnet_config(mv_engine_config_h *engine_cfg) -{ - int err = MEDIA_VISION_ERROR_NONE; - - mv_engine_config_h handle = NULL; - err = mv_create_engine_config(&handle); - if (err != MEDIA_VISION_ERROR_NONE) { - printf("Fail to create engine configuration handle.\n"); - if (handle) { - int err2 = mv_destroy_engine_config(handle); - if (err2 != MEDIA_VISION_ERROR_NONE) { - printf("Fail to destroy engine configuration.\n"); - } - } - return err; - } - - mv_engine_config_set_string_attribute( - handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH, - IC_TFLITE_WEIGHT_MNASNET_224_PATH); - - mv_engine_config_set_string_attribute( - handle, MV_INFERENCE_MODEL_USER_FILE_PATH, - IC_LABEL_MNASNET_224_PATH); - - mv_engine_config_set_int_attribute( - handle, MV_INFERENCE_BACKEND_TYPE, - MV_INFERENCE_BACKEND_TFLITE); - - mv_engine_config_set_int_attribute( - handle, MV_INFERENCE_TARGET_TYPE, - MV_INFERENCE_TARGET_CPU); - - *engine_cfg = handle; - return err; -} - -int perform_hosted_tflite_resnet_config(mv_engine_config_h *engine_cfg) -{ - int err = MEDIA_VISION_ERROR_NONE; - - mv_engine_config_h handle = NULL; - err = mv_create_engine_config(&handle); - if (err != MEDIA_VISION_ERROR_NONE) { - printf("Fail to create engine configuration handle.\n"); - if (handle) { - int err2 = mv_destroy_engine_config(handle); - if (err2 != MEDIA_VISION_ERROR_NONE) { - printf("Fail to destroy engine configuration.\n"); - } - } - return err; - } - - mv_engine_config_set_string_attribute( - handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH, - IC_TFLITE_WEIGHT_RESNET_V2_299_PATH); - - mv_engine_config_set_string_attribute( - handle, MV_INFERENCE_MODEL_USER_FILE_PATH, - IC_LABEL_RESNET_V2_299_PATH); - - mv_engine_config_set_int_attribute( - handle, MV_INFERENCE_BACKEND_TYPE, - MV_INFERENCE_BACKEND_TFLITE); - - mv_engine_config_set_int_attribute( - handle, MV_INFERENCE_TARGET_TYPE, - MV_INFERENCE_TARGET_CPU); - - *engine_cfg = handle; - return err; -} - -int perform_hosted_tflite_squeezenet_config(mv_engine_config_h *engine_cfg) -{ - int err = MEDIA_VISION_ERROR_NONE; - - mv_engine_config_h handle = NULL; - err = mv_create_engine_config(&handle); - if (err != MEDIA_VISION_ERROR_NONE) { - printf("Fail to create engine configuration handle.\n"); - if (handle) { - int err2 = mv_destroy_engine_config(handle); - if (err2 != MEDIA_VISION_ERROR_NONE) { - printf("Fail to destroy engine configuration.\n"); - } - } - return err; - } - - mv_engine_config_set_string_attribute( - handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH, - IC_TFLITE_WEIGHT_SQUEEZENET_224_PATH); - - mv_engine_config_set_string_attribute( - handle, MV_INFERENCE_MODEL_USER_FILE_PATH, - IC_LABEL_SQUEEZENET_224_PATH); - - mv_engine_config_set_int_attribute( - handle, MV_INFERENCE_BACKEND_TYPE, - MV_INFERENCE_BACKEND_TFLITE); - - mv_engine_config_set_int_attribute( - handle, MV_INFERENCE_TARGET_TYPE, - MV_INFERENCE_TARGET_CPU); - - *engine_cfg = handle; - return err; -} - -int perform_image_classification() -{ - int err = MEDIA_VISION_ERROR_NONE; - - int sel_opt = 0; - const char *names[] = { "Configuration", - "TFLite(cpu + Mobilenet)", - "OpenCV(cpu + Squeezenet)", - "ARMNN(cpu + Mobilenet)", - "ONE(cpu + Mobilenet_Q)", - "Vivante(NPU + Inceptionv3)", - "Hosted: TFLite(cpu + Mobilenet V1)", // 7 - "Hosted: TFLite(cpu + Mobilenet V2)", - "Hosted: TFLite(cpu + Densenet)", - "Hosted: TFLite(cpu + Inception Resnet)", - "Hosted: TFLite(cpu + Inception V3)", - "Hosted: TFLite(cpu + Inception V4)", - "Hosted: TFLite(cpu + Nasnet)", - "Hosted: TFLite(cpu + Mnasnet)", - "Hosted: TFLite(cpu + Resnet)", - "Hosted: TFLite(cpu + Squeezenet)", //16 - "Prepare", - "Run", - "Back" }; - - mv_engine_config_h engine_cfg = NULL; - mv_inference_h infer = NULL; - mv_source_h mvSource = NULL; - - while (sel_opt == 0) { - sel_opt = show_menu_linear("Select Action:", names, ARRAY_SIZE(names)); - switch (sel_opt) { - case 1: { - //perform configuration - if (engine_cfg) { - int err2 = mv_destroy_engine_config(engine_cfg); - if (err2 != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy engine_cfg [err:%i]\n", err2); - engine_cfg = NULL; - } - - err = perform_configuration(&engine_cfg); - } break; - case 2: { - // perform TFLite - if (engine_cfg) { - int err2 = mv_destroy_engine_config(engine_cfg); - if (err2 != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy engine_cfg [err:%i]\n", err2); - engine_cfg = NULL; - } - - err = perform_tflite_mobilenetv1_config(&engine_cfg); - } break; - - case 3: { - // perform OpenCV - if (engine_cfg) { - int err2 = mv_destroy_engine_config(engine_cfg); - if (err2 != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy engine_cfg [err:%i]\n", err2); - engine_cfg = NULL; - } - - err = perform_opencv_caffe_squeezenet_config(&engine_cfg); - } break; - case 4: { - // perform ARMNN - if (engine_cfg) { - int err2 = mv_destroy_engine_config(engine_cfg); - if (err2 != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy engine_cfg [err:%i]\n", err2); - } - - err = perform_armnn_mobilenetv1_config(&engine_cfg); - } break; - case 5: { - // perform ONE(On-device Neural Engine) - if (engine_cfg) { - int err2 = mv_destroy_engine_config(engine_cfg); - if (err2 != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy engine_cfg [err:%i]\n", err2); - } - - err = perform_one_mobilenetv1_quant_config(&engine_cfg); - } break; - case 6: { - // perform Vivante - if (engine_cfg) { - int err2 = mv_destroy_engine_config(engine_cfg); - if (err2 != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy engine_cfg [err:%i]\n", err2); - } - - err = perform_vivante_inceptionv3_config(&engine_cfg); - } break; - case 7: { - // perform hosted mobilenetv1 - if (engine_cfg) { - int err2 = mv_destroy_engine_config(engine_cfg); - if (err2 != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy engine_cfg [err:%i]\n", err2); - } - - err = perform_hosted_tflite_mobilenetv1_224_config(&engine_cfg); - } break; - case 8: { - // perform hosted mobilenetv2 - if (engine_cfg) { - int err2 = mv_destroy_engine_config(engine_cfg); - if (err2 != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy engine_cfg [err:%i]\n", err2); - } - - err = perform_hosted_tflite_mobilenetv2_224_config(&engine_cfg); - } break; - case 9: { - // perform hosted densenet - if (engine_cfg) { - int err2 = mv_destroy_engine_config(engine_cfg); - if (err2 != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy engine_cfg [err:%i]\n", err2); - } - - err = perform_hosted_tflite_densenet_224_config(&engine_cfg); - } break; - case 10: { - // perform hosted inception resnet - if (engine_cfg) { - int err2 = mv_destroy_engine_config(engine_cfg); - if (err2 != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy engine_cfg [err:%i]\n", err2); - } - - err = perform_hosted_tflite_inception_resnet_299_config(&engine_cfg); - } break; - case 11: { - // perform hosted inception v3 - if (engine_cfg) { - int err2 = mv_destroy_engine_config(engine_cfg); - if (err2 != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy engine_cfg [err:%i]\n", err2); - } - - err = perform_hosted_tflite_inception_v3_config(&engine_cfg); - } break; - case 12: { - // perform hosted inception v4 - if (engine_cfg) { - int err2 = mv_destroy_engine_config(engine_cfg); - if (err2 != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy engine_cfg [err:%i]\n", err2); - } - - err = perform_hosted_tflite_inception_v4_config(&engine_cfg); - } break; - case 13: { - // perform hosted nasnet - if (engine_cfg) { - int err2 = mv_destroy_engine_config(engine_cfg); - if (err2 != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy engine_cfg [err:%i]\n", err2); - } - - err = perform_hosted_tflite_nasnet_config(&engine_cfg); - } break; - case 14: { - // perform hosted mnasnet - if (engine_cfg) { - int err2 = mv_destroy_engine_config(engine_cfg); - if (err2 != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy engine_cfg [err:%i]\n", err2); - } - - err = perform_hosted_tflite_mnasnet_config(&engine_cfg); - } break; - case 15: { - // perform hosted resnet - if (engine_cfg) { - int err2 = mv_destroy_engine_config(engine_cfg); - if (err2 != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy engine_cfg [err:%i]\n", err2); - } - - err = perform_hosted_tflite_resnet_config(&engine_cfg); - } break; - case 16: { - // perform hosted squeezenet - if (engine_cfg) { - int err2 = mv_destroy_engine_config(engine_cfg); - if (err2 != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy engine_cfg [err:%i]\n", err2); - } - - err = perform_hosted_tflite_squeezenet_config(&engine_cfg); - } break; - case 17: { - //create - configure - prepare - if (infer) { - int err2 = mv_inference_destroy(infer); - if (err2 != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy inference handle [err:%i]\n", err2); - infer = NULL; - } - - // inference - // create handle - err = mv_inference_create(&infer); - if (err != MEDIA_VISION_ERROR_NONE) { - printf("Fail to create inference handle [err:%i]\n", err); - break; - } - - // configure - err = mv_inference_configure(infer, engine_cfg); - if (err != MEDIA_VISION_ERROR_NONE) { - printf("Fail to configure inference handle\n"); - break; - } - - // prepare - err = mv_inference_prepare(infer); - if (err != MEDIA_VISION_ERROR_NONE) { - printf("Fail to prepare inference handle."); - break; - } - } break; - case 18: { - if (mvSource) { - int err2 = mv_destroy_source(mvSource); - if (err2 != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy mvSource.\n"); - mvSource = NULL; - } - - char *in_file_name = NULL; - /* Load media source */ - while (input_string("Input file name to be inferred:", 1024, - &(in_file_name)) == -1) - printf("Incorrect input! Try again.\n"); - - err = mv_create_source(&mvSource); - if (err != MEDIA_VISION_ERROR_NONE) { - printf("Fail to create mvSource.\n"); - free(in_file_name); - break; - } - - err = load_mv_source_from_file(in_file_name, mvSource); - if (MEDIA_VISION_ERROR_NONE != err) { - int err2 = mv_destroy_source(mvSource); - if (err2 != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy mvSource. error code:%i\n", err2); - mvSource = NULL; - free(in_file_name); - break; - } - free(in_file_name); - - struct timespec s_tspec; - struct timespec e_tspec; - - clock_gettime(CLOCK_MONOTONIC, &s_tspec); - - // Run - err = mv_inference_image_classify(mvSource, infer, NULL, - _image_classified_cb, NULL); - - clock_gettime(CLOCK_MONOTONIC, &e_tspec); - - struct timespec diffspec = diff(s_tspec, e_tspec); - unsigned long timeDiff = gettotalmillisec(diffspec); - printf("elapsed time : %lu(ms)\n", timeDiff); - - } break; - case 19: { - //perform destroy - if (engine_cfg) { - err = mv_destroy_engine_config(engine_cfg); - if (err != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy engine_cfg [err:%i]\n", err); - engine_cfg = NULL; - } - - if (infer) { - err = mv_inference_destroy(infer); - if (err != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy inference handle [err:%i]\n", err); - infer = NULL; - } - - if (mvSource) { - err = mv_destroy_source(mvSource); - if (err != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy mvSource [err:%i]\n", err); - mvSource = NULL; - } - } break; - default: - printf("Invalid option.\n"); - sel_opt = 0; - continue; - } - - int do_another = 0; - if (err != MEDIA_VISION_ERROR_NONE) { - printf("ERROR: Action is finished with error code:%i\n", err); - } - - sel_opt = 0; - while (sel_opt == 0) { - sel_opt = show_menu_yes_or_no("Run Image Classification again?: "); - switch (sel_opt) { - case 1: - do_another = 1; - break; - case 2: - do_another = 0; - break; - default: - printf("Invalid option.\n"); - sel_opt = 0; - } - } - - sel_opt = (do_another == 1) ? 0 : 1; - } - - if (engine_cfg) { - err = mv_destroy_engine_config(engine_cfg); - if (err != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy engine_cfg [err:%i]\n", err); - engine_cfg = NULL; - } - - if (infer) { - err = mv_inference_destroy(infer); - if (err != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy inference handle [err:%i]\n", err); - infer = NULL; - } - - if (mvSource) { - err = mv_destroy_source(mvSource); - if (err != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy mvSource [err:%i]\n", err); - mvSource = NULL; - } - + IC_OPENCV_CONFIG_CAFFE_PATH)); + RET_IF_FAIL(mv_engine_config_set_string_attribute( + handle, MV_INFERENCE_MODEL_USER_FILE_PATH, + IC_OPENCV_LABEL_CAFFE_PATH)); + RET_IF_FAIL(mv_engine_config_set_double_attribute( + handle, MV_INFERENCE_MODEL_MEAN_VALUE, 0.0)); + RET_IF_FAIL(mv_engine_config_set_double_attribute( + handle, MV_INFERENCE_MODEL_STD_VALUE, 1.0)); + RET_IF_FAIL(mv_engine_config_set_double_attribute( + handle, MV_INFERENCE_CONFIDENCE_THRESHOLD, 0.3)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_BACKEND_TYPE, MV_INFERENCE_BACKEND_OPENCV)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_TARGET_TYPE, MV_INFERENCE_TARGET_CPU)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_INPUT_TENSOR_WIDTH, 227)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_INPUT_TENSOR_HEIGHT, 227)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_INPUT_TENSOR_CHANNELS, 3)); + RET_IF_FAIL(mv_engine_config_set_string_attribute( + handle, MV_INFERENCE_INPUT_NODE_NAME, inputNodeName)); + RET_IF_FAIL(mv_engine_config_set_array_string_attribute( + handle, MV_INFERENCE_OUTPUT_NODE_NAMES, outputNodeName, 1)); return MEDIA_VISION_ERROR_NONE; } -/* - * - * Object Detection - * - */ -int perform_tflite_mobilenetv1ssd_config(mv_engine_config_h *engine_cfg) -{ - int err = MEDIA_VISION_ERROR_NONE; - - mv_engine_config_h handle = NULL; - err = mv_create_engine_config(&handle); - if (err != MEDIA_VISION_ERROR_NONE) { - printf("Fail to create engine configuration handle.\n"); - if (handle) { - int err2 = mv_destroy_engine_config(handle); - if (err2 != MEDIA_VISION_ERROR_NONE) { - printf("Fail to destroy engine configuration.\n"); - } - } - return err; - } - - const char *inputNodeName = "normalized_input_image_tensor"; - const char *outputNodeName[] = { "TFLite_Detection_PostProcess", - "TFLite_Detection_PostProcess:1", - "TFLite_Detection_PostProcess:2", - "TFLite_Detection_PostProcess:3" }; - - mv_engine_config_set_string_attribute( - handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH, OD_TFLITE_WEIGHT_PATH); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_DATA_TYPE, - MV_INFERENCE_DATA_FLOAT32); - - mv_engine_config_set_string_attribute( - handle, MV_INFERENCE_MODEL_USER_FILE_PATH, OD_LABEL_PATH); - - mv_engine_config_set_double_attribute(handle, MV_INFERENCE_MODEL_MEAN_VALUE, - 127.5); - - mv_engine_config_set_double_attribute(handle, MV_INFERENCE_MODEL_STD_VALUE, - 127.5); - - mv_engine_config_set_double_attribute( - handle, MV_INFERENCE_CONFIDENCE_THRESHOLD, 0.3); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_BACKEND_TYPE, - MV_INFERENCE_BACKEND_TFLITE); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_TARGET_TYPE, - MV_INFERENCE_TARGET_CPU); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_TENSOR_WIDTH, - 300); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_TENSOR_HEIGHT, - 300); - - mv_engine_config_set_int_attribute(handle, - MV_INFERENCE_INPUT_TENSOR_CHANNELS, 3); - - mv_engine_config_set_string_attribute(handle, MV_INFERENCE_INPUT_NODE_NAME, - inputNodeName); - - mv_engine_config_set_array_string_attribute( - handle, MV_INFERENCE_OUTPUT_NODE_NAMES, outputNodeName, 4); - - *engine_cfg = handle; - return err; -} - -int perform_opencv_mobilenetv1ssd_config(mv_engine_config_h *engine_cfg) -{ - int err = MEDIA_VISION_ERROR_NONE; - - mv_engine_config_h handle = NULL; - err = mv_create_engine_config(&handle); - if (err != MEDIA_VISION_ERROR_NONE) { - printf("Fail to create engine configuration handle.\n"); - if (handle) { - int err2 = mv_destroy_engine_config(handle); - if (err2 != MEDIA_VISION_ERROR_NONE) { - printf("Fail to destroy engine configuration.\n"); - } - } - return err; - } - - const char *inputNodeName = "data"; - const char *outputNodeName[1] = { "detection_out" }; - - mv_engine_config_set_string_attribute(handle, - MV_INFERENCE_MODEL_WEIGHT_FILE_PATH, - OD_OPENCV_WEIGHT_CAFFE_PATH); - - mv_engine_config_set_string_attribute( - handle, MV_INFERENCE_MODEL_CONFIGURATION_FILE_PATH, - OD_OPENCV_CONFIG_CAFFE_PATH); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_DATA_TYPE, - MV_INFERENCE_DATA_FLOAT32); - - mv_engine_config_set_string_attribute(handle, - MV_INFERENCE_MODEL_USER_FILE_PATH, - OD_OPENCV_LABEL_CAFFE_PATH); - - mv_engine_config_set_double_attribute(handle, MV_INFERENCE_MODEL_MEAN_VALUE, - 127.5); - - mv_engine_config_set_double_attribute(handle, MV_INFERENCE_MODEL_STD_VALUE, - 127.5); - - mv_engine_config_set_double_attribute( - handle, MV_INFERENCE_CONFIDENCE_THRESHOLD, 0.3); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_BACKEND_TYPE, - MV_INFERENCE_BACKEND_OPENCV); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_TARGET_TYPE, - MV_INFERENCE_TARGET_CPU); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_TENSOR_WIDTH, - 300); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_TENSOR_HEIGHT, - 300); - - mv_engine_config_set_int_attribute(handle, - MV_INFERENCE_INPUT_TENSOR_CHANNELS, 3); - - mv_engine_config_set_string_attribute(handle, MV_INFERENCE_INPUT_NODE_NAME, - inputNodeName); - - mv_engine_config_set_array_string_attribute( - handle, MV_INFERENCE_OUTPUT_NODE_NAMES, outputNodeName, 1); - - *engine_cfg = handle; - return err; -} - -int perform_armnn_mobilenetv1ssd_config(mv_engine_config_h *engine_cfg) -{ - int err = MEDIA_VISION_ERROR_NONE; - - mv_engine_config_h handle = NULL; - err = mv_create_engine_config(&handle); - if (err != MEDIA_VISION_ERROR_NONE) { - printf("Fail to create engine configuration handle.\n"); - if (handle) { - int err2 = mv_destroy_engine_config(handle); - if (err2 != MEDIA_VISION_ERROR_NONE) { - printf("Fail to destroy engine configuration.\n"); - } - } - return err; - } - - const char *inputNodeName = "normalized_input_image_tensor"; - const char *outputNodeName[] = { "TFLite_Detection_PostProcess", - "TFLite_Detection_PostProcess:1", - "TFLite_Detection_PostProcess:2", - "TFLite_Detection_PostProcess:3" }; - - mv_engine_config_set_string_attribute( - handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH, OD_TFLITE_WEIGHT_PATH); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_DATA_TYPE, - MV_INFERENCE_DATA_FLOAT32); - - mv_engine_config_set_string_attribute( - handle, MV_INFERENCE_MODEL_USER_FILE_PATH, OD_LABEL_PATH); - - mv_engine_config_set_double_attribute(handle, MV_INFERENCE_MODEL_MEAN_VALUE, - 127.5); - - mv_engine_config_set_double_attribute(handle, MV_INFERENCE_MODEL_STD_VALUE, - 127.5); - - mv_engine_config_set_double_attribute( - handle, MV_INFERENCE_CONFIDENCE_THRESHOLD, 0.3); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_BACKEND_TYPE, - MV_INFERENCE_BACKEND_ARMNN); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_TARGET_TYPE, - MV_INFERENCE_TARGET_CPU); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_TENSOR_WIDTH, - 300); - - mv_engine_config_set_int_attribute(handle, MV_INFERENCE_INPUT_TENSOR_HEIGHT, - 300); - - mv_engine_config_set_int_attribute(handle, - MV_INFERENCE_INPUT_TENSOR_CHANNELS, 3); - - mv_engine_config_set_string_attribute(handle, MV_INFERENCE_INPUT_NODE_NAME, - inputNodeName); - - mv_engine_config_set_array_string_attribute( - handle, MV_INFERENCE_OUTPUT_NODE_NAMES, outputNodeName, 4); - - *engine_cfg = handle; - return err; -} - -int perform_hosted_tflite_mobilenetv1ssd_300_config(mv_engine_config_h *engine_cfg) -{ - int err = MEDIA_VISION_ERROR_NONE; - - mv_engine_config_h handle = NULL; - err = mv_create_engine_config(&handle); - if (err != MEDIA_VISION_ERROR_NONE) { - printf("Fail to create engine configuration handle.\n"); - if (handle) { - int err2 = mv_destroy_engine_config(handle); - if (err2 != MEDIA_VISION_ERROR_NONE) { - printf("Fail to destroy engine configuration.\n"); - } - } - return err; - } - - mv_engine_config_set_string_attribute( - handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH, - OD_TFLITE_WEIGHT_MOBILENET_V1_SSD_300_PATH); - - mv_engine_config_set_string_attribute( - handle, MV_INFERENCE_MODEL_USER_FILE_PATH, - OD_LABEL_MOBILENET_V1_SSD_300_PATH); - - mv_engine_config_set_int_attribute( - handle, MV_INFERENCE_BACKEND_TYPE, - MV_INFERENCE_BACKEND_TFLITE); - - mv_engine_config_set_int_attribute( - handle, MV_INFERENCE_TARGET_TYPE, - MV_INFERENCE_TARGET_CPU); - - *engine_cfg = handle; - return err; -} - -int perform_hosted_tflite_mobilenetv2ssd_320_config(mv_engine_config_h *engine_cfg) +int perform_image_classification() { int err = MEDIA_VISION_ERROR_NONE; + mv_engine_config_h engine_cfg = NULL; + const char *names[] = { + "TFLite(cpu + Mobilenet)", + "OpenCV(cpu + Squeezenet)", + "ARMNN(cpu + Mobilenet)", + "ONE(cpu + Mobilenet_Q)", + "Vivante(NPU + Inceptionv3)", + "Hosted: TFLite(cpu + Mobilenet V1)", + "Hosted: TFLite(cpu + Mobilenet V2)", + "Hosted: TFLite(cpu + Densenet)", + "Hosted: TFLite(cpu + Inception Resnet)", + "Hosted: TFLite(cpu + Inception V3)", + "Hosted: TFLite(cpu + Inception V4)", + "Hosted: TFLite(cpu + Nasnet)", + "Hosted: TFLite(cpu + Mnasnet)", + "Hosted: TFLite(cpu + Resnet)", + "Hosted: TFLite(cpu + Squeezenet)", + }; - mv_engine_config_h handle = NULL; - err = mv_create_engine_config(&handle); - if (err != MEDIA_VISION_ERROR_NONE) { - printf("Fail to create engine configuration handle.\n"); - if (handle) { - int err2 = mv_destroy_engine_config(handle); - if (err2 != MEDIA_VISION_ERROR_NONE) { - printf("Fail to destroy engine configuration.\n"); - } - } - return err; + int sel_opt = show_menu_linear("Select Action:", names, ARRAY_SIZE(names)); + if (sel_opt <= 0 || sel_opt > ARRAY_SIZE(names)) { + printf("Invalid option"); + return -1; } - mv_engine_config_set_string_attribute( - handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH, - OD_TFLITE_WEIGHT_MOBILENET_V2_SSD_320_PATH); - - mv_engine_config_set_string_attribute( - handle, MV_INFERENCE_MODEL_USER_FILE_PATH, - OD_LABEL_MOBILENET_V2_SSD_320_PATH); + RET_IF_FAIL(mv_create_engine_config(&engine_cfg)); - mv_engine_config_set_int_attribute( - handle, MV_INFERENCE_BACKEND_TYPE, - MV_INFERENCE_BACKEND_TFLITE); + switch (sel_opt) { + case 1: { + err = perform_tflite_mobilenetv1_config(engine_cfg); + } break; + case 2: { + err = perform_opencv_caffe_squeezenet_config(engine_cfg); + } break; + case 3: { + err = perform_armnn_mobilenetv1_config(engine_cfg); + } break; + case 4: { + err = perform_one_mobilenetv1_quant_config(engine_cfg); + } break; + case 5: { + err = perform_vivante_inceptionv3_config(engine_cfg); + } break; + case 6: { + err = engine_config_user_hosted_tflite_cpu( + engine_cfg, IC_TFLITE_WEIGHT_MOBILENET_V1_224_PATH, + IC_LABEL_MOBILENET_V1_224_PATH); + } break; + case 7: { + err = engine_config_user_hosted_tflite_cpu( + engine_cfg, IC_TFLITE_WEIGHT_MOBILENET_V2_224_PATH, + IC_LABEL_MOBILENET_V2_224_PATH); + } break; + case 8: { + err = engine_config_user_hosted_tflite_cpu( + engine_cfg, IC_TFLITE_WEIGHT_DENSENET_224_PATH, + IC_LABEL_DENSENET_224_PATH); + } break; + case 9: { + err = engine_config_user_hosted_tflite_cpu( + engine_cfg, IC_TFLITE_WEIGHT_INCEPTION_RESENET_299_PATH, + IC_LABEL_INCEPTION_RESENET_299_PATH); + } break; + case 10: { + err = engine_config_user_hosted_tflite_cpu( + engine_cfg, IC_TFLITE_WEIGHT_INCEPTION_V3_299_PATH, + IC_LABEL_INCEPTION_V3_299_PATH); + } break; + case 11: { + err = engine_config_user_hosted_tflite_cpu( + engine_cfg, IC_TFLITE_WEIGHT_INCEPTION_V4_299_PATH, + IC_LABEL_INCEPTION_V4_299_PATH); + } break; + case 12: { + err = engine_config_user_hosted_tflite_cpu( + engine_cfg, IC_TFLITE_WEIGHT_NASNET_224_PATH, + IC_LABEL_NASNET_224_PATH); + } break; + case 13: { + err = engine_config_user_hosted_tflite_cpu( + engine_cfg, IC_TFLITE_WEIGHT_MNASNET_224_PATH, + IC_LABEL_MNASNET_224_PATH); + } break; + case 14: { + err = engine_config_user_hosted_tflite_cpu( + engine_cfg, IC_TFLITE_WEIGHT_RESNET_V2_299_PATH, + IC_LABEL_RESNET_V2_299_PATH); + } break; + case 15: { + err = engine_config_user_hosted_tflite_cpu( + engine_cfg, IC_TFLITE_WEIGHT_SQUEEZENET_224_PATH, + IC_LABEL_SQUEEZENET_224_PATH); + } break; + } + if (err != MEDIA_VISION_ERROR_NONE) { + printf("Fail to perform config [err:%i]\n", err); + goto clean_image_engine; + } - mv_engine_config_set_int_attribute( - handle, MV_INFERENCE_TARGET_TYPE, - MV_INFERENCE_TARGET_CPU); + err = mv_inference_task_helper(engine_cfg, TASK_IC); + if (err != MEDIA_VISION_ERROR_NONE) + printf("Fail to detect with engine [err:%i]\n", err); - *engine_cfg = handle; +clean_image_engine: + RET_IF_FAIL(mv_destroy_engine_config(engine_cfg)); return err; } -int perform_hosted_tflite_quant_efficient_config(mv_engine_config_h *engine_cfg) +/* + * + * Object Detection + * + */ +int perform_tflite_mobilenetv1ssd_config(mv_engine_config_h handle) { - int err = MEDIA_VISION_ERROR_NONE; - - mv_engine_config_h handle = NULL; - err = mv_create_engine_config(&handle); - if (err != MEDIA_VISION_ERROR_NONE) { - printf("Fail to create engine configuration handle.\n"); - if (handle) { - int err2 = mv_destroy_engine_config(handle); - if (err2 != MEDIA_VISION_ERROR_NONE) { - printf("Fail to destroy engine configuration.\n"); - } - } - return err; - } + const char *inputNodeName = "normalized_input_image_tensor"; + const char *outputNodeName[] = { "TFLite_Detection_PostProcess", + "TFLite_Detection_PostProcess:1", + "TFLite_Detection_PostProcess:2", + "TFLite_Detection_PostProcess:3" }; - mv_engine_config_set_string_attribute( - handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH, - OD_TFLITE_WEIGHT_QUANT_EFFICIENT_PATH); + RET_IF_FAIL(mv_engine_config_set_string_attribute( + handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH, + OD_TFLITE_WEIGHT_PATH)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_INPUT_DATA_TYPE, MV_INFERENCE_DATA_FLOAT32)); + RET_IF_FAIL(mv_engine_config_set_string_attribute( + handle, MV_INFERENCE_MODEL_USER_FILE_PATH, OD_LABEL_PATH)); + RET_IF_FAIL(mv_engine_config_set_double_attribute( + handle, MV_INFERENCE_MODEL_MEAN_VALUE, 127.5)); + RET_IF_FAIL(mv_engine_config_set_double_attribute( + handle, MV_INFERENCE_MODEL_STD_VALUE, 127.5)); + RET_IF_FAIL(mv_engine_config_set_double_attribute( + handle, MV_INFERENCE_CONFIDENCE_THRESHOLD, 0.3)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_BACKEND_TYPE, MV_INFERENCE_BACKEND_TFLITE)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_TARGET_TYPE, MV_INFERENCE_TARGET_CPU)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_INPUT_TENSOR_WIDTH, 300)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_INPUT_TENSOR_HEIGHT, 300)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_INPUT_TENSOR_CHANNELS, 3)); + RET_IF_FAIL(mv_engine_config_set_string_attribute( + handle, MV_INFERENCE_INPUT_NODE_NAME, inputNodeName)); + RET_IF_FAIL(mv_engine_config_set_array_string_attribute( + handle, MV_INFERENCE_OUTPUT_NODE_NAMES, outputNodeName, 4)); + return MEDIA_VISION_ERROR_NONE; +} - mv_engine_config_set_string_attribute( - handle, MV_INFERENCE_MODEL_USER_FILE_PATH, - OD_LABEL_QUANT_EFFICIENT_PATH); +int perform_opencv_mobilenetv1ssd_config(mv_engine_config_h handle) +{ + const char *inputNodeName = "data"; + const char *outputNodeName[1] = { "detection_out" }; - mv_engine_config_set_int_attribute( - handle, MV_INFERENCE_BACKEND_TYPE, - MV_INFERENCE_BACKEND_TFLITE); + RET_IF_FAIL(mv_engine_config_set_string_attribute( + handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH, + OD_OPENCV_WEIGHT_CAFFE_PATH)); + RET_IF_FAIL(mv_engine_config_set_string_attribute( + handle, MV_INFERENCE_MODEL_CONFIGURATION_FILE_PATH, + OD_OPENCV_CONFIG_CAFFE_PATH)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_INPUT_DATA_TYPE, MV_INFERENCE_DATA_FLOAT32)); + RET_IF_FAIL(mv_engine_config_set_string_attribute( + handle, MV_INFERENCE_MODEL_USER_FILE_PATH, + OD_OPENCV_LABEL_CAFFE_PATH)); + RET_IF_FAIL(mv_engine_config_set_double_attribute( + handle, MV_INFERENCE_MODEL_MEAN_VALUE, 127.5)); + RET_IF_FAIL(mv_engine_config_set_double_attribute( + handle, MV_INFERENCE_MODEL_STD_VALUE, 127.5)); + RET_IF_FAIL(mv_engine_config_set_double_attribute( + handle, MV_INFERENCE_CONFIDENCE_THRESHOLD, 0.3)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_BACKEND_TYPE, MV_INFERENCE_BACKEND_OPENCV)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_TARGET_TYPE, MV_INFERENCE_TARGET_CPU)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_INPUT_TENSOR_WIDTH, 300)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_INPUT_TENSOR_HEIGHT, 300)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_INPUT_TENSOR_CHANNELS, 3)); + RET_IF_FAIL(mv_engine_config_set_string_attribute( + handle, MV_INFERENCE_INPUT_NODE_NAME, inputNodeName)); + RET_IF_FAIL(mv_engine_config_set_array_string_attribute( + handle, MV_INFERENCE_OUTPUT_NODE_NAMES, outputNodeName, 1)); + return MEDIA_VISION_ERROR_NONE; +} - mv_engine_config_set_int_attribute( - handle, MV_INFERENCE_TARGET_TYPE, - MV_INFERENCE_TARGET_CPU); +int perform_armnn_mobilenetv1ssd_config(mv_engine_config_h handle) +{ + const char *inputNodeName = "normalized_input_image_tensor"; + const char *outputNodeName[] = { "TFLite_Detection_PostProcess", + "TFLite_Detection_PostProcess:1", + "TFLite_Detection_PostProcess:2", + "TFLite_Detection_PostProcess:3" }; - *engine_cfg = handle; - return err; + RET_IF_FAIL(mv_engine_config_set_string_attribute( + handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH, + OD_TFLITE_WEIGHT_PATH)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_INPUT_DATA_TYPE, MV_INFERENCE_DATA_FLOAT32)); + RET_IF_FAIL(mv_engine_config_set_string_attribute( + handle, MV_INFERENCE_MODEL_USER_FILE_PATH, OD_LABEL_PATH)); + RET_IF_FAIL(mv_engine_config_set_double_attribute( + handle, MV_INFERENCE_MODEL_MEAN_VALUE, 127.5)); + RET_IF_FAIL(mv_engine_config_set_double_attribute( + handle, MV_INFERENCE_MODEL_STD_VALUE, 127.5)); + RET_IF_FAIL(mv_engine_config_set_double_attribute( + handle, MV_INFERENCE_CONFIDENCE_THRESHOLD, 0.3)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_BACKEND_TYPE, MV_INFERENCE_BACKEND_ARMNN)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_TARGET_TYPE, MV_INFERENCE_TARGET_CPU)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_INPUT_TENSOR_WIDTH, 300)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_INPUT_TENSOR_HEIGHT, 300)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_INPUT_TENSOR_CHANNELS, 3)); + RET_IF_FAIL(mv_engine_config_set_string_attribute( + handle, MV_INFERENCE_INPUT_NODE_NAME, inputNodeName)); + RET_IF_FAIL(mv_engine_config_set_array_string_attribute( + handle, MV_INFERENCE_OUTPUT_NODE_NAMES, outputNodeName, 4)); + return MEDIA_VISION_ERROR_NONE; } int perform_object_detection() { int err = MEDIA_VISION_ERROR_NONE; - - int sel_opt = 0; - const char *names[] = { "Configuration", - "TFLITE(CPU) + MobileNetV1+SSD", - "OPENCV(CPU) + MobileNetV1+SSD", - "ARMNN(CPU) + MobileNetV1+SSD", - "Hosted: TFLite(cpu + MobilenetV1+SSD)", - "Hosted: TFLite(cpu + MobilenetV2+SSD)", - "Hosted: TFLite(Quant + EfficientDet)", - "Prepare", - "Run", - "Back" }; - mv_engine_config_h engine_cfg = NULL; - mv_inference_h infer = NULL; - mv_source_h mvSource = NULL; - - while (sel_opt == 0) { - sel_opt = show_menu_linear("Select Action:", names, ARRAY_SIZE(names)); - switch (sel_opt) { - case 1: { - //perform configuration - if (engine_cfg) { - int err2 = mv_destroy_engine_config(engine_cfg); - if (err2 != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy engine_cfg [err:%i]\n", err2); - engine_cfg = NULL; - } - - err = perform_configuration(&engine_cfg); - } break; - case 2: { - //perform TFlite MobileSSD config - if (engine_cfg) { - int err2 = mv_destroy_engine_config(engine_cfg); - if (err2 != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy engine_cfg [err:%i]\n", err2); - engine_cfg = NULL; - } - - err = perform_tflite_mobilenetv1ssd_config(&engine_cfg); - } break; - case 3: { - //perform OpenCV MobileSSD config - if (engine_cfg) { - int err2 = mv_destroy_engine_config(engine_cfg); - if (err2 != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy engine_cfg [err:%i]\n", err2); - } - - err = perform_opencv_mobilenetv1ssd_config(&engine_cfg); - } break; - case 4: { - //perform ARMNN MobileSSD config - if (engine_cfg) { - int err2 = mv_destroy_engine_config(engine_cfg); - if (err2 != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy engine_cfg [err:%i]\n", err2); - } - - err = perform_armnn_mobilenetv1ssd_config(&engine_cfg); - } break; - case 5: { - //perform hosted mobilenet v1 + ssd - if (engine_cfg) { - int err2 = mv_destroy_engine_config(engine_cfg); - if (err2 != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy engine_cfg [err:%i]\n", err2); - } - - err = perform_hosted_tflite_mobilenetv1ssd_300_config(&engine_cfg); - } break; - case 6: { - //perform hosted mobilenet v2 + ssd - if (engine_cfg) { - int err2 = mv_destroy_engine_config(engine_cfg); - if (err2 != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy engine_cfg [err:%i]\n", err2); - } - - err = perform_hosted_tflite_mobilenetv2ssd_320_config(&engine_cfg); - } break; - case 7: { - //perform hosted quantized efficientdet - if (engine_cfg) { - int err2 = mv_destroy_engine_config(engine_cfg); - if (err2 != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy engine_cfg [err:%i]\n", err2); - } - - err = perform_hosted_tflite_quant_efficient_config(&engine_cfg); - } break; - case 8: { - // create - configure - prepare - if (infer) { - int err2 = mv_inference_destroy(infer); - if (err2 != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy inference handle [err:%i]\n", err2); - infer = NULL; - } - - // inference - // create handle - err = mv_inference_create(&infer); - if (err != MEDIA_VISION_ERROR_NONE) { - printf("Fail to create inference handle [err:%i]\n", err); - break; - } - - //configure - err = mv_inference_configure(infer, engine_cfg); - if (err != MEDIA_VISION_ERROR_NONE) { - printf("Fail to configure inference handle [err:%i]\n", err); - break; - } - - //prepare - err = mv_inference_prepare(infer); - if (err != MEDIA_VISION_ERROR_NONE) { - printf("Fail to prepare inference handle"); - break; - } - } break; - case 9: { - if (mvSource) { - int err2 = mv_destroy_source(mvSource); - if (err2 != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy mvSource\n"); - mvSource = NULL; - } - - char *in_file_name = NULL; - /* Load media source */ - while (input_string("Input file name to be inferred:", 1024, - &(in_file_name)) == -1) - printf("Incorrect input! Try again.\n"); - - err = mv_create_source(&mvSource); - if (err != MEDIA_VISION_ERROR_NONE) { - printf("Fail to create mvSource.\n"); - free(in_file_name); - break; - } - - err = load_mv_source_from_file(in_file_name, mvSource); - if (err != MEDIA_VISION_ERROR_NONE) { - int err2 = mv_destroy_source(mvSource); - if (err2 != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy mvSource.\n"); - mvSource = NULL; - free(in_file_name); - break; - } - free(in_file_name); - - struct timespec s_tspec; - struct timespec e_tspec; - - clock_gettime(CLOCK_MONOTONIC, &s_tspec); - - // Object Detect - err = mv_inference_object_detect(mvSource, infer, - _object_detected_cb, NULL); - - clock_gettime(CLOCK_MONOTONIC, &e_tspec); - - struct timespec diffspec = diff(s_tspec, e_tspec); - unsigned long timeDiff = gettotalmillisec(diffspec); - printf("elapsed time : %lu(ms)\n", timeDiff); - - } break; - case 10: { - //perform destroy - if (engine_cfg) { - err = mv_destroy_engine_config(engine_cfg); - if (err != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy engine_cfg [err:%i]\n", err); - engine_cfg = NULL; - } - - if (infer) { - err = mv_inference_destroy(infer); - if (err != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy inference handle [err:%i]\n", err); - infer = NULL; - } - - if (mvSource) { - err = mv_destroy_source(mvSource); - if (err != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy mvSource.\n"); - mvSource = NULL; - } - } break; - default: - printf("Invalid option.\n"); - sel_opt = 0; - continue; - } - - int do_another = 0; - if (err != MEDIA_VISION_ERROR_NONE) { - printf("ERROR: Action is finished with error code:%i\n", err); - } - - sel_opt = 0; - while (sel_opt == 0) { - sel_opt = show_menu_yes_or_no("Run Object Detection again?:"); - switch (sel_opt) { - case 1: - do_another = 1; - break; - case 2: - do_another = 0; - break; - default: - printf("Invalid option.\n"); - sel_opt = 0; - } - } + const char *names[] = { + "TFLITE(CPU) + MobileNetV1+SSD", + "OPENCV(CPU) + MobileNetV1+SSD", + "ARMNN(CPU) + MobileNetV1+SSD", + "Hosted: TFLite(cpu + MobilenetV1+SSD)", + "Hosted: TFLite(cpu + MobilenetV2+SSD)", + "Hosted: TFLite(Quant + EfficientDet)", + }; - sel_opt = (do_another == 1) ? 0 : 1; + int sel_opt = show_menu_linear("Select Action:", names, ARRAY_SIZE(names)); + if (sel_opt <= 0 || sel_opt > ARRAY_SIZE(names)) { + printf("Invalid option"); + return -1; } - if (engine_cfg) { - err = mv_destroy_engine_config(engine_cfg); - if (err != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy engine_cfg [err:%i]\n", err); - engine_cfg = NULL; - } + RET_IF_FAIL(mv_create_engine_config(&engine_cfg)); - if (infer) { - err = mv_inference_destroy(infer); - if (err != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy inference handle [err:%i]\n", err); - infer = NULL; + switch (sel_opt) { + case 1: { + err = perform_tflite_mobilenetv1ssd_config(engine_cfg); + } break; + case 2: { + err = perform_opencv_mobilenetv1ssd_config(engine_cfg); + } break; + case 3: { + err = perform_armnn_mobilenetv1ssd_config(engine_cfg); + } break; + case 4: { + err = engine_config_user_hosted_tflite_cpu( + engine_cfg, OD_TFLITE_WEIGHT_MOBILENET_V1_SSD_300_PATH, + OD_LABEL_MOBILENET_V1_SSD_300_PATH); + } break; + case 5: { + err = engine_config_user_hosted_tflite_cpu( + engine_cfg, OD_TFLITE_WEIGHT_MOBILENET_V2_SSD_320_PATH, + OD_LABEL_MOBILENET_V2_SSD_320_PATH); + } break; + case 6: { + err = engine_config_user_hosted_tflite_cpu( + engine_cfg, OD_TFLITE_WEIGHT_QUANT_EFFICIENT_PATH, + OD_LABEL_QUANT_EFFICIENT_PATH); + } break; } - - if (mvSource) { - err = mv_destroy_source(mvSource); - if (err != MEDIA_VISION_ERROR_NONE) - printf("Fail to destroy mvSource\n"); - mvSource = NULL; + if (err != MEDIA_VISION_ERROR_NONE) { + printf("Fail to perform config [err:%i]\n", err); + goto clean_object_detect_engine; } - return MEDIA_VISION_ERROR_NONE; + err = mv_inference_task_helper(engine_cfg, TASK_OD); + if (err != MEDIA_VISION_ERROR_NONE) + printf("Fail to detect with engine [err:%i]\n", err); + +clean_object_detect_engine: + RET_IF_FAIL(mv_destroy_engine_config(engine_cfg)); + return err; } int perform_tflite_mobilenetv1ssd_face(mv_engine_config_h handle) @@ -2662,6 +1521,16 @@ int engine_config_hosted_tflite_cpu(mv_engine_config_h handle, return MEDIA_VISION_ERROR_NONE; } +int engine_config_user_hosted_tflite_cpu(mv_engine_config_h handle, + const char *tf_weight, + const char *user_file) +{ + RET_IF_FAIL(engine_config_hosted_tflite_cpu(handle, tf_weight)); + RET_IF_FAIL(mv_engine_config_set_int_attribute( + handle, MV_INFERENCE_MODEL_USER_FILE_PATH, user_file)); + return MEDIA_VISION_ERROR_NONE; +} + int perform_armnn_cpm_config(mv_engine_config_h handle) { const char *inputNodeName = "image"; -- 2.7.4 From e6a9eef049112d88efd533dfa83dbd0805e7a187 Mon Sep 17 00:00:00 2001 From: Kwang Son Date: Sun, 8 Aug 2021 23:24:45 -0400 Subject: [PATCH 05/16] test: Add mv_test media vision unit test based on Gtest media vision already has testsuites and assessment but each has some limitations. See test/README.md more details. Change-Id: I1d62adaeac92efe5ddc9cc6fa7a350e1aa3c846a Signed-off-by: Kwang Son --- packaging/capi-media-vision.spec | 3 +- test/CMakeLists.txt | 11 ++++ test/README.md | 26 +++++++++ .../inference/test_image_classification.cpp | 58 ++++++++++++++++++++ .../inference/test_inference_helper.cpp | 62 ++++++++++++++++++++++ .../inference/test_inference_helper.hpp | 15 ++++++ 6 files changed, 174 insertions(+), 1 deletion(-) create mode 100644 test/README.md create mode 100644 test/testsuites/machine_learning/inference/test_image_classification.cpp create mode 100644 test/testsuites/machine_learning/inference/test_inference_helper.cpp create mode 100644 test/testsuites/machine_learning/inference/test_inference_helper.hpp diff --git a/packaging/capi-media-vision.spec b/packaging/capi-media-vision.spec index e2543f2..805d60f 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.8.3 +Version: 0.8.4 Release: 0 Group: Multimedia/Framework License: Apache-2.0 and BSD-3-Clause @@ -29,6 +29,7 @@ BuildRequires: pkgconfig(gstreamer-app-1.0) BuildRequires: pkgconfig(libtzplatform-config) BuildRequires: pkgconfig(ncurses) BuildRequires: pkgconfig(check) +BuildRequires: pkgconfig(gtest) %endif Requires: %{name}-machine_learning diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index e8822a8..57768b0 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,2 +1,13 @@ add_subdirectory(assessment) add_subdirectory(testsuites) + +project(mv_test) +cmake_minimum_required(VERSION 2.6) + +pkg_check_modules(${PROJECT_NAME}_DEP REQUIRED gtest gtest_main) +add_executable(${PROJECT_NAME} + testsuites/machine_learning/inference/test_inference_helper.cpp + testsuites/machine_learning/inference/test_image_classification.cpp +) +target_link_libraries(${PROJECT_NAME} ${${PROJECT_NAME}_DEP_LIBRARIES} mv_inference mv_image_helper) +install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR}) \ No newline at end of file diff --git a/test/README.md b/test/README.md new file mode 100644 index 0000000..310adf8 --- /dev/null +++ b/test/README.md @@ -0,0 +1,26 @@ +# mv_test +media vision unit test based on [GTEST](https://github.com/google/googletest) + +## Why? +media vision already has testsuites and assessment but each has some limitations. +1. testsuite - ITC(interactive test case) based which is mean when you modify some of vision code, you need type ITC commands on terminal. ITC hides some resource allocation and logics, it makes hard to debug code. +2. assessment - it's basically testsuite with timer so most of code are duplicated. + +mv_test try convert testsuite ITC to unit test and timer function. + +## How test? +First test needs dataset https://github.sec.samsung.net/k-son/mv_test.git +Install dataset on target using install.sh script and type `$ mv_test` + +### ASAN build command +`$ gbs build -A $ARCH --include-all --extra-packs asan-force-options,sanitizer-devel` +install libasan on target and on target terminal `$ ASAN_OPTIONS=detect_leaks=1 mv_test` + +## FAQ +### What about Tizen TCT? +Tizen tct is for public API verification. It's still valid however mv_test is more focus on internal APIs. +Another point is Tizen tct has huge amount of datset of other packages which is not related with media vision so build takes long, and complicated. + +### Why gtest? +I tried with libcheck but since Tizen API is C/C++, hard to cover all of C++ modules (interal API is more rely on C++). +libcheck also needs runtime dependancy. \ No newline at end of file diff --git a/test/testsuites/machine_learning/inference/test_image_classification.cpp b/test/testsuites/machine_learning/inference/test_image_classification.cpp new file mode 100644 index 0000000..979ebfa --- /dev/null +++ b/test/testsuites/machine_learning/inference/test_image_classification.cpp @@ -0,0 +1,58 @@ +#include +#include "test_inference_helper.hpp" + +#define IC_LABEL_MOBILENET_V1_224_PATH \ + MV_CONFIG_PATH \ + "/models/IC/tflite/ic_mobilenet_v1_label.txt" +#define IC_TFLITE_WEIGHT_MOBILENET_V1_224_PATH \ + MV_CONFIG_PATH \ + "/models/IC/tflite/ic_mobilenet_v1_224x224.tflite" +#define IMG_BANANA \ + MV_CONFIG_PATH \ + "/res/inference/images/banana.jpg" + +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) +{ + ASSERT_EQ(number_of_classes, 1); + EXPECT_STREQ(names[0], "banana"); +} + +class TestImageClassification : public ::testing::Test +{ +public: + TestImageClassification() + { + EXPECT_EQ(mv_create_engine_config(&engine_cfg), + MEDIA_VISION_ERROR_NONE); + EXPECT_EQ(mv_inference_create(&infer), MEDIA_VISION_ERROR_NONE); + EXPECT_EQ(mv_create_source(&mv_source), MEDIA_VISION_ERROR_NONE); + } + ~TestImageClassification() + { + EXPECT_EQ(mv_destroy_source(mv_source), MEDIA_VISION_ERROR_NONE); + EXPECT_EQ(mv_inference_destroy(infer), MEDIA_VISION_ERROR_NONE); + EXPECT_EQ(mv_destroy_engine_config(engine_cfg), + MEDIA_VISION_ERROR_NONE); + } + mv_engine_config_h engine_cfg; + mv_inference_h infer; + mv_source_h mv_source; +}; + +TEST_F(TestImageClassification, CPU_TFLITE_MobilenetV1) +{ + engine_config_hosted_cpu_tflite_user_model( + engine_cfg, IC_TFLITE_WEIGHT_MOBILENET_V1_224_PATH, + IC_LABEL_MOBILENET_V1_224_PATH); + EXPECT_EQ(mv_inference_configure(infer, engine_cfg), + MEDIA_VISION_ERROR_NONE); + EXPECT_EQ(mv_inference_prepare(infer), MEDIA_VISION_ERROR_NONE); + EXPECT_EQ(load_mv_source_from_file(mv_source, IMG_BANANA), + MEDIA_VISION_ERROR_NONE); + EXPECT_EQ(mv_inference_image_classify(mv_source, infer, NULL, + _image_classified_cb, NULL), + MEDIA_VISION_ERROR_NONE); + EXPECT_EQ(mv_source_clear(mv_source), MEDIA_VISION_ERROR_NONE); +} \ No newline at end of file diff --git a/test/testsuites/machine_learning/inference/test_inference_helper.cpp b/test/testsuites/machine_learning/inference/test_inference_helper.cpp new file mode 100644 index 0000000..9700001 --- /dev/null +++ b/test/testsuites/machine_learning/inference/test_inference_helper.cpp @@ -0,0 +1,62 @@ +#include +#include +#include "test_inference_helper.hpp" + +void engine_config_hosted_cpu_tflite(mv_engine_config_h handle, + const char *tf_weight) +{ + EXPECT_EQ(mv_engine_config_set_string_attribute( + handle, MV_INFERENCE_MODEL_WEIGHT_FILE_PATH, tf_weight), + MEDIA_VISION_ERROR_NONE); + EXPECT_EQ(mv_engine_config_set_int_attribute(handle, + MV_INFERENCE_BACKEND_TYPE, + MV_INFERENCE_BACKEND_TFLITE), + 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); +} + +void engine_config_hosted_cpu_tflite_user_model(mv_engine_config_h handle, + const char *tf_weight, + const char *user_file) +{ + engine_config_hosted_cpu_tflite(handle, tf_weight); + EXPECT_EQ(mv_engine_config_set_string_attribute( + handle, MV_INFERENCE_MODEL_USER_FILE_PATH, user_file), + MEDIA_VISION_ERROR_NONE); +} + +// TODO: memcpy twice to one time +int load_mv_source_from_file(mv_source_h source, const char *path_to_image) +{ + unsigned char *data_buffer = NULL; + unsigned long buffer_size = 0; + image_data_s image_data; + + int err = load_image_to_buffer(path_to_image, &data_buffer, &buffer_size, + &image_data); + if (MEDIA_VISION_ERROR_NONE != err) { + printf("ERROR: Errors were occurred during opening file!!! code: %i\n", + err); + if (NULL != data_buffer) + destroy_loaded_buffer(data_buffer); + + return err; + } + + err = mv_source_fill_by_buffer(source, data_buffer, buffer_size, + image_data.image_width, + image_data.image_height, + image_data.image_colorspace); + + if (MEDIA_VISION_ERROR_NONE != err) + printf("ERROR: Errors were occurred during filling source!!! code %i\n", + err); + + if (NULL != data_buffer) + destroy_loaded_buffer(data_buffer); + + return err; +} diff --git a/test/testsuites/machine_learning/inference/test_inference_helper.hpp b/test/testsuites/machine_learning/inference/test_inference_helper.hpp new file mode 100644 index 0000000..4d1f679 --- /dev/null +++ b/test/testsuites/machine_learning/inference/test_inference_helper.hpp @@ -0,0 +1,15 @@ +#ifndef __TEST_INFERENCE_HELPER_HPP__ +#define __TEST_INFERENCE_HELPER_HPP__ + +#include + +void engine_config_hosted_cpu_tflite(mv_engine_config_h handle, + const char *tf_weight); + +void engine_config_hosted_cpu_tflite_user_model(mv_engine_config_h handle, + const char *tf_weight, + const char *user_file); + +int load_mv_source_from_file(mv_source_h source, const char *path_to_image); + +#endif //__TEST_INFERENCE_HELPER_HPP__ \ No newline at end of file -- 2.7.4 From 335692365c8ef735e851ad05bfb23c2ff4b69541 Mon Sep 17 00:00:00 2001 From: Kwang Son Date: Tue, 10 Aug 2021 22:02:26 -0400 Subject: [PATCH 06/16] test: Move load image function to helper ImageHelper already has similar function. Change-Id: Ibeecaf6ba387a1504811c70423f9d7b216cec154 Signed-off-by: Kwang Son --- .../common/image_helper/include/ImageHelper.h | 2 ++ .../common/image_helper/src/ImageHelper.cpp | 28 ++++++++++++++++++ .../inference/test_image_classification.cpp | 6 ++-- .../inference/test_inference_helper.cpp | 33 ---------------------- .../inference/test_inference_helper.hpp | 4 +-- 5 files changed, 35 insertions(+), 38 deletions(-) diff --git a/test/testsuites/common/image_helper/include/ImageHelper.h b/test/testsuites/common/image_helper/include/ImageHelper.h index 9e3102f..a2e01bd 100644 --- a/test/testsuites/common/image_helper/include/ImageHelper.h +++ b/test/testsuites/common/image_helper/include/ImageHelper.h @@ -77,6 +77,8 @@ public: unsigned long *pBufferSize, ImageData *pImageData); + static int loadImageToSource(const char *filePath, mv_source_h source); + /** * @brief Saves image stored into @a pDataBuffer to the file in jpeg format. * diff --git a/test/testsuites/common/image_helper/src/ImageHelper.cpp b/test/testsuites/common/image_helper/src/ImageHelper.cpp index d4fb4cd..fa123cc 100644 --- a/test/testsuites/common/image_helper/src/ImageHelper.cpp +++ b/test/testsuites/common/image_helper/src/ImageHelper.cpp @@ -87,6 +87,34 @@ int ImageHelper::loadImageToBuffer( return MEDIA_VISION_ERROR_NONE; } +int ImageHelper::loadImageToSource(const char *filePath, mv_source_h source) +{ + unsigned char *data_buffer = NULL; + unsigned long buffer_size = 0; + ImageData image_data; + + int err = loadImageToBuffer(filePath, &data_buffer, &buffer_size, + &image_data); + if (MEDIA_VISION_ERROR_NONE != err) { + printf("ERROR: Errors were occurred during opening file!!! code: %i\n", + err); + return err; + } + + err = mv_source_fill_by_buffer(source, data_buffer, buffer_size, + image_data.imageWidth, + image_data.imageHeight, + image_data.imageColorspace); + + if (MEDIA_VISION_ERROR_NONE != err) + printf("ERROR: Errors were occurred during filling source!!! code %i\n", + err); + + if (NULL != data_buffer) + destroyLoadedBuffer(data_buffer); + return err; +} + int ImageHelper::saveImageFromBuffer( const char *filePath, unsigned char *pDataBuffer, diff --git a/test/testsuites/machine_learning/inference/test_image_classification.cpp b/test/testsuites/machine_learning/inference/test_image_classification.cpp index 979ebfa..96f8075 100644 --- a/test/testsuites/machine_learning/inference/test_image_classification.cpp +++ b/test/testsuites/machine_learning/inference/test_image_classification.cpp @@ -1,4 +1,5 @@ #include +#include #include "test_inference_helper.hpp" #define IC_LABEL_MOBILENET_V1_224_PATH \ @@ -49,10 +50,11 @@ TEST_F(TestImageClassification, CPU_TFLITE_MobilenetV1) EXPECT_EQ(mv_inference_configure(infer, engine_cfg), MEDIA_VISION_ERROR_NONE); EXPECT_EQ(mv_inference_prepare(infer), MEDIA_VISION_ERROR_NONE); - EXPECT_EQ(load_mv_source_from_file(mv_source, IMG_BANANA), + EXPECT_EQ(MediaVision::Common::ImageHelper::loadImageToSource(IMG_BANANA, + mv_source), MEDIA_VISION_ERROR_NONE); EXPECT_EQ(mv_inference_image_classify(mv_source, infer, NULL, _image_classified_cb, NULL), MEDIA_VISION_ERROR_NONE); EXPECT_EQ(mv_source_clear(mv_source), MEDIA_VISION_ERROR_NONE); -} \ No newline at end of file +} diff --git a/test/testsuites/machine_learning/inference/test_inference_helper.cpp b/test/testsuites/machine_learning/inference/test_inference_helper.cpp index 9700001..4fc1038 100644 --- a/test/testsuites/machine_learning/inference/test_inference_helper.cpp +++ b/test/testsuites/machine_learning/inference/test_inference_helper.cpp @@ -27,36 +27,3 @@ void engine_config_hosted_cpu_tflite_user_model(mv_engine_config_h handle, handle, MV_INFERENCE_MODEL_USER_FILE_PATH, user_file), MEDIA_VISION_ERROR_NONE); } - -// TODO: memcpy twice to one time -int load_mv_source_from_file(mv_source_h source, const char *path_to_image) -{ - unsigned char *data_buffer = NULL; - unsigned long buffer_size = 0; - image_data_s image_data; - - int err = load_image_to_buffer(path_to_image, &data_buffer, &buffer_size, - &image_data); - if (MEDIA_VISION_ERROR_NONE != err) { - printf("ERROR: Errors were occurred during opening file!!! code: %i\n", - err); - if (NULL != data_buffer) - destroy_loaded_buffer(data_buffer); - - return err; - } - - err = mv_source_fill_by_buffer(source, data_buffer, buffer_size, - image_data.image_width, - image_data.image_height, - image_data.image_colorspace); - - if (MEDIA_VISION_ERROR_NONE != err) - printf("ERROR: Errors were occurred during filling source!!! code %i\n", - err); - - if (NULL != data_buffer) - destroy_loaded_buffer(data_buffer); - - return err; -} diff --git a/test/testsuites/machine_learning/inference/test_inference_helper.hpp b/test/testsuites/machine_learning/inference/test_inference_helper.hpp index 4d1f679..05cab7a 100644 --- a/test/testsuites/machine_learning/inference/test_inference_helper.hpp +++ b/test/testsuites/machine_learning/inference/test_inference_helper.hpp @@ -10,6 +10,4 @@ void engine_config_hosted_cpu_tflite_user_model(mv_engine_config_h handle, const char *tf_weight, const char *user_file); -int load_mv_source_from_file(mv_source_h source, const char *path_to_image); - -#endif //__TEST_INFERENCE_HELPER_HPP__ \ No newline at end of file +#endif //__TEST_INFERENCE_HELPER_HPP__ -- 2.7.4 From fe4f0e808e85716c52130b2aaf6360f4334c433f Mon Sep 17 00:00:00 2001 From: Kwang Son Date: Fri, 13 Aug 2021 04:10:33 -0400 Subject: [PATCH 07/16] test: Replace barcode libcheck to gtest Change-Id: I22339de3c880f3958ee8e049a29d902846fc0acf Signed-off-by: Kwang Son --- packaging/capi-media-vision.spec | 3 +- test/CMakeLists.txt | 3 +- test/testsuites/CMakeLists.txt | 1 - test/testsuites/barcode/CMakeLists.txt | 14 ----- test/testsuites/barcode/test_barcode.c | 71 --------------------- test/testsuites/barcode/test_barcode.cpp | 105 +++++++++++++++++++++++++++++++ 6 files changed, 108 insertions(+), 89 deletions(-) delete mode 100644 test/testsuites/barcode/CMakeLists.txt delete mode 100644 test/testsuites/barcode/test_barcode.c create mode 100644 test/testsuites/barcode/test_barcode.cpp diff --git a/packaging/capi-media-vision.spec b/packaging/capi-media-vision.spec index 805d60f..18e1793 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.8.4 +Version: 0.8.5 Release: 0 Group: Multimedia/Framework License: Apache-2.0 and BSD-3-Clause @@ -28,7 +28,6 @@ BuildRequires: pkgconfig(gstreamer-base-1.0) BuildRequires: pkgconfig(gstreamer-app-1.0) BuildRequires: pkgconfig(libtzplatform-config) BuildRequires: pkgconfig(ncurses) -BuildRequires: pkgconfig(check) BuildRequires: pkgconfig(gtest) %endif diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 57768b0..43c7e23 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -6,8 +6,9 @@ cmake_minimum_required(VERSION 2.6) pkg_check_modules(${PROJECT_NAME}_DEP REQUIRED gtest gtest_main) add_executable(${PROJECT_NAME} + testsuites/barcode/test_barcode.cpp testsuites/machine_learning/inference/test_inference_helper.cpp testsuites/machine_learning/inference/test_image_classification.cpp ) -target_link_libraries(${PROJECT_NAME} ${${PROJECT_NAME}_DEP_LIBRARIES} mv_inference mv_image_helper) +target_link_libraries(${PROJECT_NAME} ${${PROJECT_NAME}_DEP_LIBRARIES} 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/CMakeLists.txt b/test/testsuites/CMakeLists.txt index bc1711d..bc195d7 100644 --- a/test/testsuites/CMakeLists.txt +++ b/test/testsuites/CMakeLists.txt @@ -6,7 +6,6 @@ set(INC_VIDEO_HELPER "${PROJECT_SOURCE_DIR}/common/video_helper") set(INC_TS_COMMON "${PROJECT_SOURCE_DIR}/common/testsuite_common") add_subdirectory(${PROJECT_SOURCE_DIR}/common) -add_subdirectory(${PROJECT_SOURCE_DIR}/barcode) add_subdirectory(${PROJECT_SOURCE_DIR}/face) add_subdirectory(${PROJECT_SOURCE_DIR}/image) add_subdirectory(${PROJECT_SOURCE_DIR}/surveillance) diff --git a/test/testsuites/barcode/CMakeLists.txt b/test/testsuites/barcode/CMakeLists.txt deleted file mode 100644 index fb86885..0000000 --- a/test/testsuites/barcode/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -project(mv_barcode_test_suite) -cmake_minimum_required(VERSION 2.6) - -pkg_check_modules(${PROJECT_NAME}_DEP REQUIRED ncurses capi-system-info -dlog check) - -add_executable(${PROJECT_NAME} test_barcode.c) -target_link_libraries(${PROJECT_NAME} ${MV_BARCODE_DETECTOR_LIB_NAME} -${MV_BARCODE_GENERATOR_LIB_NAME} ${${PROJECT_NAME}_DEP_LIBRARIES} -avcodec avformat avutil swscale mv_image_helper -) - -install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR}) -install(FILES mv_barcode_test_suite_auto PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ DESTINATION ${CMAKE_INSTALL_BINDIR}) diff --git a/test/testsuites/barcode/test_barcode.c b/test/testsuites/barcode/test_barcode.c deleted file mode 100644 index a34fdbd..0000000 --- a/test/testsuites/barcode/test_barcode.c +++ /dev/null @@ -1,71 +0,0 @@ -#include -#include -#include -#include - -mv_engine_config_h mv_engine_config; - -void setup(void) -{ - ck_assert_int_eq(mv_create_engine_config(&mv_engine_config), - MEDIA_VISION_ERROR_NONE); -} -void teardown(void) -{ - ck_assert_int_eq(mv_destroy_engine_config(mv_engine_config), - MEDIA_VISION_ERROR_NONE); -} -START_TEST(barcode_generate_num) -{ - ck_assert_int_eq(mv_engine_config_set_string_attribute( - mv_engine_config, - MV_BARCODE_GENERATE_ATTR_COLOR_FRONT, "000000"), - MEDIA_VISION_ERROR_NONE); - ck_assert_int_eq(mv_engine_config_set_string_attribute( - mv_engine_config, - MV_BARCODE_GENERATE_ATTR_COLOR_BACK, "ffffff"), - MEDIA_VISION_ERROR_NONE); - ck_assert_int_eq(mv_barcode_generate_image( - mv_engine_config, "11234", 200, 200, MV_BARCODE_QR, - MV_BARCODE_QR_MODE_NUMERIC, MV_BARCODE_QR_ECC_HIGH, - 20, "/tmp/mvtest/gen.png", MV_BARCODE_IMAGE_FORMAT_PNG), - MEDIA_VISION_ERROR_NONE); -} -END_TEST -START_TEST(barcode_generate_utf8) -{ - ck_assert_int_eq(mv_engine_config_set_string_attribute( - mv_engine_config, - MV_BARCODE_GENERATE_ATTR_COLOR_FRONT, "000000"), - MEDIA_VISION_ERROR_NONE); - ck_assert_int_eq(mv_engine_config_set_string_attribute( - mv_engine_config, - MV_BARCODE_GENERATE_ATTR_COLOR_BACK, "ffffff"), - MEDIA_VISION_ERROR_NONE); - ck_assert_int_eq(mv_barcode_generate_image( - mv_engine_config, "qr_test1", 200, 200, - MV_BARCODE_QR, MV_BARCODE_QR_MODE_UTF8, - MV_BARCODE_QR_ECC_HIGH, 20, "/tmp/mvtest/gen2.png", - MV_BARCODE_IMAGE_FORMAT_PNG), - MEDIA_VISION_ERROR_NONE); -} -END_TEST -Suite *barcode_suite(void) -{ - Suite *s = suite_create("Barcode"); - TCase *tc_core = tcase_create("Core"); - tcase_add_checked_fixture(tc_core, setup, teardown); - tcase_add_test(tc_core, barcode_generate_num); - tcase_add_test(tc_core, barcode_generate_utf8); - suite_add_tcase(s, tc_core); - return s; -} -int main() -{ - Suite *s = barcode_suite(); - SRunner *sr = srunner_create(s); - srunner_run_all(sr, CK_NORMAL); - int number_failed = srunner_ntests_failed(sr); - srunner_free(sr); - return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; -} \ No newline at end of file diff --git a/test/testsuites/barcode/test_barcode.cpp b/test/testsuites/barcode/test_barcode.cpp new file mode 100644 index 0000000..a4247dc --- /dev/null +++ b/test/testsuites/barcode/test_barcode.cpp @@ -0,0 +1,105 @@ +#include +#include +#include +#include +#include +#include +#include + +using namespace std; +using TestParams = tuple; + +#define BARCODE_IMG_PREFIX \ + MV_CONFIG_PATH \ + "/res/img/" + +#define BARCODE_JSON \ + MV_CONFIG_PATH \ + "/res/media-vision-barcodes.json" + +void barcode_detected_cb(mv_source_h source, mv_engine_config_h engine_cfg, + const mv_quadrangle_s *barcodes_locations, + const char *messages[], const mv_barcode_type_e *types, + int number_of_barcodes, void *user_data) +{ + EXPECT_EQ(number_of_barcodes, 1); + EXPECT_STREQ(messages[0], (const char *) user_data); +} + +vector ReadDetPositive1() +{ + vector rv; + GError *error = NULL; + + JsonParser *parser = json_parser_new(); + json_parser_load_from_file(parser, BARCODE_JSON, &error); + EXPECT_TRUE(error == NULL); + + JsonReader *reader = json_reader_new(json_parser_get_root(parser)); + + json_reader_read_member(reader, "det_positive1"); + for (gint i = 0; i < json_reader_count_elements(reader); i++) { + json_reader_read_element(reader, i); + + json_reader_read_member(reader, "image_name"); + std::string image_name = json_reader_get_string_value(reader); + json_reader_end_member(reader); + + json_reader_read_member(reader, "message"); + std::string message = json_reader_get_string_value(reader); + json_reader_end_member(reader); + + rv.push_back(make_tuple(image_name, message)); + + json_reader_end_element(reader); + } + json_reader_end_member(reader); + + g_object_unref(reader); + g_object_unref(parser); + + return rv; +} + +class TestBarcode : public testing::TestWithParam +{ +public: + TestBarcode() + { + EXPECT_EQ(mv_create_engine_config(&engine_cfg), + MEDIA_VISION_ERROR_NONE); + EXPECT_EQ(mv_create_source(&mv_source), MEDIA_VISION_ERROR_NONE); + } + ~TestBarcode() + { + EXPECT_EQ(mv_destroy_source(mv_source), MEDIA_VISION_ERROR_NONE); + EXPECT_EQ(mv_destroy_engine_config(engine_cfg), + MEDIA_VISION_ERROR_NONE); + } + mv_engine_config_h engine_cfg; + mv_source_h mv_source; +}; + +TEST_P(TestBarcode, Detection) +{ + auto image_name = BARCODE_IMG_PREFIX + get<0>(GetParam()); + auto message = get<1>(GetParam()); + + EXPECT_EQ(MediaVision::Common::ImageHelper::loadImageToSource( + image_name.c_str(), mv_source), + MEDIA_VISION_ERROR_NONE); + + mv_rectangle_s roi = { { 0, 0 }, 0, 0 }; + mv_source_get_width(mv_source, (unsigned int *) &(roi.width)); + mv_source_get_width(mv_source, (unsigned int *) &(roi.height)); + mv_engine_config_set_int_attribute(engine_cfg, + MV_BARCODE_DETECT_ATTR_TARGET, + MV_BARCODE_DETECT_ATTR_TARGET_ALL); + + EXPECT_EQ(mv_barcode_detect(mv_source, engine_cfg, roi, barcode_detected_cb, + (void *) message.c_str()), + MEDIA_VISION_ERROR_NONE); +} + +INSTANTIATE_TEST_CASE_P(GeneralAndSpecial, TestBarcode, + testing::ValuesIn(ReadDetPositive1())); \ No newline at end of file -- 2.7.4 From 6a27bd54f30a0bd1de0b36018ec27f8b9d1ce4f9 Mon Sep 17 00:00:00 2001 From: Kwang Son Date: Fri, 13 Aug 2021 04:24:35 -0400 Subject: [PATCH 08/16] test: Update assessment test instruction Change-Id: Ic7782efdb199aab123dd2f0488a7b5cbc4952c91 Signed-off-by: Kwang Son --- test/README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/README.md b/test/README.md index 310adf8..5155327 100644 --- a/test/README.md +++ b/test/README.md @@ -6,7 +6,9 @@ media vision already has testsuites and assessment but each has some limitations 1. testsuite - ITC(interactive test case) based which is mean when you modify some of vision code, you need type ITC commands on terminal. ITC hides some resource allocation and logics, it makes hard to debug code. 2. assessment - it's basically testsuite with timer so most of code are duplicated. -mv_test try convert testsuite ITC to unit test and timer function. +mv_test try convert testsuite ITC to unit test and timer function. +Since assessment is optional test, it will be `DISABLED_` [optional gtest](https://github.com/google/googletest/blob/master/docs/advanced.md#temporarily-disabling-tests). +assessment test could be run with `--gtest_also_run_disabled_tests` ## How test? First test needs dataset https://github.sec.samsung.net/k-son/mv_test.git @@ -19,7 +21,7 @@ install libasan on target and on target terminal `$ ASAN_OPTIONS=detect_leaks=1 ## FAQ ### What about Tizen TCT? Tizen tct is for public API verification. It's still valid however mv_test is more focus on internal APIs. -Another point is Tizen tct has huge amount of datset of other packages which is not related with media vision so build takes long, and complicated. +Another point is Tizen tct has huge amount of dataset of other packages which is not related with media vision so build takes long, and complicated. ### Why gtest? I tried with libcheck but since Tizen API is C/C++, hard to cover all of C++ modules (interal API is more rely on C++). -- 2.7.4 From 09e5c966f2c306e6fa8f80119e7e6b5550fb3510 Mon Sep 17 00:00:00 2001 From: Tae-Young Chung Date: Tue, 17 Aug 2021 11:10:02 +0900 Subject: [PATCH 09/16] Fix printf type of size_t from i to zu Change-Id: I97a0b981a599ef971016eca85860fcb51df49d1f Signed-off-by: Tae-Young Chung --- test/testsuites/common/testsuite_common/mv_testsuite_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/testsuites/common/testsuite_common/mv_testsuite_common.c b/test/testsuites/common/testsuite_common/mv_testsuite_common.c index 91f5bc1..29a1385 100644 --- a/test/testsuites/common/testsuite_common/mv_testsuite_common.c +++ b/test/testsuites/common/testsuite_common/mv_testsuite_common.c @@ -280,7 +280,7 @@ int show_menu_linear(const char *title, const char **menu, size_t len_menu) printf("*-------------------------------------------*\n"); for (size_t i = 0; i < len_menu; ++i) - printf("* %2i. %34s *\n", i + 1, menu[i]); + printf("* %2zu. %34s *\n", i + 1, menu[i]); printf("*********************************************\n\n"); int selection = 0; -- 2.7.4 From 9e6b1c394f9aa236c57ee4624f19a19b39163472 Mon Sep 17 00:00:00 2001 From: Tae-Young Chung Date: Tue, 17 Aug 2021 15:33:04 +0900 Subject: [PATCH 10/16] Fix unsafe mix of types 'gboolean' and 'bool' Change-Id: I547f2e907f1be1d3774026e9fe36b299f4b4cca3 Signed-off-by: Tae-Young Chung --- .../mv_inference/inference/src/InputMetadata.cpp | 4 +-- .../mv_inference/inference/src/OutputMetadata.cpp | 34 +++++++++++----------- packaging/capi-media-vision.spec | 2 +- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/mv_machine_learning/mv_inference/inference/src/InputMetadata.cpp b/mv_machine_learning/mv_inference/inference/src/InputMetadata.cpp index 28edbe3..befbd43 100644 --- a/mv_machine_learning/mv_inference/inference/src/InputMetadata.cpp +++ b/mv_machine_learning/mv_inference/inference/src/InputMetadata.cpp @@ -51,7 +51,7 @@ namespace inference { LOGI("ENTER"); - if (json_object_has_member(root, "tensor_info") == false) { + if (!json_object_has_member(root, "tensor_info")) { LOGE("No tensor_info inputmetadata"); return MEDIA_VISION_ERROR_INVALID_OPERATION; } @@ -106,7 +106,7 @@ namespace inference { LOGI("ENTER"); - if (json_object_has_member(root, "preprocess") == false) { + if (!json_object_has_member(root, "preprocess")) { LOGI("No preprocess inputmetadata"); return MEDIA_VISION_ERROR_NONE; } diff --git a/mv_machine_learning/mv_inference/inference/src/OutputMetadata.cpp b/mv_machine_learning/mv_inference/inference/src/OutputMetadata.cpp index aab8b50..04f97cc 100755 --- a/mv_machine_learning/mv_inference/inference/src/OutputMetadata.cpp +++ b/mv_machine_learning/mv_inference/inference/src/OutputMetadata.cpp @@ -77,7 +77,7 @@ namespace inference { LOGI("ENTER"); - if (json_object_has_member(root, "score") == false) { + if (!json_object_has_member(root, "score")) { LOGI("No score outputmetadata"); LOGI("LEAVE"); return MEDIA_VISION_ERROR_NONE; @@ -158,7 +158,7 @@ namespace inference { LOGI("ENTER"); - if (json_object_has_member(root, "box") == false) { + if (!json_object_has_member(root, "box")) { LOGE("No box outputmetadata"); LOGI("LEAVE"); return MEDIA_VISION_ERROR_NONE; @@ -202,7 +202,7 @@ namespace inference { LOGI("ENTER"); - if (json_object_has_member(root, "label") == false) { + if (!json_object_has_member(root, "label")) { LOGE("No box outputmetadata"); LOGI("LEAVE"); return MEDIA_VISION_ERROR_INVALID_OPERATION; @@ -244,7 +244,7 @@ namespace inference { LOGI("ENTER"); - if (json_object_has_member(root, "number") == false) { + if (!json_object_has_member(root, "number")) { LOGE("No number outputmetadata"); LOGI("LEAVE"); return MEDIA_VISION_ERROR_INVALID_OPERATION; @@ -259,7 +259,7 @@ namespace inference { LOGI("ENTER"); - if (json_object_has_member(root, "box") == false) { + if (!json_object_has_member(root, "box")) { LOGE("No box outputmetadata"); LOGI("LEAVE"); return MEDIA_VISION_ERROR_NONE; @@ -274,7 +274,7 @@ namespace inference JsonNode *pNode = json_array_get_element(rootArray, elem); JsonObject *pObject = json_node_get_object(pNode); - if (json_object_has_member(pObject, "decoding_info") == false) { + if (!json_object_has_member(pObject, "decoding_info")) { LOGE("decoding_info is mandatory. Invalid metadata"); LOGI("LEAVE"); @@ -282,7 +282,7 @@ namespace inference } JsonObject *cObject = json_object_get_object_member(pObject, "decoding_info"); - if (json_object_has_member(cObject, "anchor") == false) { + if (!json_object_has_member(cObject, "anchor")) { LOGE("anchor is mandatory. Invalid metadata"); LOGI("LEAVE"); @@ -499,7 +499,7 @@ namespace inference int BoxInfo::DecodeInfo::ParseNms(JsonObject *root) { - if (json_object_has_member(root, "nms") == false) { + if (!json_object_has_member(root, "nms")) { LOGI("nms is empty. skip it"); return MEDIA_VISION_ERROR_NONE; } @@ -523,7 +523,7 @@ namespace inference int BoxInfo::DecodeInfo::ParseRotate(JsonObject *root) { - if (json_object_has_member(root, "rotate") == false) { + if (!json_object_has_member(root, "rotate")) { LOGI("rotate is empty. skip it"); return MEDIA_VISION_ERROR_NONE; } @@ -593,7 +593,7 @@ namespace inference int BoxInfo::DecodeInfo::ParseRoiOption(JsonObject *root) { - if (json_object_has_member(root, "roi") == false) { + if (!json_object_has_member(root, "roi")) { LOGI("roi is empty. skip it"); return MEDIA_VISION_ERROR_NONE; } @@ -731,7 +731,7 @@ namespace inference { LOGI("ENTER"); - if (json_object_has_member(root, "landmark") == false) { + if (!json_object_has_member(root, "landmark")) { LOGI("No landmark outputmetadata"); LOGI("LEAVE"); return MEDIA_VISION_ERROR_NONE; @@ -747,7 +747,7 @@ namespace inference { LOGI("ENTER"); - if (json_object_has_member(root, "landmark") == false) { + if (!json_object_has_member(root, "landmark")) { LOGI("No landmark outputmetadata"); LOGI("LEAVE"); return MEDIA_VISION_ERROR_NONE; @@ -763,7 +763,7 @@ namespace inference JsonNode *pNode = json_array_get_element(rootArray, elem); JsonObject *pObject = json_node_get_object(pNode); - if (json_object_has_member(pObject, "decoding_info") == false) { + if (!json_object_has_member(pObject, "decoding_info")) { LOGE("decoding_info is mandatory. Invalid metadata"); LOGI("LEAVE"); @@ -771,7 +771,7 @@ namespace inference } JsonObject *cObject = json_object_get_object_member(pObject, "decoding_info"); - if (json_object_has_member(cObject, "heatmap") == false) { + if (!json_object_has_member(cObject, "heatmap")) { LOGE("heatmap is mandatory. Invalid metadata"); LOGI("LEAVE"); @@ -840,7 +840,7 @@ namespace inference { LOGI("ENTER"); - if (json_object_has_member(root, "offset") == false) { + if (!json_object_has_member(root, "offset")) { LOGI("No offset outputmetadata"); LOGI("LEAVE"); return MEDIA_VISION_ERROR_INVALID_OPERATION; @@ -884,7 +884,7 @@ namespace inference { LOGI("ENTER"); - if (json_object_has_member(root, "displacement") == false) { + if (!json_object_has_member(root, "displacement")) { LOGI("No displacement outputmetadata"); LOGI("LEAVE"); return MEDIA_VISION_ERROR_INVALID_OPERATION; @@ -932,7 +932,7 @@ namespace inference { LOGI("ENTER"); - if (json_object_has_member(root, "edgemap") == false) { + if (!json_object_has_member(root, "edgemap")) { LOGI("No edgemap outputmetadata"); LOGI("LEAVE"); return MEDIA_VISION_ERROR_INVALID_OPERATION; diff --git a/packaging/capi-media-vision.spec b/packaging/capi-media-vision.spec index 18e1793..6b97410 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.8.5 +Version: 0.8.6 Release: 0 Group: Multimedia/Framework License: Apache-2.0 and BSD-3-Clause -- 2.7.4 From 40b0ed0dcca342ceef6ff9de004e3d352c5fef0e Mon Sep 17 00:00:00 2001 From: Kwang Son Date: Tue, 17 Aug 2021 05:26:32 -0400 Subject: [PATCH 11/16] test: Add Image classicifation models Change-Id: Ie394dedaf72ffbfc76b2f69d41ddf6ee4c83cfaf Signed-off-by: Kwang Son --- .../inference/test_image_classification.cpp | 100 ++++++++++++++++++--- 1 file changed, 88 insertions(+), 12 deletions(-) diff --git a/test/testsuites/machine_learning/inference/test_image_classification.cpp b/test/testsuites/machine_learning/inference/test_image_classification.cpp index 96f8075..7c6bc0c 100644 --- a/test/testsuites/machine_learning/inference/test_image_classification.cpp +++ b/test/testsuites/machine_learning/inference/test_image_classification.cpp @@ -1,4 +1,5 @@ #include +#include #include #include "test_inference_helper.hpp" @@ -11,13 +12,37 @@ #define IMG_BANANA \ MV_CONFIG_PATH \ "/res/inference/images/banana.jpg" +#define IC_TFLITE_WEIGHT_MOBILENET_V2_224_PATH \ + MV_CONFIG_PATH \ + "/models/IC/tflite/ic_mobilenet_v2_224x224.tflite" +#define IC_TFLITE_WEIGHT_DENSENET_224_PATH \ + MV_CONFIG_PATH \ + "/models/IC/tflite/ic_densenet_224x224.tflite" +#define IC_TFLITE_WEIGHT_NASNET_224_PATH \ + MV_CONFIG_PATH \ + "/models/IC/tflite/ic_nasnet_224x224.tflite" +#define IC_TFLITE_WEIGHT_MNASNET_224_PATH \ + MV_CONFIG_PATH \ + "/models/IC/tflite/ic_mnasnet_224x224.tflite" +#define IC_TFLITE_WEIGHT_SQUEEZENET_224_PATH \ + MV_CONFIG_PATH \ + "/models/IC/tflite/ic_squeezenet_224x224.tflite" +#define IC_TFLITE_WEIGHT_QUANT_MOBILENET_V1_224_PATH \ + MV_CONFIG_PATH \ + "/models/IC/tflite/quant_mobilenet_v1_224x224.tflite" 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) { - ASSERT_EQ(number_of_classes, 1); - EXPECT_STREQ(names[0], "banana"); + const std::string answer = "banana"; + auto answer_found = false; + for (int i = 0; i < number_of_classes; i++) { + if (answer == names[i]) { + answer_found = true; + } + } + EXPECT_TRUE(answer_found); } class TestImageClassification : public ::testing::Test @@ -37,6 +62,18 @@ public: EXPECT_EQ(mv_destroy_engine_config(engine_cfg), MEDIA_VISION_ERROR_NONE); } + void inference_banana() + { + 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_BANANA, mv_source), + MEDIA_VISION_ERROR_NONE); + ASSERT_EQ(mv_inference_image_classify(mv_source, infer, NULL, + _image_classified_cb, NULL), + MEDIA_VISION_ERROR_NONE); + } mv_engine_config_h engine_cfg; mv_inference_h infer; mv_source_h mv_source; @@ -47,14 +84,53 @@ TEST_F(TestImageClassification, CPU_TFLITE_MobilenetV1) engine_config_hosted_cpu_tflite_user_model( engine_cfg, IC_TFLITE_WEIGHT_MOBILENET_V1_224_PATH, IC_LABEL_MOBILENET_V1_224_PATH); - EXPECT_EQ(mv_inference_configure(infer, engine_cfg), - MEDIA_VISION_ERROR_NONE); - EXPECT_EQ(mv_inference_prepare(infer), MEDIA_VISION_ERROR_NONE); - EXPECT_EQ(MediaVision::Common::ImageHelper::loadImageToSource(IMG_BANANA, - mv_source), - MEDIA_VISION_ERROR_NONE); - EXPECT_EQ(mv_inference_image_classify(mv_source, infer, NULL, - _image_classified_cb, NULL), - MEDIA_VISION_ERROR_NONE); - EXPECT_EQ(mv_source_clear(mv_source), MEDIA_VISION_ERROR_NONE); + inference_banana(); +} + +TEST_F(TestImageClassification, CPU_TFLITE_MobilenetV2) +{ + engine_config_hosted_cpu_tflite_user_model( + engine_cfg, IC_TFLITE_WEIGHT_MOBILENET_V2_224_PATH, + IC_LABEL_MOBILENET_V1_224_PATH); + inference_banana(); +} + +TEST_F(TestImageClassification, CPU_TFLITE_Densenet) +{ + engine_config_hosted_cpu_tflite_user_model( + engine_cfg, IC_TFLITE_WEIGHT_DENSENET_224_PATH, + IC_LABEL_MOBILENET_V1_224_PATH); + inference_banana(); } + +TEST_F(TestImageClassification, CPU_TFLITE_Nasnet) +{ + engine_config_hosted_cpu_tflite_user_model(engine_cfg, + IC_TFLITE_WEIGHT_NASNET_224_PATH, + IC_LABEL_MOBILENET_V1_224_PATH); + inference_banana(); +} + +TEST_F(TestImageClassification, CPU_TFLITE_MNasnet) +{ + engine_config_hosted_cpu_tflite_user_model( + engine_cfg, IC_TFLITE_WEIGHT_MNASNET_224_PATH, + IC_LABEL_MOBILENET_V1_224_PATH); + inference_banana(); +} + +TEST_F(TestImageClassification, CPU_TFLITE_Squeezenet) +{ + engine_config_hosted_cpu_tflite_user_model( + engine_cfg, IC_TFLITE_WEIGHT_SQUEEZENET_224_PATH, + IC_LABEL_MOBILENET_V1_224_PATH); + inference_banana(); +} + +TEST_F(TestImageClassification, CPU_TFLITE_QUANT_MobilenetV1) +{ + engine_config_hosted_cpu_tflite_user_model( + engine_cfg, IC_TFLITE_WEIGHT_QUANT_MOBILENET_V1_224_PATH, + IC_LABEL_MOBILENET_V1_224_PATH); + inference_banana(); +} \ No newline at end of file -- 2.7.4 From 230c3da7525c3ab337b214879f29aa9b44e43127 Mon Sep 17 00:00:00 2001 From: Tae-Young Chung Date: Tue, 17 Aug 2021 18:35:02 +0900 Subject: [PATCH 12/16] Change inputmetadata's shape_type, data_type, color_space to string Those metadata are user unfriendly and difficult to use because of a lack of decscription. They are changed to string and user can understand what they mean. The string values are parsed and converted to proper enumerations. Change-Id: Ia98f29790d68fe2bf2fb38e2e922cc0b9b4d80e4 Signed-off-by: Tae-Young Chung --- meta-template/README.md | 6 +-- meta-template/fd_blazeface_front_128x128.json | 4 +- .../fd_mobilenet_v1_ssd_postop_300x300.json | 4 +- meta-template/fld_mediapipe_192x192.json | 4 +- meta-template/fld_tweakcnn_128x128.json | 4 +- meta-template/ic_densenet_224x224.json | 4 +- meta-template/ic_inception_resnet_v2_299x299.json | 4 +- meta-template/ic_inception_v3_299x299.json | 4 +- meta-template/ic_inception_v4_299x299.json | 4 +- meta-template/ic_mnasnet_224x224.json | 4 +- meta-template/ic_mobilenet_v1_224x224.json | 4 +- meta-template/ic_mobilenet_v2_224x224.json | 4 +- meta-template/ic_nasnet_224x224.json | 4 +- meta-template/ic_resnet_v2_299x299.json | 4 +- meta-template/ic_squeezenet_224x224.json | 4 +- meta-template/image-classification-001-meta.json | 4 +- .../image-classification-quant-001-meta.json | 4 +- .../od_mobilenet_v1_ssd_postop_300x300.json | 4 +- meta-template/od_mobilenet_v2_ssd_320x320.json | 4 +- meta-template/pld_cpm_192x192.json | 4 +- .../pld_mobilenet_v1_posenet_multi_257x257.json | 4 +- .../mv_inference/inference/include/InputMetadata.h | 10 +++- .../mv_inference/inference/src/InputMetadata.cpp | 61 +++++++++++++--------- packaging/capi-media-vision.spec | 2 +- 24 files changed, 88 insertions(+), 71 deletions(-) diff --git a/meta-template/README.md b/meta-template/README.md index 1e31cfc..f7fda1e 100644 --- a/meta-template/README.md +++ b/meta-template/README.md @@ -11,9 +11,9 @@ The Meta file consists of 1) inputmetadata and 2) outputmetadata. For example, a "tensor_info" : [ { "name" : "input_2", - "shape_type" : 1, + "shape_type" : "NHWC", "shape_dims" : [ 1, 224, 224, 3], - "data_type" : 0, + "data_type" : "FLOAT32", "color_space" : "RGB888" } ], @@ -47,7 +47,7 @@ In the classification meta file, the `inputmetadata` includes `tensor_info` which has knowledge of an input tensor such as - `name`: name to an input tensor -- `shape_type`: shape type of the input tensor on `NCHW = 0` and `NHWC = 1` +- `shape_type`: shape type of the input tensor on `NCHW` and `NHWC` - `shape_dims`: shape dimensions based on the `shape_type` - `data_type`: data type of the input tensor on `MV_INFERENCE_DATA_FLOAT32 = 0` and `MV_INFERENCE_DATA_UINT8 = 1` - `color_space`: color space of the input tensor. diff --git a/meta-template/fd_blazeface_front_128x128.json b/meta-template/fd_blazeface_front_128x128.json index 4c94a03..a7c8041 100644 --- a/meta-template/fd_blazeface_front_128x128.json +++ b/meta-template/fd_blazeface_front_128x128.json @@ -4,9 +4,9 @@ "tensor_info" : [ { "name" : "input", - "shape_type" : 1, + "shape_type" : "NHWC", "shape_dims" : [ 1, 128, 128, 3], - "data_type" : 0, + "data_type" : "FLOAT32", "color_space" : "RGB888" } ], diff --git a/meta-template/fd_mobilenet_v1_ssd_postop_300x300.json b/meta-template/fd_mobilenet_v1_ssd_postop_300x300.json index e9aa00b..75b5d65 100644 --- a/meta-template/fd_mobilenet_v1_ssd_postop_300x300.json +++ b/meta-template/fd_mobilenet_v1_ssd_postop_300x300.json @@ -4,9 +4,9 @@ "tensor_info" : [ { "name" : "normalized_input_image_tensor", - "shape_type" : 1, + "shape_type" : "NHWC", "shape_dims" : [ 1, 300, 300, 3], - "data_type" : 0, + "data_type" : "FLOAT32", "color_space" : "RGB888" } ], diff --git a/meta-template/fld_mediapipe_192x192.json b/meta-template/fld_mediapipe_192x192.json index 562fb77..ad266a8 100644 --- a/meta-template/fld_mediapipe_192x192.json +++ b/meta-template/fld_mediapipe_192x192.json @@ -4,9 +4,9 @@ "tensor_info" : [ { "name" : "input", - "shape_type" : 1, + "shape_type" : "NHWC", "shape_dims" : [ 1, 192, 192, 3], - "data_type" : 0, + "data_type" : "FLOAT32", "color_space" : "RGB888" } ], diff --git a/meta-template/fld_tweakcnn_128x128.json b/meta-template/fld_tweakcnn_128x128.json index 7d8b48f..0c30ad3 100644 --- a/meta-template/fld_tweakcnn_128x128.json +++ b/meta-template/fld_tweakcnn_128x128.json @@ -4,9 +4,9 @@ "tensor_info" : [ { "name" : "Placeholder", - "shape_type" : 1, + "shape_type" : "NHWC", "shape_dims" : [ 1, 128, 128, 3], - "data_type" : 0, + "data_type" : "FLOAT32", "color_space" : "RGB888" } ], diff --git a/meta-template/ic_densenet_224x224.json b/meta-template/ic_densenet_224x224.json index 9a69d01..3e69393 100644 --- a/meta-template/ic_densenet_224x224.json +++ b/meta-template/ic_densenet_224x224.json @@ -4,9 +4,9 @@ "tensor_info" : [ { "name" : "Placeholder", - "shape_type" : 1, + "shape_type" : "NHWC", "shape_dims" : [ 1, 224, 224, 3], - "data_type" : 0, + "data_type" : "FLOAT32", "color_space" : "RGB888" } ], diff --git a/meta-template/ic_inception_resnet_v2_299x299.json b/meta-template/ic_inception_resnet_v2_299x299.json index 87d87da..34d934a 100644 --- a/meta-template/ic_inception_resnet_v2_299x299.json +++ b/meta-template/ic_inception_resnet_v2_299x299.json @@ -4,9 +4,9 @@ "tensor_info" : [ { "name" : "input", - "shape_type" : 1, + "shape_type" : "NHWC", "shape_dims" : [ 1, 299, 299, 3], - "data_type" : 0, + "data_type" : "FLOAT32", "color_space" : "RGB888" } ], diff --git a/meta-template/ic_inception_v3_299x299.json b/meta-template/ic_inception_v3_299x299.json index 7c2ef9f..6e8c3f2 100644 --- a/meta-template/ic_inception_v3_299x299.json +++ b/meta-template/ic_inception_v3_299x299.json @@ -4,9 +4,9 @@ "tensor_info" : [ { "name" : "input", - "shape_type" : 1, + "shape_type" : "NHWC", "shape_dims" : [ 1, 299, 299, 3], - "data_type" : 0, + "data_type" : "FLOAT32", "color_space" : "RGB888" } ], diff --git a/meta-template/ic_inception_v4_299x299.json b/meta-template/ic_inception_v4_299x299.json index 8cd3f47..4d31be4 100644 --- a/meta-template/ic_inception_v4_299x299.json +++ b/meta-template/ic_inception_v4_299x299.json @@ -4,9 +4,9 @@ "tensor_info" : [ { "name" : "input", - "shape_type" : 1, + "shape_type" : "NHWC", "shape_dims" : [ 1, 299, 299, 3], - "data_type" : 0, + "data_type" : "FLOAT32", "color_space" : "RGB888" } ], diff --git a/meta-template/ic_mnasnet_224x224.json b/meta-template/ic_mnasnet_224x224.json index 83938df..e7eecf4 100644 --- a/meta-template/ic_mnasnet_224x224.json +++ b/meta-template/ic_mnasnet_224x224.json @@ -4,9 +4,9 @@ "tensor_info" : [ { "name" : "input", - "shape_type" : 1, + "shape_type" : "NHWC", "shape_dims" : [ 1, 224, 224, 3], - "data_type" : 0, + "data_type" : "FLOAT32", "color_space" : "RGB888" } ], diff --git a/meta-template/ic_mobilenet_v1_224x224.json b/meta-template/ic_mobilenet_v1_224x224.json index 2599d8c..c68f146 100644 --- a/meta-template/ic_mobilenet_v1_224x224.json +++ b/meta-template/ic_mobilenet_v1_224x224.json @@ -4,9 +4,9 @@ "tensor_info" : [ { "name" : "input", - "shape_type" : 1, + "shape_type" : "NHWC", "shape_dims" : [ 1, 224, 224, 3], - "data_type" : 0, + "data_type" : "FLOAT32", "color_space" : "RGB888" } ], diff --git a/meta-template/ic_mobilenet_v2_224x224.json b/meta-template/ic_mobilenet_v2_224x224.json index c0c976b..c2bee18 100644 --- a/meta-template/ic_mobilenet_v2_224x224.json +++ b/meta-template/ic_mobilenet_v2_224x224.json @@ -4,9 +4,9 @@ "tensor_info" : [ { "name" : "input", - "shape_type" : 1, + "shape_type" : "NHWC", "shape_dims" : [ 1, 224, 224, 3], - "data_type" : 0, + "data_type" : "FLOAT32", "color_space" : "RGB888" } ], diff --git a/meta-template/ic_nasnet_224x224.json b/meta-template/ic_nasnet_224x224.json index 8448561..32769db 100644 --- a/meta-template/ic_nasnet_224x224.json +++ b/meta-template/ic_nasnet_224x224.json @@ -4,9 +4,9 @@ "tensor_info" : [ { "name" : "input", - "shape_type" : 1, + "shape_type" : "NHWC", "shape_dims" : [ 1, 224, 224, 3], - "data_type" : 0, + "data_type" : "FLOAT32", "color_space" : "RGB888" } ], diff --git a/meta-template/ic_resnet_v2_299x299.json b/meta-template/ic_resnet_v2_299x299.json index 865652c..8e6f723 100644 --- a/meta-template/ic_resnet_v2_299x299.json +++ b/meta-template/ic_resnet_v2_299x299.json @@ -4,9 +4,9 @@ "tensor_info" : [ { "name" : "input", - "shape_type" : 1, + "shape_type" : "NHWC", "shape_dims" : [ 1, 299, 299, 3], - "data_type" : 0, + "data_type" : "FLOAT32", "color_space" : "RGB888" } ], diff --git a/meta-template/ic_squeezenet_224x224.json b/meta-template/ic_squeezenet_224x224.json index fdf00e2..b0e8f34 100644 --- a/meta-template/ic_squeezenet_224x224.json +++ b/meta-template/ic_squeezenet_224x224.json @@ -4,9 +4,9 @@ "tensor_info" : [ { "name" : "Placeholder", - "shape_type" : 1, + "shape_type" : "NHWC", "shape_dims" : [ 1, 224, 224, 3], - "data_type" : 0, + "data_type" : "FLOAT32", "color_space" : "RGB888" } ], diff --git a/meta-template/image-classification-001-meta.json b/meta-template/image-classification-001-meta.json index 151908c..a89bc97 100644 --- a/meta-template/image-classification-001-meta.json +++ b/meta-template/image-classification-001-meta.json @@ -4,9 +4,9 @@ "tensor_info" : [ { "name" : "input_2", - "shape_type" : 1, + "shape_type" : "NHWC", "shape_dims" : [ 1, 224, 224, 3], - "data_type" : 0, + "data_type" : "FLOAT32", "color_space" : "RGB888" } ], diff --git a/meta-template/image-classification-quant-001-meta.json b/meta-template/image-classification-quant-001-meta.json index 9a44eab..1936dbd 100644 --- a/meta-template/image-classification-quant-001-meta.json +++ b/meta-template/image-classification-quant-001-meta.json @@ -4,9 +4,9 @@ "tensor_info" : [ { "name" : "input", - "shape_type" : 1, + "shape_type" : "NHWC", "shape_dims" : [ 1, 224, 224, 3], - "data_type" : 1, + "data_type" : "UNIT8", "color_space" : "RGB888" } ] diff --git a/meta-template/od_mobilenet_v1_ssd_postop_300x300.json b/meta-template/od_mobilenet_v1_ssd_postop_300x300.json index e9aa00b..75b5d65 100644 --- a/meta-template/od_mobilenet_v1_ssd_postop_300x300.json +++ b/meta-template/od_mobilenet_v1_ssd_postop_300x300.json @@ -4,9 +4,9 @@ "tensor_info" : [ { "name" : "normalized_input_image_tensor", - "shape_type" : 1, + "shape_type" : "NHWC", "shape_dims" : [ 1, 300, 300, 3], - "data_type" : 0, + "data_type" : "FLOAT32", "color_space" : "RGB888" } ], diff --git a/meta-template/od_mobilenet_v2_ssd_320x320.json b/meta-template/od_mobilenet_v2_ssd_320x320.json index 6574f70..826640c 100644 --- a/meta-template/od_mobilenet_v2_ssd_320x320.json +++ b/meta-template/od_mobilenet_v2_ssd_320x320.json @@ -4,9 +4,9 @@ "tensor_info" : [ { "name" : "normalized_input_image_tensor", - "shape_type" : 1, + "shape_type" : "NHWC", "shape_dims" : [ 1, 320, 320, 3], - "data_type" : 0, + "data_type" : "FLOAT32", "color_space" : "RGB888" } ], diff --git a/meta-template/pld_cpm_192x192.json b/meta-template/pld_cpm_192x192.json index e4f573b..3bee725 100644 --- a/meta-template/pld_cpm_192x192.json +++ b/meta-template/pld_cpm_192x192.json @@ -4,9 +4,9 @@ "tensor_info" : [ { "name" : "image", - "shape_type" : 1, + "shape_type" : "NHWC", "shape_dims" : [ 1, 192, 192, 3], - "data_type" : 0, + "data_type" : "FLOAT32", "color_space" : "RGB888" } ], diff --git a/meta-template/pld_mobilenet_v1_posenet_multi_257x257.json b/meta-template/pld_mobilenet_v1_posenet_multi_257x257.json index 1d69c7a..44b942c 100644 --- a/meta-template/pld_mobilenet_v1_posenet_multi_257x257.json +++ b/meta-template/pld_mobilenet_v1_posenet_multi_257x257.json @@ -4,9 +4,9 @@ "tensor_info" : [ { "name" : "sub_2", - "shape_type" : 1, + "shape_type" : "NHWC", "shape_dims" : [ 1, 257, 257, 3], - "data_type" : 0, + "data_type" : "FLOAT32", "color_space" : "RGB888" } ], diff --git a/mv_machine_learning/mv_inference/inference/include/InputMetadata.h b/mv_machine_learning/mv_inference/inference/include/InputMetadata.h index 01da01c..8b5e2bd 100644 --- a/mv_machine_learning/mv_inference/inference/include/InputMetadata.h +++ b/mv_machine_learning/mv_inference/inference/include/InputMetadata.h @@ -97,7 +97,7 @@ namespace inference * * @since_tizen 6.5 */ - InputMetadata() : parsed(false) {}; + InputMetadata(); /** * @brief Destroys an InputMetadata class instance including @@ -115,9 +115,15 @@ namespace inference int Parse(JsonObject *root); private: + std::map mSupportedShapeType; + std::map mSupportedDataType; + std::map mSupportedColorSpace; + + template + static T GetSupportedType(JsonObject* root, std::string typeName, + std::map& supportedTypes); int GetTensorInfo(JsonObject* root); int GetPreProcess(JsonObject* root); - mv_colorspace_e ConvertTypeToMD(const std::string& type); }; diff --git a/mv_machine_learning/mv_inference/inference/src/InputMetadata.cpp b/mv_machine_learning/mv_inference/inference/src/InputMetadata.cpp index befbd43..66d257c 100644 --- a/mv_machine_learning/mv_inference/inference/src/InputMetadata.cpp +++ b/mv_machine_learning/mv_inference/inference/src/InputMetadata.cpp @@ -28,23 +28,36 @@ namespace mediavision { namespace inference { - mv_colorspace_e InputMetadata::ConvertTypeToMD(const std::string& type) + InputMetadata::InputMetadata() : + parsed(false), + layer(), + option() { - mv_colorspace_e colorspace = MEDIA_VISION_COLORSPACE_INVALID; - if (type.empty()) { - LOGE("Invalid type[null]"); - return colorspace; - } + // shape_type + mSupportedShapeType.insert({"NCHW", INFERENCE_TENSOR_SHAPE_NCHW}); + mSupportedShapeType.insert({"NHWC", INFERENCE_TENSOR_SHAPE_NHWC}); + + // data_type + mSupportedDataType.insert({"FLOAT32", MV_INFERENCE_DATA_FLOAT32}); + mSupportedDataType.insert({"UINT8", MV_INFERENCE_DATA_UINT8}); - if (type.compare("RGB888") == 0) { - colorspace = MEDIA_VISION_COLORSPACE_RGB888; - } else if (type.compare("Y800") == 0) { - colorspace = MEDIA_VISION_COLORSPACE_Y800; - } else { - LOGE("Not supported channel type"); + // color_space + mSupportedColorSpace.insert({"RGB888", MEDIA_VISION_COLORSPACE_RGB888}); + mSupportedColorSpace.insert({"GRAY8", MEDIA_VISION_COLORSPACE_Y800}); + } + + template + T InputMetadata::GetSupportedType(JsonObject* root, std::string typeName, + std::map& supportedTypes) + { + auto supportedType = supportedTypes.find(json_object_get_string_member(root, typeName.c_str())); + if (supportedType == supportedTypes.end()) { + throw std::invalid_argument(typeName); } - return colorspace; + LOGI("%s: %d:%s", typeName.c_str(), supportedType->second, supportedType->first.c_str()); + + return supportedType->second; } int InputMetadata::GetTensorInfo(JsonObject *root) @@ -57,6 +70,7 @@ namespace inference } // tensor_info + int ret = MEDIA_VISION_ERROR_NONE; JsonArray * rootArray = json_object_get_array_member(root, "tensor_info"); unsigned int elements = json_array_get_length(rootArray); @@ -72,17 +86,14 @@ namespace inference static_cast(json_object_get_string_member(pObject,"name")); LOGI("layer: %s", info.name.c_str()); - info.shapeType = - static_cast(json_object_get_int_member(pObject, "shape_type")); - LOGI("shape type: %d:%s", info.shapeType, info.shapeType == 0 ? "NCHW" : "NHWC"); - - info.dataType = - static_cast(json_object_get_int_member(pObject, "data_type")); - LOGI("data type : %d:%s", info.dataType, info.dataType == 0 ? "FLOAT32" : "UINT8"); - - const char *colorSpace = static_cast(json_object_get_string_member(pObject,"color_space")); - info.colorSpace = ConvertTypeToMD(std::string(colorSpace)); - LOGI("color space : %d:%s", info.colorSpace, info.colorSpace == MEDIA_VISION_COLORSPACE_RGB888 ? "RGB888" : ""); + try { + info.shapeType = GetSupportedType(pObject, "shape_type", mSupportedShapeType); + info.dataType = GetSupportedType(pObject, "data_type", mSupportedDataType); + info.colorSpace = GetSupportedType(pObject, "color_space", mSupportedColorSpace); + } catch (const std::exception& e) { + LOGE("Invalid %s", e.what()); + return MEDIA_VISION_ERROR_INVALID_OPERATION; + } // dims JsonArray * array = json_object_get_array_member(pObject, "shape_dims"); @@ -99,7 +110,7 @@ namespace inference LOGI("LEAVE"); - return MEDIA_VISION_ERROR_NONE; + return ret; } int InputMetadata::GetPreProcess(JsonObject *root) diff --git a/packaging/capi-media-vision.spec b/packaging/capi-media-vision.spec index 6b97410..1462ad3 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.8.6 +Version: 0.8.7 Release: 0 Group: Multimedia/Framework License: Apache-2.0 and BSD-3-Clause -- 2.7.4 From 51211a955871f8506594dd13e470c192702eed12 Mon Sep 17 00:00:00 2001 From: Kwang Son Date: Tue, 17 Aug 2021 23:12:11 -0400 Subject: [PATCH 13/16] test: Reduce memcpy in loadImageToSource loadImageToBuffer and mv_source_fill_by_buffer has own memcpy functions which are duplicated. - Before patch [ PASSED ] 117 tests. real 0m24.457s user 0m23.040s sys 0m6.565s - After patch [ PASSED ] 117 tests. real 0m23.857s user 0m22.802s sys 0m6.085s Change-Id: Ibc6dbcc01a1b4a768ea6a8b9311f3484008e4ff0 Signed-off-by: Kwang Son --- test/testsuites/common/image_helper/CMakeLists.txt | 4 +-- .../common/image_helper/src/ImageHelper.cpp | 32 +++++++--------------- 2 files changed, 12 insertions(+), 24 deletions(-) diff --git a/test/testsuites/common/image_helper/CMakeLists.txt b/test/testsuites/common/image_helper/CMakeLists.txt index e96a744..be4ec3f 100644 --- a/test/testsuites/common/image_helper/CMakeLists.txt +++ b/test/testsuites/common/image_helper/CMakeLists.txt @@ -18,6 +18,6 @@ else() add_library(${PROJECT_NAME} SHARED ${MV_IMAGE_HELPER_SRC_LIST}) endif() -target_include_directories(${PROJECT_NAME} PUBLIC include ${OpenCV_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR}/include ${${PROJECT_NAME}_DEP_INCLUDE_DIRS}) -target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS}) +target_include_directories(${PROJECT_NAME} PUBLIC include) +target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS} ${${PROJECT_NAME}_DEP_LIBRARIES} mv_common) install(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR}) diff --git a/test/testsuites/common/image_helper/src/ImageHelper.cpp b/test/testsuites/common/image_helper/src/ImageHelper.cpp index fa123cc..66c164f 100644 --- a/test/testsuites/common/image_helper/src/ImageHelper.cpp +++ b/test/testsuites/common/image_helper/src/ImageHelper.cpp @@ -16,7 +16,6 @@ #include "ImageHelper.h" #include "mv_private.h" - #include #include @@ -28,6 +27,7 @@ #include #include #include +#include /** * @file ImageHelper.cpp @@ -89,30 +89,18 @@ int ImageHelper::loadImageToBuffer( int ImageHelper::loadImageToSource(const char *filePath, mv_source_h source) { - unsigned char *data_buffer = NULL; - unsigned long buffer_size = 0; - ImageData image_data; - - int err = loadImageToBuffer(filePath, &data_buffer, &buffer_size, - &image_data); - if (MEDIA_VISION_ERROR_NONE != err) { - printf("ERROR: Errors were occurred during opening file!!! code: %i\n", - err); - return err; - } + if (filePath == nullptr || source == nullptr) + return MEDIA_VISION_ERROR_INVALID_PARAMETER; - err = mv_source_fill_by_buffer(source, data_buffer, buffer_size, - image_data.imageWidth, - image_data.imageHeight, - image_data.imageColorspace); + MediaSource *mediaSource = static_cast(source); + cv::Mat image = cv::imread(filePath); + cv::cvtColor(image, image, CV_BGR2RGB); - if (MEDIA_VISION_ERROR_NONE != err) - printf("ERROR: Errors were occurred during filling source!!! code %i\n", - err); + if (!(mediaSource->fill(image.data, image.total() * image.elemSize(), + image.cols, image.rows, OPEN_CV_COLOR))) + return MEDIA_VISION_ERROR_OUT_OF_MEMORY; - if (NULL != data_buffer) - destroyLoadedBuffer(data_buffer); - return err; + return MEDIA_VISION_ERROR_NONE; } int ImageHelper::saveImageFromBuffer( -- 2.7.4 From cf2f533e63f85ac1e70f429a28a7a9ebceeefbc9 Mon Sep 17 00:00:00 2001 From: Kwang Son Date: Wed, 18 Aug 2021 04:15:32 -0400 Subject: [PATCH 14/16] test: Add ObjectDetection test Add inference dog object detection test. Move common shared code to helper test class. Change-Id: I7c02d62fa1c45422ecd5550853adaf39f7fc6a5a Signed-off-by: Kwang Son --- test/CMakeLists.txt | 1 + .../inference/test_image_classification.cpp | 35 ++++---------- .../inference/test_inference_helper.cpp | 13 ++++++ .../inference/test_inference_helper.hpp | 10 ++++ .../inference/test_object_detection.cpp | 54 ++++++++++++++++++++++ 5 files changed, 87 insertions(+), 26 deletions(-) create mode 100644 test/testsuites/machine_learning/inference/test_object_detection.cpp diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 43c7e23..d2fcd07 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -9,6 +9,7 @@ add_executable(${PROJECT_NAME} testsuites/barcode/test_barcode.cpp testsuites/machine_learning/inference/test_inference_helper.cpp testsuites/machine_learning/inference/test_image_classification.cpp + testsuites/machine_learning/inference/test_object_detection.cpp ) target_link_libraries(${PROJECT_NAME} ${${PROJECT_NAME}_DEP_LIBRARIES} 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_image_classification.cpp b/test/testsuites/machine_learning/inference/test_image_classification.cpp index 7c6bc0c..2a13d06 100644 --- a/test/testsuites/machine_learning/inference/test_image_classification.cpp +++ b/test/testsuites/machine_learning/inference/test_image_classification.cpp @@ -45,24 +45,10 @@ void _image_classified_cb(mv_source_h source, const int number_of_classes, EXPECT_TRUE(answer_found); } -class TestImageClassification : public ::testing::Test +class TestImageClassification : public TestInference { public: - TestImageClassification() - { - EXPECT_EQ(mv_create_engine_config(&engine_cfg), - MEDIA_VISION_ERROR_NONE); - EXPECT_EQ(mv_inference_create(&infer), MEDIA_VISION_ERROR_NONE); - EXPECT_EQ(mv_create_source(&mv_source), MEDIA_VISION_ERROR_NONE); - } - ~TestImageClassification() - { - EXPECT_EQ(mv_destroy_source(mv_source), MEDIA_VISION_ERROR_NONE); - EXPECT_EQ(mv_inference_destroy(infer), MEDIA_VISION_ERROR_NONE); - EXPECT_EQ(mv_destroy_engine_config(engine_cfg), - MEDIA_VISION_ERROR_NONE); - } - void inference_banana() + void inferenceBanana() { ASSERT_EQ(mv_inference_configure(infer, engine_cfg), MEDIA_VISION_ERROR_NONE); @@ -74,9 +60,6 @@ public: _image_classified_cb, NULL), MEDIA_VISION_ERROR_NONE); } - mv_engine_config_h engine_cfg; - mv_inference_h infer; - mv_source_h mv_source; }; TEST_F(TestImageClassification, CPU_TFLITE_MobilenetV1) @@ -84,7 +67,7 @@ TEST_F(TestImageClassification, CPU_TFLITE_MobilenetV1) engine_config_hosted_cpu_tflite_user_model( engine_cfg, IC_TFLITE_WEIGHT_MOBILENET_V1_224_PATH, IC_LABEL_MOBILENET_V1_224_PATH); - inference_banana(); + inferenceBanana(); } TEST_F(TestImageClassification, CPU_TFLITE_MobilenetV2) @@ -92,7 +75,7 @@ TEST_F(TestImageClassification, CPU_TFLITE_MobilenetV2) engine_config_hosted_cpu_tflite_user_model( engine_cfg, IC_TFLITE_WEIGHT_MOBILENET_V2_224_PATH, IC_LABEL_MOBILENET_V1_224_PATH); - inference_banana(); + inferenceBanana(); } TEST_F(TestImageClassification, CPU_TFLITE_Densenet) @@ -100,7 +83,7 @@ TEST_F(TestImageClassification, CPU_TFLITE_Densenet) engine_config_hosted_cpu_tflite_user_model( engine_cfg, IC_TFLITE_WEIGHT_DENSENET_224_PATH, IC_LABEL_MOBILENET_V1_224_PATH); - inference_banana(); + inferenceBanana(); } TEST_F(TestImageClassification, CPU_TFLITE_Nasnet) @@ -108,7 +91,7 @@ TEST_F(TestImageClassification, CPU_TFLITE_Nasnet) engine_config_hosted_cpu_tflite_user_model(engine_cfg, IC_TFLITE_WEIGHT_NASNET_224_PATH, IC_LABEL_MOBILENET_V1_224_PATH); - inference_banana(); + inferenceBanana(); } TEST_F(TestImageClassification, CPU_TFLITE_MNasnet) @@ -116,7 +99,7 @@ TEST_F(TestImageClassification, CPU_TFLITE_MNasnet) engine_config_hosted_cpu_tflite_user_model( engine_cfg, IC_TFLITE_WEIGHT_MNASNET_224_PATH, IC_LABEL_MOBILENET_V1_224_PATH); - inference_banana(); + inferenceBanana(); } TEST_F(TestImageClassification, CPU_TFLITE_Squeezenet) @@ -124,7 +107,7 @@ TEST_F(TestImageClassification, CPU_TFLITE_Squeezenet) engine_config_hosted_cpu_tflite_user_model( engine_cfg, IC_TFLITE_WEIGHT_SQUEEZENET_224_PATH, IC_LABEL_MOBILENET_V1_224_PATH); - inference_banana(); + inferenceBanana(); } TEST_F(TestImageClassification, CPU_TFLITE_QUANT_MobilenetV1) @@ -132,5 +115,5 @@ TEST_F(TestImageClassification, CPU_TFLITE_QUANT_MobilenetV1) engine_config_hosted_cpu_tflite_user_model( engine_cfg, IC_TFLITE_WEIGHT_QUANT_MOBILENET_V1_224_PATH, IC_LABEL_MOBILENET_V1_224_PATH); - inference_banana(); + inferenceBanana(); } \ No newline at end of file diff --git a/test/testsuites/machine_learning/inference/test_inference_helper.cpp b/test/testsuites/machine_learning/inference/test_inference_helper.cpp index 4fc1038..d34d383 100644 --- a/test/testsuites/machine_learning/inference/test_inference_helper.cpp +++ b/test/testsuites/machine_learning/inference/test_inference_helper.cpp @@ -2,6 +2,19 @@ #include #include "test_inference_helper.hpp" +TestInference::TestInference() +{ + EXPECT_EQ(mv_create_engine_config(&engine_cfg), MEDIA_VISION_ERROR_NONE); + EXPECT_EQ(mv_inference_create(&infer), MEDIA_VISION_ERROR_NONE); + EXPECT_EQ(mv_create_source(&mv_source), MEDIA_VISION_ERROR_NONE); +} +TestInference::~TestInference() +{ + EXPECT_EQ(mv_destroy_source(mv_source), MEDIA_VISION_ERROR_NONE); + EXPECT_EQ(mv_inference_destroy(infer), MEDIA_VISION_ERROR_NONE); + EXPECT_EQ(mv_destroy_engine_config(engine_cfg), MEDIA_VISION_ERROR_NONE); +} + void engine_config_hosted_cpu_tflite(mv_engine_config_h handle, const char *tf_weight) { diff --git a/test/testsuites/machine_learning/inference/test_inference_helper.hpp b/test/testsuites/machine_learning/inference/test_inference_helper.hpp index 05cab7a..16bb4c6 100644 --- a/test/testsuites/machine_learning/inference/test_inference_helper.hpp +++ b/test/testsuites/machine_learning/inference/test_inference_helper.hpp @@ -3,6 +3,16 @@ #include +class TestInference : public ::testing::Test +{ +public: + TestInference(); + virtual ~TestInference(); + mv_engine_config_h engine_cfg; + mv_inference_h infer; + mv_source_h mv_source; +}; + void engine_config_hosted_cpu_tflite(mv_engine_config_h handle, const char *tf_weight); diff --git a/test/testsuites/machine_learning/inference/test_object_detection.cpp b/test/testsuites/machine_learning/inference/test_object_detection.cpp new file mode 100644 index 0000000..345fb8f --- /dev/null +++ b/test/testsuites/machine_learning/inference/test_object_detection.cpp @@ -0,0 +1,54 @@ +#include +#include +#include +#include "test_inference_helper.hpp" + +#define OD_LABEL_MOBILENET_V1_SSD_300_PATH \ + MV_CONFIG_PATH \ + "/models/OD/tflite/od_mobilenet_v1_ssd_postop_label.txt" +#define OD_TFLITE_WEIGHT_MOBILENET_V1_SSD_300_PATH \ + MV_CONFIG_PATH \ + "/models/OD/tflite/od_mobilenet_v1_ssd_postop_300x300.tflite" +#define IMG_DOG \ + MV_CONFIG_PATH \ + "/res/inference/images/dog2.jpg" + +void _object_detected_cb(mv_source_h source, const int number_of_objects, + const int *indices, const char **names, + const float *confidences, + const mv_rectangle_s *locations, void *user_data) +{ + const std::string answer = "Dog"; + auto answer_found = false; + for (int i = 0; i < number_of_objects; i++) { + if (answer == names[i]) { + answer_found = true; + } + } + EXPECT_TRUE(answer_found); +} + +class TestObjectDetection : public TestInference +{ +public: + void inferenceDog() + { + 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_DOG, mv_source), + MEDIA_VISION_ERROR_NONE); + ASSERT_EQ(mv_inference_object_detect(mv_source, infer, + _object_detected_cb, NULL), + MEDIA_VISION_ERROR_NONE); + } +}; + +TEST_F(TestObjectDetection, CPU_TFLITE_MobilenetV1_SSD) +{ + engine_config_hosted_cpu_tflite_user_model( + engine_cfg, OD_TFLITE_WEIGHT_MOBILENET_V1_SSD_300_PATH, + OD_LABEL_MOBILENET_V1_SSD_300_PATH); + inferenceDog(); +} \ No newline at end of file -- 2.7.4 From e72aa182aadb43c77060331b582da76c48fb8ea9 Mon Sep 17 00:00:00 2001 From: Tae-Young Chung Date: Wed, 18 Aug 2021 15:36:07 +0900 Subject: [PATCH 15/16] Add Quantize() to PreProcess Change-Id: I4df22f0ec4e1bcf663459083ce77f70d91c7a600 Signed-off-by: Tae-Young Chung --- .../mv_inference/inference/include/PreProcess.h | 2 ++ .../mv_inference/inference/src/PreProcess.cpp | 24 ++++++++++++++++++++++ packaging/capi-media-vision.spec | 2 +- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/mv_machine_learning/mv_inference/inference/include/PreProcess.h b/mv_machine_learning/mv_inference/inference/include/PreProcess.h index f4c002b..4121557 100644 --- a/mv_machine_learning/mv_inference/inference/include/PreProcess.h +++ b/mv_machine_learning/mv_inference/inference/include/PreProcess.h @@ -68,6 +68,8 @@ namespace inference int ColorConvert(cv::Mat& source, cv::Mat& dest, int sType, int dType); int Normalize(cv::Mat& source, cv::Mat& dest, const std::vector& mean, const std::vector& std); + int Quantize(cv::Mat& source, cv::Mat& dest, + const std::vector& scale, const std::vector& zeropoint); }; diff --git a/mv_machine_learning/mv_inference/inference/src/PreProcess.cpp b/mv_machine_learning/mv_inference/inference/src/PreProcess.cpp index fa65ced..6d79586 100644 --- a/mv_machine_learning/mv_inference/inference/src/PreProcess.cpp +++ b/mv_machine_learning/mv_inference/inference/src/PreProcess.cpp @@ -83,6 +83,7 @@ namespace inference const std::vector& mean, const std::vector& std) { LOGI("ENTER"); + try { cv::subtract(source, cv::Scalar(mean[0], mean[1], mean[2]), dest); source = dest; @@ -97,6 +98,25 @@ namespace inference return MEDIA_VISION_ERROR_NONE; } + int PreProcess::Quantize(cv::Mat& source, cv::Mat& dest, + const std::vector& scale, const std::vector& zeropoint) + { + LOGI("ENTER"); + + try { + cv::subtract(source, cv::Scalar(zeropoint[0], zeropoint[1], zeropoint[2]), dest); + source = dest; + cv::multiply(source, cv::Scalar(scale[0], scale[1], scale[2]), dest); + } catch (cv::Exception& e) { + LOGE("Fail to subtract/multiply with msg: %s", e.what()); + return MEDIA_VISION_ERROR_INVALID_OPERATION; + } + + LOGI("LEAVE"); + + return MEDIA_VISION_ERROR_NONE; + } + int PreProcess::Run(cv::Mat& source, const int colorSpace, const int dataType, const LayerInfo& layerInfo, const Options& options, void* buffer) @@ -121,6 +141,10 @@ namespace inference Normalize(dest, dest, options.normalization.mean, options.normalization.std); } + if (options.quantization.use) { + Quantize(dest, dest, options.quantization.scale, options.quantization.zeropoint); + } + LOGI("LEAVE"); return MEDIA_VISION_ERROR_NONE; diff --git a/packaging/capi-media-vision.spec b/packaging/capi-media-vision.spec index 1462ad3..e86b09c 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.8.7 +Version: 0.8.8 Release: 0 Group: Multimedia/Framework License: Apache-2.0 and BSD-3-Clause -- 2.7.4 From 57cc706ea2a641b769feee2e2213eb2428d8d441 Mon Sep 17 00:00:00 2001 From: Kwang Son Date: Thu, 19 Aug 2021 01:59:07 -0400 Subject: [PATCH 16/16] test: break condition Change-Id: I9994f71ad8627dd4a3d6792e87b9602651ba76b4 Signed-off-by: Kwang Son --- test/testsuites/machine_learning/inference/test_image_classification.cpp | 1 + test/testsuites/machine_learning/inference/test_object_detection.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/test/testsuites/machine_learning/inference/test_image_classification.cpp b/test/testsuites/machine_learning/inference/test_image_classification.cpp index 2a13d06..0aab594 100644 --- a/test/testsuites/machine_learning/inference/test_image_classification.cpp +++ b/test/testsuites/machine_learning/inference/test_image_classification.cpp @@ -40,6 +40,7 @@ void _image_classified_cb(mv_source_h source, const int number_of_classes, for (int i = 0; i < number_of_classes; i++) { if (answer == names[i]) { answer_found = true; + break; } } EXPECT_TRUE(answer_found); diff --git a/test/testsuites/machine_learning/inference/test_object_detection.cpp b/test/testsuites/machine_learning/inference/test_object_detection.cpp index 345fb8f..8cea9f7 100644 --- a/test/testsuites/machine_learning/inference/test_object_detection.cpp +++ b/test/testsuites/machine_learning/inference/test_object_detection.cpp @@ -23,6 +23,7 @@ void _object_detected_cb(mv_source_h source, const int number_of_objects, for (int i = 0; i < number_of_objects; i++) { if (answer == names[i]) { answer_found = true; + break; } } EXPECT_TRUE(answer_found); -- 2.7.4