Update testsuite to run facial landmark models with meta files 69/261269/5
authorTae-Young Chung <ty83.chung@samsung.com>
Wed, 14 Jul 2021 07:04:28 +0000 (16:04 +0900)
committerTae-Young Chung <ty83.chung@samsung.com>
Fri, 16 Jul 2021 06:43:46 +0000 (06:43 +0000)
Change-Id: Id3b8c985a7dcdc55f3e034107f7e4e9f5cd3760b
Signed-off-by: Tae-Young Chung <ty83.chung@samsung.com>
meta-template/fld_mediapipe_192x192.json [new file with mode: 0644]
meta-template/fld_tweakcnn_128x128.json [new file with mode: 0644]
test/testsuites/machine_learning/inference/inference_test_suite.c

diff --git a/meta-template/fld_mediapipe_192x192.json b/meta-template/fld_mediapipe_192x192.json
new file mode 100644 (file)
index 0000000..562fb77
--- /dev/null
@@ -0,0 +1,46 @@
+{
+    "inputmetadata" :
+    {
+        "tensor_info" : [
+            {
+                "name" : "input",
+                "shape_type" : 1,
+                "shape_dims" : [ 1, 192, 192, 3],
+                "data_type" : 0,
+                "color_space" : "RGB888"
+            }
+        ],
+        "preprocess" : [
+            {
+                "normalization" : [
+                    {
+                        "mean" : [127.5, 127.5, 127.5],
+                        "std" : [127.5, 127.5, 127.5]
+                    }
+                ]
+            }
+        ]
+    },
+    "outputmetadata" :
+    {
+        "score" : [
+            {
+                "name" : "conv2d_30",
+                "index" : [-1, -1, -1, 1],
+                "top_number" : 1,
+                "threshold" : 0.3,
+                "score_type" : 1
+            }
+        ],
+        "landmark" : [
+            {
+                "name" : "conv2d_20",
+                "index" : [-1, -1, -1, 1],
+                "landmark_type" : 0,
+                "landmark_coordinate" : 1,
+                "decoding_type" : 0,
+                "landmark_offset" : 3
+            }
+        ]
+    }
+}
diff --git a/meta-template/fld_tweakcnn_128x128.json b/meta-template/fld_tweakcnn_128x128.json
new file mode 100644 (file)
index 0000000..7d8b48f
--- /dev/null
@@ -0,0 +1,46 @@
+{
+    "inputmetadata" :
+    {
+        "tensor_info" : [
+            {
+                "name" : "Placeholder",
+                "shape_type" : 1,
+                "shape_dims" : [ 1, 128, 128, 3],
+                "data_type" : 0,
+                "color_space" : "RGB888"
+            }
+        ],
+        "preprocess" : [
+            {
+                "normalization" : [
+                    {
+                        "mean" : [0.0, 0.0, 0.0],
+                        "std" : [1.0, 1.0, 1.0]
+                    }
+                ]
+            }
+        ]
+    },
+    "outputmetadata" :
+    {
+        "score" : [
+            {
+                "name" : "fanet8ss_inference/fully_connected_1/Sigmoid",
+                "index" : [-1, -1, -1, -1],
+                "top_number" : 1,
+                "threshold" : 0.0,
+                "score_type" : 0
+            }
+        ],
+        "landmark" : [
+            {
+                "name" : "fanet8ss_inference/fully_connected_1/Sigmoid",
+                "index" : [-1, 1],
+                "landmark_type" : 0,
+                "landmark_coordinate" : 0,
+                "landmark_offset" : 2,
+                "decoding_type" : 0
+            }
+        ]
+    }
+}
index 579e9f1..b838945 100644 (file)
 #define FLD_OPENCV_CONFIG_CAFFE_PATH \
        "/usr/share/capi-media-vision/models/FLD/caffe/fld_caffe_model_tweak.prototxt"
 
+/*
+ * Hosted models
+ */
+#define FLD_TFLITE_WIEGHT_TWEAKCNN_128_PATH \
+       "/usr/share/capi-media-vision/models/FLD/tflite/fld_tweakcnn_128x128.tflite"
+#define FLD_TFLITE_WIEGHT_MEDIAPIPE_192_PATH \
+       "/usr/share/capi-media-vision/models/FLD/tflite/fld_mediapipe_192x192.tflite"
+
 //Pose Detection
 #define PLD_TFLITE_WEIGHT_PATH \
        "/usr/share/capi-media-vision/models/PLD/tflite/pld-tflite-001.tflite"
@@ -2917,15 +2925,80 @@ int perform_opencv_cnncascade(mv_engine_config_h *engine_cfg)
        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;
+}
+
 int perform_facial_landmark_detection()
 {
        int err = MEDIA_VISION_ERROR_NONE;
 
        int sel_opt = 0;
-       const int options[] = { 1, 2, 3, 4, 5, 6 };
+       const int options[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
        const char *names[] = { "Configuration",
                                                "Tflite(CPU) + TweakCNN",
                                                "OPENCV(CPU) + TweakCNN",
+                                               "Hosted: TFLite(TweakCNN)",
+                                               "Hosted: TFLite(MediaPipe)",
                                                "Prepare",
                                                "Run",
                                                "Back" };
@@ -2969,6 +3042,26 @@ int perform_facial_landmark_detection()
                        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);
@@ -2999,7 +3092,7 @@ int perform_facial_landmark_detection()
                                break;
                        }
                } break;
-               case 5: {
+               case 7: {
                        if (mvSource) {
                                int err2 = mv_destroy_source(mvSource);
                                if (err2 != MEDIA_VISION_ERROR_NONE)
@@ -3046,7 +3139,7 @@ int perform_facial_landmark_detection()
                        unsigned long timeDiff = gettotalmillisec(diffspec);
                        printf("elapsed time : %lu(ms)\n", timeDiff);
                } break;
-               case 6: {
+               case 8: {
                        //perform destroy
                        if (engine_cfg) {
                                err = mv_destroy_engine_config(engine_cfg);