Skip to content

Commit

Permalink
[tf2tfliteV2-conversion-test] Rename tf2tfliteV2-pbtxt-value-test (Sa…
Browse files Browse the repository at this point in the history
…msung#789)

* [tf2tfliteV2-conversion-test] Rename tf2tfliteV2-pbtxt-value-test

This commit renames tf2tfliteV2-pbtxt-value-test

ONE-DCO-1.0-Signed-off-by: seongwoo <[email protected]>

* fix typo
  • Loading branch information
mhs4670go authored May 13, 2020
1 parent fc50cca commit 81ce09a
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,22 @@ find_package(PythonInterp 3 QUIET)
find_package(PythonLibs 3 QUIET)

if(NOT ${PYTHONINTERP_FOUND})
message(STATUS "Build tf2tfliteV2-value-pbtxt-test: FALSE (Python3 is missing)")
message(STATUS "Build tf2tfliteV2-conversion-test: FALSE (Python3 is missing)")
return()
endif()

if(${PYTHON_VERSION_MINOR} LESS 3)
message(STATUS "Build tf2tfliteV2-value-pbtxt-test: FALSE (You need to install Python version higher than 3.3)")
message(STATUS "Build tf2tfliteV2-conversion-test: FALSE (You need to install Python version higher than 3.3)")
return()
endif()

nnas_include(TargetRequire)

unset(REQUIRED_TARGETS)
list(APPEND REQUIRED_TARGETS tfkit)
list(APPEND REQUIRED_TARGETS tf2tfliteV2)
list(APPEND REQUIRED_TARGETS nnkit-run)
list(APPEND REQUIRED_TARGETS nnkit_tf_backend)
list(APPEND REQUIRED_TARGETS nnkit_tflite_backend)
list(APPEND REQUIRED_TARGETS nnkit_randomize_action)
list(APPEND REQUIRED_TARGETS nnkit_HDF5_export_action)
list(APPEND REQUIRED_TARGETS nnkit_HDF5_import_action)
list(APPEND REQUIRED_TARGETS i5diff)
TargetRequire_Return(${REQUIRED_TARGETS})

message(STATUS "tf2tfliteV2-value-pbtxt-test: run tests")
message(STATUS "tf2tfliteV2-conversion-test: run tests")

# Create python virtual environment
set(VIRTUALENV "${CMAKE_CURRENT_BINARY_DIR}/venv")
Expand All @@ -48,8 +40,8 @@ add_custom_command(
DEPENDS ${VIRTUALENV} ${REQUIREMENTS_SRC_PATH}
)

add_custom_target(tf2tfliteV2_value_pbtxt_python_deps ALL
DEPENDS ${VIRTUALENV} ${REQUIREMENTS_BIN_PATH} #${TF2TFLITEV2_BIN_PATH}
add_custom_target(tf2tfliteV2_conversion_test_python_deps ALL
DEPENDS ${VIRTUALENV} ${REQUIREMENTS_BIN_PATH}
)

nncc_find_resource(TensorFlowTests)
Expand Down Expand Up @@ -91,9 +83,6 @@ foreach(PREFIX IN ITEMS ${TESTCASES})
set(INFO_FILE "${PREFIX}.info")
set(INFO_PATH "${CMAKE_CURRENT_BINARY_DIR}/${INFO_FILE}")

set(PB_FILE "${PREFIX}.pb")
set(PB_PATH "${CMAKE_CURRENT_BINARY_DIR}/${PB_FILE}")

# Copy .pbtxt
add_custom_command(OUTPUT ${PBTXT_PATH}
COMMAND ${CMAKE_COMMAND} -E copy "${PBTXT_SOURCE_PATH}" "${PBTXT_PATH}"
Expand All @@ -108,14 +97,7 @@ foreach(PREFIX IN ITEMS ${TESTCASES})
COMMENT "Generate ${INFO_FILE}"
)

# Generate .pb from .pbtxt
add_custom_command(OUTPUT ${PB_PATH}
COMMAND $<TARGET_FILE:tfkit> encode ${PBTXT_PATH} ${PB_PATH}
DEPENDS ${PBTXT_PATH}
COMMENT "Generate ${PB_FILE}"
)

list(APPEND TEST_DEPS ${INFO_PATH} ${PB_PATH})
list(APPEND TEST_DEPS ${INFO_PATH} ${PBTXT_PATH})
list(APPEND TEST_NAMES ${PREFIX})
endforeach(PREFIX)

Expand Down Expand Up @@ -146,36 +128,23 @@ set(TF2TFLITEV2_PATH "${TF2TFLITEV2_BIN_DIR}/tf2tfliteV2.py")
add_custom_command(
OUTPUT ${TEST_CONFIG}
COMMAND ${CMAKE_COMMAND} -E remove -f ${TEST_CONFIG}
COMMAND ${CMAKE_COMMAND} -E echo 'NNKIT_RUN_PATH=\"$<TARGET_FILE:nnkit-run>\"' >> ${TEST_CONFIG}
COMMAND ${CMAKE_COMMAND} -E echo 'TF_BACKEND_PATH=\"$<TARGET_FILE:nnkit_tf_backend>\"' >> ${TEST_CONFIG}
COMMAND ${CMAKE_COMMAND} -E echo 'TFLITE_BACKEND_PATH=\"$<TARGET_FILE:nnkit_tflite_backend>\"' >> ${TEST_CONFIG}
COMMAND ${CMAKE_COMMAND} -E echo 'RANDOMIZE_ACTION_PATH=\"$<TARGET_FILE:nnkit_randomize_action>\"' >> ${TEST_CONFIG}
COMMAND ${CMAKE_COMMAND} -E echo 'HDF5_EXPORT_ACTION_PATH=\"$<TARGET_FILE:nnkit_HDF5_export_action>\"' >> ${TEST_CONFIG}
COMMAND ${CMAKE_COMMAND} -E echo 'HDF5_IMPORT_ACTION_PATH=\"$<TARGET_FILE:nnkit_HDF5_import_action>\"' >> ${TEST_CONFIG}
COMMAND ${CMAKE_COMMAND} -E echo 'I5DIFF_PATH=\"$<TARGET_FILE:i5diff>\"' >> ${TEST_CONFIG}
COMMAND ${CMAKE_COMMAND} -E echo 'TF2TFLITEV2_PATH=\"${TF2TFLITEV2_PATH}\"' >> ${TEST_CONFIG}
COMMAND ${CMAKE_COMMAND} -E echo 'VIRTUALENV=\"${VIRTUALENV}\"' >> ${TEST_CONFIG}
DEPENDS
i5diff
nnkit-run
nnkit_tf_backend
nnkit_tflite_backend
nnkit_randomize_action
nnkit_HDF5_export_action
nnkit_HDF5_import_action
tf2tfliteV2
tf2tfliteV2_value_pbtxt_python_deps
tf2tfliteV2_conversion_test_python_deps
COMMENT "Generate test configuration"
)

list(APPEND TEST_DEPS "${TEST_CONFIG}")

# This "tf2tfliteV2_value_pbtxt_test_deps" target enforces CMake to generate all the dependencies during "build" phase
add_custom_target(tf2tfliteV2_value_pbtxt_test_deps ALL DEPENDS ${TEST_DEPS})
# This "tf2tfliteV2_conversion_test_deps" target enforces CMake to generate all the dependencies during "build" phase
add_custom_target(tf2tfliteV2_conversion_test_deps ALL DEPENDS ${TEST_DEPS})

# TODO This test takes a long time and will only be tested once a day.
# Run tests
# add_test(
# NAME tf2tfliteV2_value_pbtxt_test
# NAME tf2tfliteV2_conversion_test
# COMMAND "${TEST_RUNNER}"
# "${TEST_CONFIG}"
# "${CMAKE_CURRENT_BINARY_DIR}"
Expand Down
1 change: 1 addition & 0 deletions compiler/tf2tfliteV2-conversion-test/requires.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require("tf2tfliteV2")
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,8 @@ WORKDIR="$1"; shift

source "${CONFIG_PATH}"

echo "-- Found nnkit-run: ${NNKIT_RUN_PATH}"
echo "-- Found TF backend: ${TF_BACKEND_PATH}"
echo "-- Found TFLITE backend: ${TFLITE_BACKEND_PATH}"
echo "-- Found TF2TFLITEV2: ${TF2TFLITEV2_PATH}"
echo "-- Found randomize action: ${RANDOMIZE_ACTION_PATH}"
echo "-- Found HDF5 export action: ${HDF5_EXPORT_ACTION_PATH}"
echo "-- Found HDF5 import action: ${HDF5_IMPORT_ACTION_PATH}"
echo "-- Found i5diff: ${I5DIFF_PATH}"
echo "-- Found workdir: ${WORKDIR}"
echo "-- Found python virtualenv: ${VIRTUALENV}"

TESTED=()
PASSED=()
Expand All @@ -45,7 +38,7 @@ while [[ $# -ne 0 ]]; do
cat > "${PREFIX}.log" <(
exec 2>&1
echo "-- Found pb: ${PREFIX}.pb"
echo "-- Found pbtxt: ${PREFIX}.pbtxt"
# Exit immediately if any command fails
set -e
Expand All @@ -56,34 +49,12 @@ while [[ $# -ne 0 ]]; do
source "${VIRTUALENV}/bin/activate"
"${VIRTUALENV}/bin/python" "${TF2TFLITEV2_PATH}" \
--v1 \
--input_path "${WORKDIR}/${PREFIX}.pb" \
--input_path "${WORKDIR}/${PREFIX}.pbtxt" \
--input_arrays "$(awk -F, '/^input/ { print $2 }' ${PREFIX}.info | cut -d: -f1 | tr -d ' ' | paste -d, -s)" \
--input_shapes "$(cat ${PREFIX}.info | grep '^input' | cut -d '[' -f2 | cut -d ']' -f1 | tr -d ' ' | xargs | tr ' ' ':')" \
--output_path "${WORKDIR}/${PREFIX}.tflite" \
--output_arrays "$(awk -F, '/^output/ { print $2 }' ${PREFIX}.info | cut -d: -f1 | tr -d ' ' | paste -d, -s)"
# Run TensorFlow
"${NNKIT_RUN_PATH}" \
--backend "${TF_BACKEND_PATH}" \
--backend-arg "${WORKDIR}/${PREFIX}.pb" \
--backend-arg "${WORKDIR}/${PREFIX}.info" \
--pre "${RANDOMIZE_ACTION_PATH}" \
--pre "${HDF5_EXPORT_ACTION_PATH}" \
--pre-arg "${WORKDIR}/${PREFIX}.input.h5" \
--post "${HDF5_EXPORT_ACTION_PATH}" \
--post-arg "${WORKDIR}/${PREFIX}.expected.h5"
# Run TensorFlow Lite
"${NNKIT_RUN_PATH}" \
--backend "${TFLITE_BACKEND_PATH}" \
--backend-arg "${WORKDIR}/${PREFIX}.tflite" \
--pre "${HDF5_IMPORT_ACTION_PATH}" \
--pre-arg "${WORKDIR}/${PREFIX}.input.h5" \
--post "${HDF5_EXPORT_ACTION_PATH}" \
--post-arg "${WORKDIR}/${PREFIX}.obtained.h5"
"${I5DIFF_PATH}" -d 0.001 "${PREFIX}.expected.h5" "${PREFIX}.obtained.h5"
if [[ $? -eq 0 ]]; then
touch "${PASSED_TAG}"
fi
Expand Down
4 changes: 0 additions & 4 deletions compiler/tf2tfliteV2-value-pbtxt-test/requires.cmake

This file was deleted.

0 comments on commit 81ce09a

Please sign in to comment.