[Unittest] Tensorflow unittest with MNIST
authorHyoung Joo Ahn <hello.ahnn@gmail.com>
Mon, 7 Jan 2019 06:54:33 +0000 (15:54 +0900)
committerJijoong Moon <jijoong.moon@samsung.com>
Tue, 8 Jan 2019 23:14:13 +0000 (08:14 +0900)
the basic unittest of tensorflow with MNIST model. it resolves #994

Signed-off-by: Hyoung Joo Ahn <hello.ahnn@gmail.com>
packaging/nnstreamer.spec
tests/nnstreamer_filter_tensorflow/checkLabel.py [new file with mode: 0644]
tests/nnstreamer_filter_tensorflow/data/9.raw [new file with mode: 0644]
tests/nnstreamer_filter_tensorflow/runTest.sh [new file with mode: 0755]
tests/test_models/models/mnist.pb [new file with mode: 0644]

index f4a68a1..61cf327 100644 (file)
@@ -99,6 +99,7 @@ mkdir -p build
 
 %ifarch x86_64 aarch64
     meson --buildtype=plain --werror --prefix=%{_prefix} --libdir=%{_libdir} --bindir=%{nnstexampledir} --includedir=%{_includedir} -DINSTALL_EXAMPLES=true build
+    export TEST_TENSORFLOW=1
 %else
     meson --buildtype=plain --werror --prefix=%{_prefix} --libdir=%{_libdir} --bindir=%{nnstexampledir} --includedir=%{_includedir} -DINSTALL_EXAMPLES=true -DENABLE_TENSORFLOW=false build
 %endif
diff --git a/tests/nnstreamer_filter_tensorflow/checkLabel.py b/tests/nnstreamer_filter_tensorflow/checkLabel.py
new file mode 100644 (file)
index 0000000..6a7278d
--- /dev/null
@@ -0,0 +1,36 @@
+#!/usr/bin/env python
+
+##
+# Copyright (C) 2018 Samsung Electronics
+# License: LGPL-2.1
+#
+# @file checkLabel.py
+# @brief Check the result label of tensorflow-lite 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
+
+
+def readlabel (filename):
+  F = open(filename, 'r')
+  line = F.readlines()
+  F.close()
+  return line
+
+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 = sys.argv[2].split('/')[1].split('.')[0].strip()
+exit(pred != string.atoi(answer))
diff --git a/tests/nnstreamer_filter_tensorflow/data/9.raw b/tests/nnstreamer_filter_tensorflow/data/9.raw
new file mode 100644 (file)
index 0000000..d2d4357
Binary files /dev/null and b/tests/nnstreamer_filter_tensorflow/data/9.raw differ
diff --git a/tests/nnstreamer_filter_tensorflow/runTest.sh b/tests/nnstreamer_filter_tensorflow/runTest.sh
new file mode 100755 (executable)
index 0000000..eb7089c
--- /dev/null
@@ -0,0 +1,33 @@
+#!/usr/bin/env bash
+##
+## @file runTest.sh
+## @author HyoungJoo Ahn <hello.ahn@samsung.com>
+## @date Dec 17 2018
+## @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
+if [[ -z "${TEST_TENSORFLOW}" ]]; then
+    report
+fi
+
+# Test constant passthrough custom filter (1, 2)
+PATH_TO_PLUGIN="../../build"
+PATH_TO_MODEL="../test_models/models/mnist.pb"
+PATH_TO_DATA="data/9.raw"
+
+gstTest "--gst-plugin-path=${PATH_TO_PLUGIN} filesrc location=${PATH_TO_DATA} ! application/octet-stream ! tensor_converter input-dim=784:1 input-type=uint8 ! tensor_transform mode=arithmetic option=typecast:float32,add:-127.5,div:127.5 ! tensor_filter framework=tensorflow model=${PATH_TO_MODEL} input=784:1:1:1 inputtype=float32 inputname=input output=10:1:1:1 outputtype=float32 outputname=softmax ! filesink location=tensorfilter.out.log " 1 0 0 $PERFORMANCE
+python checkLabel.py tensorfilter.out.log ${PATH_TO_DATA}
+testResult $? 1 "Golden test comparison" 0 1
+
+report
diff --git a/tests/test_models/models/mnist.pb b/tests/test_models/models/mnist.pb
new file mode 100644 (file)
index 0000000..14d805d
Binary files /dev/null and b/tests/test_models/models/mnist.pb differ