Revert "test: drop pose estimation test"
authorInki Dae <inki.dae@samsung.com>
Tue, 21 Apr 2020 02:50:00 +0000 (11:50 +0900)
committerInki Dae <inki.dae@samsung.com>
Mon, 1 Jun 2020 02:10:37 +0000 (11:10 +0900)
This reverts commit 72b730ed61c69b4a4957b2173776023e71218b13.

Change-Id: I8a14aaaf9f0cb1505a0cb7f33323524e71b9230b

test/testsuites/inference/inference_test_suite.c

index 40c0c36ebce706b981f27e0842d52989fef008b2..4c2885f7afd44cde9708b57a3867f9a4e0f86698 100644 (file)
@@ -61,6 +61,9 @@
 #define FLD_OPENCV_WEIGHT_CAFFE_PATH "/usr/share/capi-media-vision/models/FLD/caffe/fld_caffe_model_tweak.caffemodel"
 #define FLD_OPENCV_CONFIG_CAFFE_PATH "/usr/share/capi-media-vision/models/FLD/caffe/fld_caffe_model_tweak.prototxt"
 
+//Pose Estimation
+#define PE_TFLITE_WEIGHT_PATH "/usr/share/capi-media-vision/models/PE/tflite/ped_tflite_model.tflite"
+
 /******
  * Public model:
  *  IC: mobilenet caffe, tf?
@@ -2346,20 +2349,266 @@ int perform_facial_landmark_detection()
     return MEDIA_VISION_ERROR_NONE;
 }
 
+int perform_armnn_pose_estimation_detection(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 cofniguration.\n");
+            }
+        }
+        return err;
+    }
+
+    char *inputNodeName = "image";
+    char *outputNodeName[1] = {"Convolutional_Pose_Machine/stage_5_out"};
+
+    mv_engine_config_set_string_attribute(handle,
+                        MV_INFERENCE_MODEL_WEIGHT_FILE_PATH,
+                        PE_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_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,
+                        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_pose_estimation_detection()
+{
+    int err = MEDIA_VISION_ERROR_NONE;
+
+    int sel_opt = 0;
+    const int options[5] = {1, 2, 3, 4, 5};
+    const *names[5] = { "Configuration",
+                        "ARMNN(CPU) + PoseEstimation",
+                        "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("Select Action:", options, names, 5);
+        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);
+            }
+
+            err = perform_configuration(&engine_cfg);
+        }
+            break;
+        case 2:
+        {
+            //perform pose estimation 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_pose_estimation_detection(&engine_cfg);
+        }
+            break;
+        case 3:
+        {
+            // 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);
+                }
+            }
+
+            // 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 4:
+        {
+            if (mvSource) {
+                int err2 = mv_destroy_source(mvSource);
+                if (err2 != MEDIA_VISION_ERROR_NONE);
+                    printf("Fail to destroy mvSource\n");
+            }
+
+            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", err2);
+                }
+                free(in_file_name);
+                break;
+            }
+            free(in_file_name);
+
+            struct timespec s_tspec;
+            struct timespec e_tspec;
+
+            clock_gettime(CLOCK_MONOTONIC, &s_tspec);
+
+            // Pose estimation
+            err = mv_inference_pose_estimation_detect(mvSource, infer, NULL, _pose_estimation_detected_cb, NULL);
+
+            clock_gettime(CLOCK_MONOTONIC, &e_tspec);
+
+            struct timespec diffspec = diff(s_tspec, e_tspec);
+            unsigned long timeDiff = gettotalmillisec(diffspec);
+            printf("elased time : %lu(ms)\n", timeDiff);
+
+            break;
+        }
+        case 5:
+        {
+            //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);
+                }
+            }
+
+            if (infer) {
+                err = mv_inference_destroy(infer);
+                if (err != MEDIA_VISION_ERROR_NONE) {
+                    printf("Fail to destroy inference handle [err:%i]\n", err);
+                }
+            }
+        }
+            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");
+        }
+
+        sel_opt = 0;
+        const int options_last[2] = {1, 2};
+        const char *names_last[2] = { "Yes", "No" };
+
+        while (sel_opt == 0) {
+            sel_opt = show_menu("Run Pose Estimation Detection again?:", options_last, names_last, 2);
+            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;
+    }
+
+    return MEDIA_VISION_ERROR_NONE;
+}
+
 int main()
 {
     int sel_opt = 0;
 
-    const int options[5] = {1, 2, 3, 4, 5};
-    const char *names[5] = { "Image Classification",
+    const int options[6] = {1, 2, 3, 4, 5, 6};
+    const char *names[6] = { "Image Classification",
                              "Object Detection",
                              "Face Detection",
                              "Facial LandmarkDetection",
+                             "Pose Estimation",
                              "Exit"};
 
     int err = MEDIA_VISION_ERROR_NONE;
     while (sel_opt == 0) {
-        sel_opt = show_menu("Select Action:", options, names, 4);
+        sel_opt = show_menu("Select Action:", options, names, 5);
         switch (sel_opt) {
         case 1:
         {
@@ -2394,6 +2643,14 @@ int main()
             break;
         }
         case 5:
+        {
+            err = perform_pose_estimation_detection();
+            if (err != MEDIA_VISION_ERROR_NONE) {
+                printf("Fail to perform pose estimation");
+            }
+            break;
+        }
+        case 6:
         {
             printf("Exit");
         }