diff --git a/tools/convert2tnn/build.sh b/tools/convert2tnn/build.sh index 82f755bbb..72c9bb110 100755 --- a/tools/convert2tnn/build.sh +++ b/tools/convert2tnn/build.sh @@ -1,41 +1,84 @@ -if [ ! -d "bin" ]; then - mkdir bin -fi - -if [ ! -d "temp" ]; then - mkdir temp -fi - -function build_model_check() { - cd $2 - - cmake ../../.. \ - -DCMAKE_BUILD_TYPE=Release \ - -DTNN_CPU_ENABLE:BOOL="ON" \ - -DTNN_MODEL_CHECK_ENABLE:BOOL="ON" \ - -DTNN_CONVERTER_ENABLE:BOOL="ON" \ - -DTNN_BUILD_SHARED="OFF" - - make -j4 - cp tools/converter/TnnConverter ../bin/ - - if [ -f "model_check" ]; then - mv model_check ../$1 - - cd .. - - rm -rf $2 - - cd ../onnx2tnn/onnx-converter - ./build.sh - - echo "Compiled successfully !" - else - cd .. - rm -rf $1 $2 - echo "Compiled failed !!!" - fi +#!/usr/bin/env bash + +CURRENT_DIR=$(pwd) +CLEAN="" +BUILD_DIR=build +BIN_DIR=bin + +function usage() { + echo "usage: ./build.sh [-c]" + echo "options:" + echo " -c Clean up build folders." +} + +function clean_build() { + echo $1 | grep "${BUILD_DIR}\b" >/dev/null + if [[ "$?" != "0" ]]; then + die "Warnning: $1 seems not to be a BUILD folder." + fi + rm -rf $1 + mkdir -p $1 +} + +function build_model_check_and_tnn_converter() { + + if [ "-c" == "${CLEAN}" ]; then + clean_build ${BUILD_DIR} + fi + pwd + mkdir -p ${BUILD_DIR} + cd ${BUILD_DIR} + + cmake ../../.. \ + -DCMAKE_BUILD_TYPE=DEBUG \ + -DTNN_CPU_ENABLE:BOOL="ON" \ + -DTNN_MODEL_CHECK_ENABLE:BOOL="ON" \ + -DTNN_CONVERTER_ENABLE:BOOL="ON" \ + -DTNN_BUILD_SHARED="OFF" \ + -DDEBUG="ON" + + make -j4 + + if [ -f "model_check" ]; then + cp model_check ../${BIN_DIR} + echo "Compiled model_check successfully !" + else + + echo "Compiled model_check failed !!!" + fi + + if [ -f "tools/converter/TnnConverter" ]; then + cp tools/converter/TnnConverter ../${BIN_DIR} + echo "Compiled model_check successfully !" + else + echo "Compiled TNNConverter failed !!!" + fi } -build_model_check bin temp +function build_onnx2tnn() { + cd ${CURRENT_DIR} + cd ../onnx2tnn/onnx-converter/ + + if [ "-c" == "${CLEAN}" ]; then + ./build.sh -c + else + ./build.sh + fi +} + +while [ "$1" != "" ]; do + case $1 in + -c) + shift + CLEAN="-c" + ;; + *) + usage + exit 1 + ;; + esac +done + +build_model_check_and_tnn_converter +build_onnx2tnn diff --git a/tools/convert2tnn/utils/align_model.py b/tools/convert2tnn/utils/align_model.py index 73e77389f..a44e29eeb 100644 --- a/tools/convert2tnn/utils/align_model.py +++ b/tools/convert2tnn/utils/align_model.py @@ -43,8 +43,7 @@ def run_tnn_model_check(proto_path, model_path, input_path, reference_output_pat if ret == 0: print_align_message(is_tflite) else: - print_not_align_message(None, is_tflie) - + print_not_align_message(None, is_tflite) return diff --git a/tools/onnx2tnn/onnx-converter/build.sh b/tools/onnx2tnn/onnx-converter/build.sh index 9b64ac965..b24ab9de0 100755 --- a/tools/onnx2tnn/onnx-converter/build.sh +++ b/tools/onnx2tnn/onnx-converter/build.sh @@ -1,29 +1,59 @@ -export CMAKE=/path/to/cmake -export CPP_COMPILER=/path/to/g++ -export C_COMPILER=/path/to/gcc -export PYTHON=/path/to/python3 +##!/usr/bin/env bash -# here is an example, make sure libpython3 is in LD_LIBRARY_PATH export CMAKE=cmake export CPP_COMPILER=g++ export C_COMPILER=gcc export PYTHON=`which python3` -set -xe +CLEAN="" +BUILD_DIR=build -if [ -d "build" ]; then - rm -rf build/ -fi +#set -xe -$PYTHON script/detect_dependency.py +function usage() { + echo "usage: ./build.sh [-c]" + echo "options:" + echo " -c Clean up build folders." +} -mkdir -p build -cd build && $CMAKE .. \ - -DCMAKE_CXX_COMPILER=$CPP_COMPILER \ - -DCMAKE_C_COMPILER=$C_COMPILER \ - -DPYTHON_EXECUTABLE=$PYTHON \ - && make -j4 && cd .. +function clean_build() { + echo $1 | grep "${BUILD_DIR}\b" > /dev/null + if [[ "$?" != "0" ]]; then + die "Warnning: $1 seems not to be a BUILD folder." + fi + rm -rf $1 + mkdir -p $1 +} -cp build/*.so . +function build() { -rm -rf build/ + $PYTHON script/detect_dependency.py + if [ "-c" == "${CLEAN}" ]; then + clean_build ${BUILD_DIR} + fi + mkdir -p ${BUILD_DIR} + cd ${BUILD_DIR} + + ${CMAKE} .. -DCMAKE_CXX_COMPILER=$CPP_COMPILER \ + -DCMAKE_C_COMPILER=$C_COMPILER \ + -DPYTHON_EXECUTABLE=$PYTHON \ + + make -j4 + cp *.so ../ + cd ../ +} + + +while [ "$1" != "" ]; do + case $1 in + -c) + shift + CLEAN="-c" + ;; + *) + usage + exit 1 + esac +done + +build