Update code based on feedback
authorSungbin Jo <goranmoomin@daum.net>
Mon, 18 Dec 2023 18:48:01 +0000 (03:48 +0900)
committerMyungJoo Ham <myungjoo.ham@samsung.com>
Wed, 20 Dec 2023 05:57:24 +0000 (14:57 +0900)
Incorporate the feedback given from the code review process.

Signed-off-by: Sungbin Jo <goranmoomin@daum.net>
ext/nnstreamer/tensor_filter/tensor_filter_ncnn.cc
tests/nnstreamer_filter_ncnn/runTest.sh

index 8eef515..83a51de 100644 (file)
@@ -28,7 +28,7 @@
  *
  *  custom:
  *    Each entries are separated by ','
- *    Each entries have property_key=value format.
+ *    Each entries have property_key:value format.
  *    There must be no spaces.
  *
  *    Supported custom properties:
@@ -213,7 +213,7 @@ ncnn_subplugin::configure_instance (const GstTensorFilterProperties *prop)
   // init input matrices
   for (guint i = 0; i < inputInfo.num_tensors; i++) {
     // get dimensions of the input matrix from inputInfo
-    const uint32_t *dim = inputInfo.info[i].dimension;
+    const uint32_t *dim = gst_tensors_info_get_nth_info (&inputInfo, i)->dimension;
     std::vector<int> shape;
     while (*dim)
       shape.push_back (*dim++);
@@ -234,7 +234,8 @@ ncnn_subplugin::configure_instance (const GstTensorFilterProperties *prop)
         in = ncnn::Mat (shape[0], shape[1], shape[2], shape[3]);
         break;
       default:
-        throw std::invalid_argument ("Wrong input dimension");
+        throw std::invalid_argument ("ncnn subplugin supports only up to 4 ranks and does not support input tensors of "
+                                     + std::to_string (shape.size ()) + " dimensions.");
     }
     input_mats.push_back (in);
   }
@@ -260,7 +261,12 @@ ncnn_subplugin::configure_instance (const GstTensorFilterProperties *prop)
 void
 ncnn_subplugin::invoke (const GstTensorMemory *input, GstTensorMemory *output)
 {
-  assert (!empty_model);
+  if (empty_model)
+    throw std::runtime_error (
+        "Model is empty: the ncnn instance is not configured and "
+        "its \"invoke\" method is called. This may be an internal bug of "
+        "nnstreamer or ncnn-subplugin unless if you have directly accessed "
+        "ncnn-subplugin.");
 
   // make extractor instance for each inference
   ncnn::Extractor ex = net.create_extractor ();
@@ -305,7 +311,8 @@ ncnn_subplugin::invoke (const GstTensorMemory *input, GstTensorMemory *output)
     // write detection-box infos to the output tensor
     for (guint i = 0; i < outputInfo.num_tensors; i++) {
       ncnn::Mat &out = output_mats.at (i);
-      const int label_count = outputInfo.info[i].dimension[0];
+      const int label_count
+          = gst_tensors_info_get_nth_info (&outputInfo, i)->dimension[0];
       float *output_data = (float *) output->data;
       for (int j = 0; j < out.h; j++) {
         float *values = out.row (j);
@@ -398,7 +405,7 @@ ncnn_subplugin::parseCustomProperties (const GstTensorFilterProperties *prop)
 
     for (guint i = 0; i < len; i++) {
       // split with = to parse single option
-      uniq_g_strv option (g_strsplit (options.get ()[i], "=", -1), g_strfreev);
+      uniq_g_strv option (g_strsplit (options.get ()[i], ":", -1), g_strfreev);
 
       // we only have key=value form option
       if (g_strv_length (option.get ()) == 2) {
index c42f2e7..2a8fa4a 100755 (executable)
@@ -20,7 +20,51 @@ testInit $1
 
 # NNStreamer and plugins path for test
 PATH_TO_PLUGIN="../../build"
-  
+
+if [[ -d $PATH_TO_PLUGIN ]]; then
+    ini_path="${PATH_TO_PLUGIN}/ext/nnstreamer/tensor_filter"
+    if [[ -d ${ini_path} ]]; then
+        check=$(ls ${ini_path} | grep ncnn.so)
+        if [[ ! $check ]]; then
+            echo "Cannot find ncnn shared lib"
+            report
+            exit
+        fi
+    else
+        echo "Cannot find ${ini_path}"
+    fi
+else
+    ini_file="/etc/nnstreamer.ini"
+    if [[ -f ${ini_file} ]]; then
+        path=$(grep "^filters" ${ini_file})
+        key=${path%=*}
+        value=${path##*=}
+
+        if [[ $key != "filters" ]]; then
+            echo "String Error"
+            report
+            exit
+        fi
+
+        if [[ -d ${value} ]]; then
+            check=$(ls ${value} | grep ncnn.so)
+            if [[ ! $check ]]; then
+                echo "Cannot find ncnn shared lib"
+                report
+                exit
+            fi
+        else
+            echo "Cannot find ${value}"
+            report
+            exit
+        fi
+else
+        echo "Cannot identify nnstreamer.ini"
+        report
+        exit
+    fi
+fi
+
 PATH_TO_PARAM="../test_models/models/ncnn_models/squeezenet_v1.1.param"
 PATH_TO_BIN="../test_models/models/ncnn_models/squeezenet_v1.1.bin"
 PATH_TO_LABEL="../test_models/labels/squeezenet_labels.txt"
@@ -43,7 +87,7 @@ gstTest "--gst-plugin-path=${PATH_TO_PLUGIN} filesrc location=${PATH_TO_IMAGE} !
 gstTest "--gst-plugin-path=${PATH_TO_PLUGIN} filesrc location=${PATH_TO_IMAGE} ! pngdec ! videoscale ! imagefreeze ! videoconvert ! videoscale ! video/x-raw,width=227,height=227,format=BGR,framerate=0/1 ! tensor_converter ! tensor_transform mode=arithmetic option=typecast:float32,add:-127.5 ! tensor_transform mode=transpose option=1:2:0:3 ! tensor_filter framework=ncnn model=${PATH_TO_PARAM},${PATH_TO_BIN} input=227:227:3 inputtype=float32 output=1000:1 outputtype=float32,float32 ! tensor_decoder mode=image_labeling option1=${PATH_TO_LABEL} ! filesink location=ncnn.out.log" 5 0 1 $PERFORMANCE
 
 # Fail test for invalid argument
-gstTest "--gst-plugin-path=${PATH_TO_PLUGIN} filesrc location=${PATH_TO_IMAGE} ! pngdec ! videoscale ! imagefreeze ! videoconvert ! videoscale ! video/x-raw,width=227,height=227,format=BGR,framerate=0/1 ! tensor_converter ! tensor_transform mode=arithmetic option=typecast:float32,add:-127.5 ! tensor_transform mode=transpose option=1:2:0:3 ! tensor_filter framework=ncnn model=${PATH_TO_PARAM},${PATH_TO_BIN} custom=use_yolo_decoder=fail input=227:227:3 inputtype=float32 output=1000:1 outputtype=float32 ! tensor_decoder mode=image_labeling option1=${PATH_TO_LABEL} ! filesink location=ncnn.out.log" 6 0 1 $PERFORMANCE
+gstTest "--gst-plugin-path=${PATH_TO_PLUGIN} filesrc location=${PATH_TO_IMAGE} ! pngdec ! videoscale ! imagefreeze ! videoconvert ! videoscale ! video/x-raw,width=227,height=227,format=BGR,framerate=0/1 ! tensor_converter ! tensor_transform mode=arithmetic option=typecast:float32,add:-127.5 ! tensor_transform mode=transpose option=1:2:0:3 ! tensor_filter framework=ncnn model=${PATH_TO_PARAM},${PATH_TO_BIN} custom=use_yolo_decoder:fail input=227:227:3 inputtype=float32 output=1000:1 outputtype=float32 ! tensor_decoder mode=image_labeling option1=${PATH_TO_LABEL} ! filesink location=ncnn.out.log" 6 0 1 $PERFORMANCE
 
 # Fail test for invalid argument
 gstTest "--gst-plugin-path=${PATH_TO_PLUGIN} filesrc location=${PATH_TO_IMAGE} ! pngdec ! videoscale ! imagefreeze ! videoconvert ! videoscale ! video/x-raw,width=227,height=227,format=BGR,framerate=0/1 ! tensor_converter ! tensor_transform mode=arithmetic option=typecast:float32,add:-127.5 ! tensor_transform mode=transpose option=1:2:0:3 ! tensor_filter framework=ncnn model=${PATH_TO_PARAM},${PATH_TO_BIN} custom=nakluv_esu=true input=227:227:3 inputtype=float32 output=1000:1 outputtype=float32 ! tensor_decoder mode=image_labeling option1=${PATH_TO_LABEL} ! filesink location=ncnn.out.log" 7 0 1 $PERFORMANCE