[tf2tflite-dredd-pb-test] Modified just like tf2tflite-dredd-pb-test (#8869)
author윤현식/On-Device Lab(SR)/Principal Engineer/삼성전자 <hyunsik.yoon@samsung.com>
Sun, 10 Nov 2019 23:27:36 +0000 (08:27 +0900)
committer박종현/On-Device Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Sun, 10 Nov 2019 23:27:36 +0000 (08:27 +0900)
* [tf2tflite-dredd-pb-test] Modified just like tf2tflite-dredd-pb-test

tf2tflite-dredd-pb-test was modified just like tf2tflite-dredd-pb-test.

Signed-off-by: Hyun Sik Yoon <hyunsik.yoon@samsung.com>
* Update compiler/tf2tflite-dredd-pb-test/runner.sh

Co-Authored-By: hyunsik-yoon <hyunsik.yoon@samsung.com>
compiler/tf2tflite-dredd-pb-test/CMakeLists.txt
compiler/tf2tflite-dredd-pb-test/requires.cmake
compiler/tf2tflite-dredd-pb-test/rule-lib.sh [deleted file]
compiler/tf2tflite-dredd-pb-test/runner.sh

index b636d7b..75a733b 100644 (file)
@@ -2,7 +2,9 @@ nnas_include(TargetRequire)
 
 unset(REQUIRED_TARGETS)
 list(APPEND REQUIRED_TARGETS tfl-inspect)
+list(APPEND REQUIRED_TARGETS tfl-verify)
 list(APPEND REQUIRED_TARGETS tf2tflite)
+list(APPEND REQUIRED_TARGETS dredd_rule_lib)
 TargetRequire_Return(${REQUIRED_TARGETS})
 
 nncc_find_resource(TensorFlowTests)
@@ -83,10 +85,12 @@ add_custom_command(
   OUTPUT ${TOOLCHAIN_CONFIG}
   COMMAND ${CMAKE_COMMAND} -E remove -f ${TOOLCHAIN_CONFIG}
   COMMAND ${CMAKE_COMMAND} -E echo 'TFL_INSPECT_PATH=\"$<TARGET_FILE:tfl-inspect>\"' >> ${TOOLCHAIN_CONFIG}
+  COMMAND ${CMAKE_COMMAND} -E echo 'TFL_VERIFY_PATH=\"$<TARGET_FILE:tfl-verify>\"' >> ${TOOLCHAIN_CONFIG}
   COMMAND ${CMAKE_COMMAND} -E echo 'TF2TFLITE_PATH=\"$<TARGET_FILE:tf2tflite>\"' >> ${TOOLCHAIN_CONFIG}
   # add more if new excutable file is needed in runner.sh and rule-lib.sh
   DEPENDS
     tfl-inspect
+    tfl-verify
     tf2tflite
   COMMENT "Generate toolchin configuration"
 )
@@ -109,9 +113,13 @@ add_custom_command(
 list(APPEND DEPS "${TARGET_RUNNER}")
 
 #
-# Generate rule-lib
+# copy rule-lib.sh (a library of shell script functions)
 #
-set(SOURCE_RULE_LIB "${CMAKE_CURRENT_SOURCE_DIR}/rule-lib.sh")
+
+# getting path for rule-lib.sh in dredd-rule-lib
+get_target_property(DREDD_RULE_LIB_DIR dredd_rule_lib BINARY_DIR)
+
+set(SOURCE_RULE_LIB "${DREDD_RULE_LIB_DIR}/rule-lib.sh")
 set(TARGET_RULE_LIB "${CMAKE_CURRENT_BINARY_DIR}/rule-lib.sh")
 
 add_custom_command(
index 4b3d089..da01955 100644 (file)
@@ -1,2 +1,4 @@
 require("tf2tflite")
 require("tfl-inspect")
+require("tfl-verify")
+require("dredd-rule-lib")
diff --git a/compiler/tf2tflite-dredd-pb-test/rule-lib.sh b/compiler/tf2tflite-dredd-pb-test/rule-lib.sh
deleted file mode 100755 (executable)
index 5f4856b..0000000
+++ /dev/null
@@ -1,120 +0,0 @@
-#!/bin/bash
-
-ERROR_FLAG="Error"
-
-#
-# Define rule
-#
-#   - Params: rule name (metric), actual value, condition, expected value
-#     - condition is '=', '!=', '<', '>', '<=', '>='. Refer to "man expr"
-#   - Return
-#     - 0 : success
-#     - 1 : fail (condition check fail)
-#     - 10 : error while getting actual value
-#     - 11 : error while running expected value
-#     - 20 : wrong param count
-#
-
-RULE()
-{
-  if [ "$#" -ne 4 ];then
-    echo "** [Error] count of RULE parameter should be 4"
-    return 20
-  fi
-
-  RULE_NAME=$1
-  ACTUAL=$2
-  COND=$3
-  EXPECTED=$4
-
-  # not to exit when expr result with 0
-  set +e
-
-  # check if ACTUAL or EXPECTED has "ERROR" string
-  expr match "${ACTUAL}" ${ERROR_FLAG}
-  if [ $? = 0 ]; then
-    echo "** Error in ACTUAL"
-    return 10
-  fi
-
-  expr match "${EXPECTED}" ${ERROR_FLAG}
-  if [ $? = 0 ]; then
-    echo "** Error in EXPECTED"
-    return 11
-  fi
-
-  expr ${ACTUAL} ${COND} ${EXPECTED}
-  RESULT=$?
-
-  # roll-back
-  set -e
-
-  # Note: return value of 'expr'
-  # - 0 : result is true
-  # - 1 : result is not false
-  # - 2 : error
-
-  if [ ${RESULT} -eq 0 ];then
-    echo -e "\n** [${RULE_NAME}] \t success \t ([actual: ${ACTUAL}] ${COND} [expected: ${EXPECTED}])\n"
-  elif [ ${RESULT} -eq 1 ];then
-    echo -e "\n** [${RULE_NAME}] \t ** fail \t ([actual: ${ACTUAL}] ${COND} [expected: ${EXPECTED}])\n"
-  else
-    echo -e "\t** Error in [expr ${ACTUAL} ${COND} ${EXPECTED}]"
-  fi
-
-  return ${RESULT}
-}
-
-#
-# Define each function to get quality value
-#
-
-# Note: These function is called by a sub-shell.
-# So return value should be passed through "echo return_value"
-# tip: for debugging, surround the code with "set -x" and "set +x"
-
-file_size()
-{
-  if [ ! -f ${TFLITE_PATH} ]; then
-    echo "${ERROR_FLAG} - ${TFLITE_PATH} does not exist"
-  else
-    echo `cat ${TFLITE_PATH} | wc -c`
-  fi
-}
-
-all_op_count()
-{
-  if [ ! -f ${TFLITE_PATH} ]; then
-    echo "${ERROR_FLAG} - ${TFLITE_PATH} does not exist"
-  elif [ ! -f ${TFL_INSPECT_PATH} ]; then
-    echo "${ERROR_FLAG} - ${TFL_INSPECT_PATH} does not exist"
-  else
-    echo `${TFL_INSPECT_PATH} --operators ${TFLITE_PATH} | wc -l`
-  fi
-}
-
-op_count()
-{
-  if [ "$#" -ne 1 ];then
-    echo "${ERROR_FLAG} - Wrong argument number"
-  elif [ ! -f ${TFLITE_PATH} ]; then
-    echo "${ERROR_FLAG} - ${TFLITE_PATH} does not exist"
-  elif [ ! -f ${TFL_INSPECT_PATH} ]; then
-    echo "${ERROR_FLAG} - ${TFL_INSPECT_PATH} does not exist"
-  else
-    echo `${TFL_INSPECT_PATH} --operators ${TFLITE_PATH} | grep -w "$1" | wc -l`
-  fi
-}
-
-conv2d_weight_not_constant()
-{
-  if [ ! -f ${TFLITE_PATH} ]; then
-    echo "${ERROR_FLAG} - ${TFLITE_PATH} does not exist"
-  elif [ ! -f ${TFL_INSPECT_PATH} ]; then
-    echo "${ERROR_FLAG} - ${TFL_INSPECT_PATH} does not exist"
-  else
-    echo `${TFL_INSPECT_PATH} --conv2d_weight ${TFLITE_PATH} | awk -F, '{ if ($2 != "CONST") print $0}' | wc -l`
-  fi
-}
-
-# TODO define more qullity test function
index f84137e..e44d5be 100755 (executable)
@@ -21,6 +21,7 @@ CONFIG_PATH="$1"; shift
 source "${CONFIG_PATH}"
 
 echo "-- Found tfl-inspect: ${TFL_INSPECT_PATH}"
+echo "-- Found tfl-verify: ${TFL_VERIFY_PATH}"
 echo "-- Found tf2tflite: ${TF2TFLITE_PATH}"
 echo "-- Found workdir: ${WORKDIR}"
 
@@ -30,8 +31,7 @@ FAILED=()
 
 pushd "${WORKDIR}"
 
-# loading RULE and functions that checks tflite file
-source rule-lib.sh
+# running each rule file
 
 while [[ $# -ne 0 ]]; do
   PREFIX="$1"; shift
@@ -71,7 +71,15 @@ while [[ $# -ne 0 ]]; do
 
     # Note: turn off 'command printing'. Otherwise printing will be so messy
     set +x
+
+    # set vars required by rule-lib.sh and rule file
+    COMPILED_FILE=${TFLITE_PATH}
+    INSPECT_PROG_PATH=${TFL_INSPECT_PATH}
+    VERIFY_PROG_PATH=${TFL_VERIFY_PATH}
+
+    source rule-lib.sh
     source "${MODEL_RULE_PATH}"
+
     set -x
 
     if [[ $? -eq 0 ]]; then