[Unittest/Caffe2] add the unittest of caffe2
authorHyoung Joo Ahn <hello.ahn@samsung.com>
Mon, 17 Jun 2019 12:40:05 +0000 (21:40 +0900)
committerMyungJoo Ham <myungjoo.ham@samsung.com>
Fri, 21 Jun 2019 05:05:53 +0000 (14:05 +0900)
with the toy example, test caffe2 as the framework of tensor_filter

Signed-off-by: Hyoung Joo Ahn <hello.ahn@samsung.com>
tests/nnstreamer_filter_caffe2/checkLabel.py [new file with mode: 0644]
tests/nnstreamer_filter_caffe2/data/5 [new file with mode: 0644]
tests/nnstreamer_filter_caffe2/runTest.sh [new file with mode: 0755]
tests/test_models/models/caffe2_init_net.pb [new file with mode: 0644]
tests/test_models/models/caffe2_predict_net.pb [new file with mode: 0644]

diff --git a/tests/nnstreamer_filter_caffe2/checkLabel.py b/tests/nnstreamer_filter_caffe2/checkLabel.py
new file mode 100644 (file)
index 0000000..9c04869
--- /dev/null
@@ -0,0 +1,30 @@
+#!/usr/bin/env python
+
+##
+# Copyright (C) 2018 Samsung Electronics
+# License: LGPL-2.1
+#
+# @file checkLabel.py
+# @brief Check the result label of caffe2 model
+# @author HyoungJoo Ahn <hello.ahn@samsung.com>
+
+import sys
+import struct
+import string
+
+def readbyte (filename):
+  F = open(filename, 'r')
+  readbyte = F.read()
+  F.close()
+  return readbyte
+
+bytearr = readbyte(sys.argv[1])
+softmax = []
+for i in xrange(10):
+  byte = bytearr[i * 4] + bytearr[i * 4 + 1] + bytearr[i * 4 + 2] + bytearr[i * 4 + 3]
+  softmax.append(struct.unpack('f', byte))
+
+pred = softmax.index(max(softmax))
+answer = string.atoi(sys.argv[2].strip())
+
+exit(pred != answer)
diff --git a/tests/nnstreamer_filter_caffe2/data/5 b/tests/nnstreamer_filter_caffe2/data/5
new file mode 100644 (file)
index 0000000..e95e32e
Binary files /dev/null and b/tests/nnstreamer_filter_caffe2/data/5 differ
diff --git a/tests/nnstreamer_filter_caffe2/runTest.sh b/tests/nnstreamer_filter_caffe2/runTest.sh
new file mode 100755 (executable)
index 0000000..a7a6166
--- /dev/null
@@ -0,0 +1,76 @@
+#!/usr/bin/env bash
+##
+## @file runTest.sh
+## @author HyoungJoo Ahn <hello.ahn@samsung.com>
+## @date Jun 17 2019
+## @brief SSAT Test Cases for NNStreamer
+##
+
+if [[ "$SSATAPILOADED" != "1" ]];then
+       SILENT=0
+       INDEPENDENT=1
+       search="ssat-api.sh"
+       source $search
+       printf "${Blue}Independent Mode${NC}
+"
+fi
+
+# This is compatible with SSAT (https://github.com/myungjoo/SSAT)
+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 caffe2.so)
+       if [[ ! $check ]]; then
+           echo "Cannot find caffe2 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_path})
+       key=${path%=*}
+       value=${path##*=}
+
+       if [[ $key != "filters" ]]
+       then
+           echo "String Error"
+           report
+           exit
+       fi
+
+       if [[ -d ${value} ]]; then
+           check=$(ls ${value} | grep caffe2.so)
+           if [[ ! $check ]]; then
+               echo "Cannot find caffe2 shared lib"
+               report
+               exit
+           fi
+       else
+           echo "Cannot file ${value}"
+           report
+           exit
+       fi
+    fi
+    echo "Cannot identify nnstreamer.ini"
+    report
+    exit
+fi
+
+# Test with Classifier model
+PATH_TO_INIT_MODEL="../test_models/models/caffe2_init_net.pb"
+PATH_TO_PRED_MODEL="../test_models/models/caffe2_predict_net.pb"
+PATH_TO_DATA="./data/5"
+
+gstTest "--gst-plugin-path=${PATH_TO_PLUGIN} filesrc location=${PATH_TO_DATA} blocksize=-1 ! application/octet-stream ! tensor_converter input-dim=32:32:3:1 input-type=float32 ! tensor_filter framework=caffe2 model=\"${PATH_TO_INIT_MODEL},${PATH_TO_PRED_MODEL}\" inputname=data input=32:32:3:1 inputtype=float32 output=10:1:1:1 outputtype=float32 outputname=softmax ! filesink location=tensorfilter.out.log" 1 0 0 $PERFORMANCE
+python checkLabel.py tensorfilter.out.log 5
+testResult $? 1 "Golden test comparison" 0 1
+report
diff --git a/tests/test_models/models/caffe2_init_net.pb b/tests/test_models/models/caffe2_init_net.pb
new file mode 100644 (file)
index 0000000..e15baaf
Binary files /dev/null and b/tests/test_models/models/caffe2_init_net.pb differ
diff --git a/tests/test_models/models/caffe2_predict_net.pb b/tests/test_models/models/caffe2_predict_net.pb
new file mode 100644 (file)
index 0000000..8a709be
Binary files /dev/null and b/tests/test_models/models/caffe2_predict_net.pb differ