From 06c212e4b958e6fdb0808c635853f7b327758561 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EC=9C=A4=ED=98=84=EC=8B=9D/On-Device=20Lab=28SR=29/Princip?= =?utf8?q?al=20Engineer/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Mon, 11 Nov 2019 08:27:36 +0900 Subject: [PATCH] [tf2tflite-dredd-pb-test] Modified just like tf2tflite-dredd-pb-test (#8869) * [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 * Update compiler/tf2tflite-dredd-pb-test/runner.sh Co-Authored-By: hyunsik-yoon --- compiler/tf2tflite-dredd-pb-test/CMakeLists.txt | 12 ++- compiler/tf2tflite-dredd-pb-test/requires.cmake | 2 + compiler/tf2tflite-dredd-pb-test/rule-lib.sh | 120 ------------------------ compiler/tf2tflite-dredd-pb-test/runner.sh | 12 ++- 4 files changed, 22 insertions(+), 124 deletions(-) delete mode 100755 compiler/tf2tflite-dredd-pb-test/rule-lib.sh diff --git a/compiler/tf2tflite-dredd-pb-test/CMakeLists.txt b/compiler/tf2tflite-dredd-pb-test/CMakeLists.txt index b636d7b..75a733b 100644 --- a/compiler/tf2tflite-dredd-pb-test/CMakeLists.txt +++ b/compiler/tf2tflite-dredd-pb-test/CMakeLists.txt @@ -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=\"$\"' >> ${TOOLCHAIN_CONFIG} + COMMAND ${CMAKE_COMMAND} -E echo 'TFL_VERIFY_PATH=\"$\"' >> ${TOOLCHAIN_CONFIG} COMMAND ${CMAKE_COMMAND} -E echo 'TF2TFLITE_PATH=\"$\"' >> ${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( diff --git a/compiler/tf2tflite-dredd-pb-test/requires.cmake b/compiler/tf2tflite-dredd-pb-test/requires.cmake index 4b3d089..da01955 100644 --- a/compiler/tf2tflite-dredd-pb-test/requires.cmake +++ b/compiler/tf2tflite-dredd-pb-test/requires.cmake @@ -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 index 5f4856b..0000000 --- a/compiler/tf2tflite-dredd-pb-test/rule-lib.sh +++ /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 diff --git a/compiler/tf2tflite-dredd-pb-test/runner.sh b/compiler/tf2tflite-dredd-pb-test/runner.sh index f84137e..e44d5be 100755 --- a/compiler/tf2tflite-dredd-pb-test/runner.sh +++ b/compiler/tf2tflite-dredd-pb-test/runner.sh @@ -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 -- 2.7.4