test: Add NNFW backend test case
authorInki Dae <inki.dae@samsung.com>
Mon, 22 Jun 2020 02:20:58 +0000 (11:20 +0900)
committerInki Dae <inki.dae@samsung.com>
Mon, 22 Jun 2020 02:20:58 +0000 (11:20 +0900)
Change-Id: I453ebe467da4765614acf00965f84efc3a81370b
Signed-off-by: Inki Dae <inki.dae@samsung.com>
test/testsuites/inference/inference_test_suite.c

index 420ac9812d49ca3f0ee3b78e7b956fcb22b408be..4a8bc527b5ae3327cbeeb4c74b15b09c8ac0c9df 100644 (file)
 //Image Classification
 #define IC_LABEL_PATH "/usr/share/capi-media-vision/models/IC/tflite/ic_label.txt"
 #define IC_TFLITE_WEIGHT_PATH "/usr/share/capi-media-vision/models/IC/tflite/ic_tflite_model.tflite"
+#define IC_Q_LABEL_PATH \
+       "/usr/share/capi-media-vision/models/IC_Q/tflite/ic_label.txt"
+#define IC_Q_TFLITE_WEIGHT_PATH \
+       "/usr/share/capi-media-vision/models/IC_Q/tflite/ic_tflite_model.tflite"
 
 #define IC_OPENCV_LABEL_CAFFE_PATH "/usr/share/capi-media-vision/models/IC/caffe/ic_caffe_label_squeezenet.txt"
 #define IC_OPENCV_WEIGHT_CAFFE_PATH "/usr/share/capi-media-vision/models/IC/caffe/ic_caffe_model_squeezenet.caffemodel"
@@ -885,6 +889,69 @@ int perform_armnn_mobilenetv1_config(mv_engine_config_h *engine_cfg)
     return err;
 }
 
+int perform_nnfw_mobilenetv1_quant_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 cofniguration.\n");
+                       }
+               }
+               return err;
+       }
+
+       char *inputNodeName = "input";
+       char *outputNodeName[1] = { "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_NNFW);
+
+       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;
+}
+
 int perform_opencv_caffe_squeezenet_config(mv_engine_config_h *engine_cfg)
 {
     int err = MEDIA_VISION_ERROR_NONE;
@@ -973,11 +1040,12 @@ int perform_image_classification()
     int err = MEDIA_VISION_ERROR_NONE;
 
     int sel_opt = 0;
-    const int options[7] = { 1, 2, 3, 4, 5, 6, 7};
-    const char *names[7] = { "Configuration",
+    const int options[9] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
+    const char *names[9] = { "Configuration",
                              "TFLite(cpu + Mobilenet)",
                              "OpenCV(cpu + Squeezenet)",
                              "ARMNN(cpu + Mobilenet)",
+                                                        "NNFW(cpu + Mobilenet_Q)",
                              "Prepare",
                              "Run",
                              "Back"};
@@ -1041,7 +1109,19 @@ int perform_image_classification()
             err = perform_armnn_mobilenetv1_config(&engine_cfg);
         }
             break;
-        case 5:
+               case 5:
+               {
+                       // perform NNFW
+                       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_nnfw_mobilenetv1_quant_config(&engine_cfg);
+               }
+                       break;
+        case 6:
         {
             //create - configure - prepare
             if (infer) {
@@ -1074,7 +1154,7 @@ int perform_image_classification()
             }
         }
             break;
-        case 6:
+        case 7:
         {
             if (mvSource) {
                 int err2 = mv_destroy_source(mvSource);
@@ -1122,7 +1202,7 @@ int perform_image_classification()
 
         }
             break;
-        case 7:
+        case 8:
         {
             //perform destroy
             if (engine_cfg) {