From 2c8ab3f483a2fe24d99df2b37b91988bdd660804 Mon Sep 17 00:00:00 2001 From: yeyunpeng2020 Date: Tue, 16 Mar 2021 19:03:48 +0800 Subject: [PATCH] adjust cropper and demo --- build.sh | 110 ++++++++++-------- .../lite/examples/quick_start_cpp/build.sh | 17 +-- .../lite/examples/quick_start_java/build.sh | 43 +++++++ mindspore/lite/examples/runtime_cpp/build.sh | 17 +-- mindspore/lite/examples/runtime_cpp/main.cc | 1 + mindspore/lite/tools/cropper/cropper.cc | 39 ++++--- mindspore/lite/tools/cropper/cropper.h | 6 +- 7 files changed, 146 insertions(+), 87 deletions(-) create mode 100644 mindspore/lite/examples/quick_start_java/build.sh diff --git a/build.sh b/build.sh index a4b00cf9e1..1a931525eb 100755 --- a/build.sh +++ b/build.sh @@ -557,6 +557,8 @@ build_lite() local LOCAL_LITE_PLATFORM=${LITE_PLATFORM} local LOCAL_INC_BUILD=${INC_BUILD} local LOCAL_LITE_ENABLE_GPU=${LITE_ENABLE_GPU} + local LOCAL_LITE_ENABLE_NPU=${ENABLE_NPU} + if [[ "${LITE_LANGUAGE}" == "java" ]]; then if [[ "X$1" != "X" ]]; then LOCAL_LITE_PLATFORM=$1 @@ -573,13 +575,23 @@ build_lite() else LOCAL_LITE_ENABLE_GPU="" fi + mkdir -p ${BASEPATH}/mindspore/lite/build/java + cd ${BASEPATH}/mindspore/lite/build/ + find . -maxdepth 1 | grep -v java | grep '/' | xargs -I {} rm -rf {} + fi + if [[ "${LITE_LANGUAGE}" == "cpp" ]]; then + if [[ "${DEVICE}" == "" && "${LOCAL_LITE_PLATFORM}" == "arm64" ]]; then + LOCAL_LITE_ENABLE_GPU="opencl" + LOCAL_LITE_ENABLE_NPU="on" + fi + + if [[ "${LOCAL_INC_BUILD}" == "off" ]]; then + rm -rf ${BASEPATH}/mindspore/lite/build + fi + mkdir -pv ${BASEPATH}/mindspore/lite/build fi - LITE_ENABLE_NPU=${ENABLE_NPU} - if [[ "${LITE_LANGUAGE}" == "cpp" && "${DEVICE}" == "" && "${LOCAL_LITE_PLATFORM}" == "arm64" ]]; then - LOCAL_LITE_ENABLE_GPU="opencl" - LITE_ENABLE_NPU="on" - fi - if [ "${LITE_ENABLE_NPU}" == "on" ]; then + + if [ "${LOCAL_LITE_ENABLE_NPU}" == "on" ]; then if [ "${LOCAL_LITE_PLATFORM}" == "arm64" ]; then checkddk else @@ -588,12 +600,7 @@ build_lite() fi fi - cd "${BASEPATH}/mindspore/lite" - if [[ "${LOCAL_INC_BUILD}" == "off" ]]; then - rm -rf build - fi - mkdir -pv build - cd build + cd ${BASEPATH}/mindspore/lite/build write_commit_file BUILD_TYPE="Release" if [[ "${DEBUG_MODE}" == "on" ]]; then @@ -607,7 +614,7 @@ build_lite() -DANDROID_STL=${ANDROID_STL} -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DSUPPORT_TRAIN=${SUPPORT_TRAIN} \ -DPLATFORM_ARM64=on -DENABLE_NEON=on -DENABLE_FP16="on" \ -DENABLE_TOOLS=${ENABLE_TOOLS} -DENABLE_CONVERTER=${ENABLE_CONVERTER} -DBUILD_TESTCASES=${RUN_TESTCASES} \ - -DSUPPORT_GPU=${LOCAL_LITE_ENABLE_GPU} -DSUPPORT_NPU=${LITE_ENABLE_NPU} -DENABLE_V0=on \ + -DSUPPORT_GPU=${LOCAL_LITE_ENABLE_GPU} -DSUPPORT_NPU=${LOCAL_LITE_ENABLE_NPU} -DENABLE_V0=on \ -DOFFLINE_COMPILE=${OPENCL_OFFLINE_COMPILE} -DBUILD_MINDDATA=${COMPILE_MINDDATA_LITE} \ -DCMAKE_INSTALL_PREFIX=${BASEPATH}/output/tmp -DMS_VERSION_MAJOR=${VERSION_MAJOR} \ -DMS_VERSION_MINOR=${VERSION_MINOR} -DMS_VERSION_REVISION=${VERSION_REVISION} -DENABLE_VERBOSE=${ENABLE_VERBOSE} \ @@ -619,7 +626,7 @@ build_lite() -DANDROID_STL=${ANDROID_STL} -DCMAKE_BUILD_TYPE=${BUILD_TYPE} \ -DPLATFORM_ARM32=on -DENABLE_NEON=on -DSUPPORT_TRAIN=${SUPPORT_TRAIN} \ -DENABLE_TOOLS=${ENABLE_TOOLS} -DENABLE_CONVERTER=${ENABLE_CONVERTER} -DBUILD_TESTCASES=${RUN_TESTCASES} \ - -DSUPPORT_GPU=${LOCAL_LITE_ENABLE_GPU} -DSUPPORT_NPU=${ENABLE_NPU} -DENABLE_V0=on \ + -DSUPPORT_GPU=${LOCAL_LITE_ENABLE_GPU} -DSUPPORT_NPU=${LOCAL_LITE_ENABLE_NPU} -DENABLE_V0=on \ -DOFFLINE_COMPILE=${OPENCL_OFFLINE_COMPILE} -DBUILD_MINDDATA=${COMPILE_MINDDATA_LITE} \ -DCMAKE_INSTALL_PREFIX=${BASEPATH}/output/tmp -DMS_VERSION_MAJOR=${VERSION_MAJOR} \ -DMS_VERSION_MINOR=${VERSION_MINOR} -DMS_VERSION_REVISION=${VERSION_REVISION} -DENABLE_VERBOSE=${ENABLE_VERBOSE} \ @@ -627,7 +634,7 @@ build_lite() else cmake -DPLATFORM_ARM64=off -DSUPPORT_TRAIN=${SUPPORT_TRAIN} \ -DENABLE_TOOLS=${ENABLE_TOOLS} -DENABLE_CONVERTER=${ENABLE_CONVERTER} -DBUILD_TESTCASES=${RUN_TESTCASES} \ - -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DSUPPORT_GPU=${LOCAL_LITE_ENABLE_GPU} -DSUPPORT_NPU=${ENABLE_NPU} \ + -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DSUPPORT_GPU=${LOCAL_LITE_ENABLE_GPU} -DSUPPORT_NPU=${LOCAL_LITE_ENABLE_NPU} \ -DBUILD_MINDDATA=${COMPILE_MINDDATA_LITE} -DENABLE_V0=on \ -DOFFLINE_COMPILE=${OPENCL_OFFLINE_COMPILE} -DCMAKE_INSTALL_PREFIX=${BASEPATH}/output/tmp \ -DMS_VERSION_MAJOR=${VERSION_MAJOR} -DMS_VERSION_MINOR=${VERSION_MINOR} -DMS_VERSION_REVISION=${VERSION_REVISION} \ @@ -639,7 +646,11 @@ build_lite() echo "---------------- mindspore lite: build failed ----------------" exit 1 else - mv ${BASEPATH}/output/tmp/*.tar.gz* ${BASEPATH}/output/ + if [[ "${LITE_LANGUAGE}" == "cpp" ]]; then + mv ${BASEPATH}/output/tmp/*.tar.gz* ${BASEPATH}/output/ + elif [[ "${LITE_LANGUAGE}" == "java" ]]; then + mv ${BASEPATH}/output/tmp/*.tar.gz* ${BASEPATH}/mindspore/lite/build/java + fi rm -rf ${BASEPATH}/output/tmp/ echo "---------------- mindspore lite: build success ----------------" if [[ "X$LITE_LANGUAGE" = "Xcpp" ]]; then @@ -654,7 +665,7 @@ build_lite_java_arm64() { if [[ "X$SUPPORT_TRAIN" = "Xon" ]]; then JTARBALL=mindspore-lite-${VERSION_STR}-train-android-aarch64 fi - if [[ "X$INC_BUILD" = "Xoff" ]] || [[ ! -f "${BASEPATH}/output/${JTARBALL}.tar.gz" ]]; then + if [[ "X$INC_BUILD" == "Xoff" ]] || [[ ! -f "${BASEPATH}/mindspore/lite/build/java/${JTARBALL}.tar.gz" ]]; then if [[ "X${DEVICE}" == "Xcpu" ]]; then build_lite "arm64" "off" "" elif [[ "X${DEVICE}" == "Xnpu" ]]; then @@ -665,18 +676,18 @@ build_lite_java_arm64() { fi fi # copy arm64 so - cd ${BASEPATH}/output/ + cd ${BASEPATH}/mindspore/lite/build/java/ rm -rf ${JTARBALL} tar -zxvf ${JTARBALL}.tar.gz [ -n "${JAVA_PATH}" ] && rm -rf ${JAVA_PATH}/java/app/libs/arm64-v8a/ mkdir -p ${JAVA_PATH}/java/app/libs/arm64-v8a/ mkdir -p ${JAVA_PATH}/native/libs/arm64-v8a/ if [[ "X$SUPPORT_TRAIN" = "Xon" ]]; then - cp ${BASEPATH}/output/${JTARBALL}/train/lib/libmindspore-lite.so ${JAVA_PATH}/java/app/libs/arm64-v8a/ - cp ${BASEPATH}/output/${JTARBALL}/train/lib/libmindspore-lite.so ${JAVA_PATH}/native/libs/arm64-v8a/ + cp ${BASEPATH}/mindspore/lite/build/java/${JTARBALL}/train/lib/libmindspore-lite.so ${JAVA_PATH}/java/app/libs/arm64-v8a/ + cp ${BASEPATH}/mindspore/lite/build/java/${JTARBALL}/train/lib/libmindspore-lite.so ${JAVA_PATH}/native/libs/arm64-v8a/ else - cp ${BASEPATH}/output/${JTARBALL}/inference/lib/libmindspore-lite.so ${JAVA_PATH}/java/app/libs/arm64-v8a/ - cp ${BASEPATH}/output/${JTARBALL}/inference/lib/libmindspore-lite.so ${JAVA_PATH}/native/libs/arm64-v8a/ + cp ${BASEPATH}/mindspore/lite/build/java/${JTARBALL}/inference/lib/libmindspore-lite.so ${JAVA_PATH}/java/app/libs/arm64-v8a/ + cp ${BASEPATH}/mindspore/lite/build/java/${JTARBALL}/inference/lib/libmindspore-lite.so ${JAVA_PATH}/native/libs/arm64-v8a/ fi [ -n "${VERSION_STR}" ] && rm -rf ${JTARBALL} } @@ -687,22 +698,22 @@ build_lite_java_arm32() { if [[ "X$SUPPORT_TRAIN" = "Xon" ]]; then JTARBALL=mindspore-lite-${VERSION_STR}-train-android-aarch32 fi - if [[ "X$INC_BUILD" = "Xoff" ]] || [[ ! -f "${BASEPATH}/output/${JTARBALL}.tar.gz" ]]; then + if [[ "X$INC_BUILD" == "Xoff" ]] || [[ ! -f "${BASEPATH}/mindspore/lite/build/java/${JTARBALL}.tar.gz" ]]; then build_lite "arm32" "off" "" fi # copy arm32 so - cd ${BASEPATH}/output/ + cd ${BASEPATH}/mindspore/lite/build/java/ rm -rf ${JTARBALL} tar -zxvf ${JTARBALL}.tar.gz [ -n "${JAVA_PATH}" ] && rm -rf ${JAVA_PATH}/java/app/libs/armeabi-v7a/ mkdir -p ${JAVA_PATH}/java/app/libs/armeabi-v7a/ mkdir -p ${JAVA_PATH}/native/libs/armeabi-v7a/ if [[ "X$SUPPORT_TRAIN" = "Xon" ]]; then - cp ${BASEPATH}/output/${JTARBALL}/train/lib/libmindspore-lite.so ${JAVA_PATH}/java/app/libs/armeabi-v7a/ - cp ${BASEPATH}/output/${JTARBALL}/train/lib/libmindspore-lite.so ${JAVA_PATH}/native/libs/armeabi-v7a/ + cp ${BASEPATH}/mindspore/lite/build/java/${JTARBALL}/train/lib/libmindspore-lite.so ${JAVA_PATH}/java/app/libs/armeabi-v7a/ + cp ${BASEPATH}/mindspore/lite/build/java/${JTARBALL}/train/lib/libmindspore-lite.so ${JAVA_PATH}/native/libs/armeabi-v7a/ else - cp ${BASEPATH}/output/${JTARBALL}/inference/lib/libmindspore-lite.so ${JAVA_PATH}/java/app/libs/armeabi-v7a/ - cp ${BASEPATH}/output/${JTARBALL}/inference/lib/libmindspore-lite.so ${JAVA_PATH}/native/libs/armeabi-v7a/ + cp ${BASEPATH}/mindspore/lite/build/java/${JTARBALL}/inference/lib/libmindspore-lite.so ${JAVA_PATH}/java/app/libs/armeabi-v7a/ + cp ${BASEPATH}/mindspore/lite/build/java/${JTARBALL}/inference/lib/libmindspore-lite.so ${JAVA_PATH}/native/libs/armeabi-v7a/ fi [ -n "${VERSION_STR}" ] && rm -rf ${JTARBALL} } @@ -710,26 +721,26 @@ build_lite_java_arm32() { build_lite_java_x86() { # build mindspore-lite x86 local JTARBALL=mindspore-lite-${VERSION_STR}-inference-linux-x64 - if [[ "X$INC_BUILD" = "Xoff" ]] || [[ ! -f "${BASEPATH}/output/${JTARBALL}.tar.gz" ]]; then + if [[ "X$INC_BUILD" == "Xoff" ]] || [[ ! -f "${BASEPATH}/mindspore/lite/build/java/${JTARBALL}.tar.gz" ]]; then build_lite "x86_64" "off" "" fi # copy x86 so - cd ${BASEPATH}/output/ + cd ${BASEPATH}/mindspore/lite/build/java rm -rf ${JTARBALL} tar -zxvf ${JTARBALL}.tar.gz [ -n "${JAVA_PATH}" ] && rm -rf ${JAVA_PATH}/java/linux_x86/libs/ mkdir -p ${JAVA_PATH}/java/linux_x86/libs/ mkdir -p ${JAVA_PATH}/native/libs/linux_x86/ - cp ${BASEPATH}/output/${JTARBALL}/inference/lib/libmindspore-lite.so ${JAVA_PATH}/java/linux_x86/libs/ - cp ${BASEPATH}/output/${JTARBALL}/inference/lib/libmindspore-lite.so ${JAVA_PATH}/native/libs/linux_x86/ + cp ${BASEPATH}/mindspore/lite/build/java/${JTARBALL}/inference/lib/libmindspore-lite.so ${JAVA_PATH}/java/linux_x86/libs/ + cp ${BASEPATH}/mindspore/lite/build/java/${JTARBALL}/inference/lib/libmindspore-lite.so ${JAVA_PATH}/native/libs/linux_x86/ } build_jni_arm64() { # build jni so cd "${BASEPATH}/mindspore/lite/build" - rm -rf java - mkdir -pv java - cd java + rm -rf java/jni + mkdir -pv java/jni + cd java/jni cmake -DCMAKE_TOOLCHAIN_FILE="${ANDROID_NDK}/build/cmake/android.toolchain.cmake" -DANDROID_NATIVE_API_LEVEL="19" \ -DANDROID_NDK="${ANDROID_NDK}" -DANDROID_ABI="arm64-v8a" -DANDROID_TOOLCHAIN_NAME="aarch64-linux-android-clang" \ -DMS_VERSION_MAJOR=${VERSION_MAJOR} -DMS_VERSION_MINOR=${VERSION_MINOR} -DMS_VERSION_REVISION=${VERSION_REVISION} \ @@ -741,17 +752,17 @@ build_jni_arm64() { exit 1 fi mkdir -p ${JAVA_PATH}/java/app/libs/arm64-v8a/ - cp ${BASEPATH}/mindspore/lite/build/java/libmindspore-lite-jni.so ${JAVA_PATH}/java/app/libs/arm64-v8a/ + cp ${BASEPATH}/mindspore/lite/build/java/jni/libmindspore-lite-jni.so ${JAVA_PATH}/java/app/libs/arm64-v8a/ mkdir -p ${JAVA_PATH}/native/libs/arm64-v8a/ - cp ${BASEPATH}/mindspore/lite/build/java/libmindspore-lite-jni.so ${JAVA_PATH}/native/libs/arm64-v8a/ + cp ${BASEPATH}/mindspore/lite/build/java/jni/libmindspore-lite-jni.so ${JAVA_PATH}/native/libs/arm64-v8a/ } build_jni_arm32() { # build jni so cd "${BASEPATH}/mindspore/lite/build" - rm -rf java - mkdir -pv java - cd java + rm -rf java/jni + mkdir -pv java/jni + cd java/jni cmake -DCMAKE_TOOLCHAIN_FILE="${ANDROID_NDK}/build/cmake/android.toolchain.cmake" -DANDROID_NATIVE_API_LEVEL="19" \ -DANDROID_NDK="${ANDROID_NDK}" -DANDROID_ABI="armeabi-v7a" -DANDROID_TOOLCHAIN_NAME="aarch64-linux-android-clang" \ -DMS_VERSION_MAJOR=${VERSION_MAJOR} -DMS_VERSION_MINOR=${VERSION_MINOR} -DMS_VERSION_REVISION=${VERSION_REVISION} \ @@ -763,17 +774,17 @@ build_jni_arm32() { exit 1 fi mkdir -p ${JAVA_PATH}/java/app/libs/armeabi-v7a/ - cp ${BASEPATH}/mindspore/lite/build/java/libmindspore-lite-jni.so ${JAVA_PATH}/java/app/libs/armeabi-v7a/ + cp ${BASEPATH}/mindspore/lite/build/java/jni/libmindspore-lite-jni.so ${JAVA_PATH}/java/app/libs/armeabi-v7a/ mkdir -p ${JAVA_PATH}/native/libs/armeabi-v7a/ - cp ${BASEPATH}/mindspore/lite/build/java/libmindspore-lite-jni.so ${JAVA_PATH}/native/libs/armeabi-v7a/ + cp ${BASEPATH}/mindspore/lite/build/java/jni/libmindspore-lite-jni.so ${JAVA_PATH}/native/libs/armeabi-v7a/ } build_jni_x86_64() { # build jni so cd "${BASEPATH}/mindspore/lite/build" - rm -rf java - mkdir -pv java - cd java + rm -rf java/jni + mkdir -pv java/jni + cd java/jni cmake -DMS_VERSION_MAJOR=${VERSION_MAJOR} -DMS_VERSION_MINOR=${VERSION_MINOR} -DMS_VERSION_REVISION=${VERSION_REVISION} \ -DENABLE_VERBOSE=${ENABLE_VERBOSE} "${JAVA_PATH}/native/" make -j$THREAD_NUM @@ -782,9 +793,9 @@ build_jni_x86_64() { exit 1 fi mkdir -p ${JAVA_PATH}/java/linux_x86/libs/ - cp ${BASEPATH}/mindspore/lite/build/java/libmindspore-lite-jni.so ${JAVA_PATH}/java/linux_x86/libs/ + cp ${BASEPATH}/mindspore/lite/build/java/jni/libmindspore-lite-jni.so ${JAVA_PATH}/java/linux_x86/libs/ mkdir -p ${JAVA_PATH}/native/libs/linux_x86/ - cp ${BASEPATH}/mindspore/lite/build/java/libmindspore-lite-jni.so ${JAVA_PATH}/native/libs/linux_x86/ + cp ${BASEPATH}/mindspore/lite/build/java/jni/libmindspore-lite-jni.so ${JAVA_PATH}/native/libs/linux_x86/ } check_java_home() { @@ -799,6 +810,9 @@ check_java_home() { build_java() { JAVA_PATH=${BASEPATH}/mindspore/lite/java get_version + if [[ "X${INC_BUILD}" == "Xoff" ]]; then + rm -rf ${BASEPATH}/mindspore/lite/build + fi # build common module cd ${JAVA_PATH}/java/common gradle clean @@ -844,7 +858,7 @@ build_java() { # copy output cp mindspore-lite-${VERSION_STR}-inference-linux-x64-jar.tar.gz ${BASEPATH}/output cd ${BASEPATH}/output - [ -n "${VERSION_STR}" ] && rm -rf mindspore-lite-${VERSION_STR}-inference-linux-x64 + [ -n "${VERSION_STR}" ] && rm -rf ${BASEPATH}/mindspore/lite/build/java/mindspore-lite-${VERSION_STR}-inference-linux-x64 exit 0 } diff --git a/mindspore/lite/examples/quick_start_cpp/build.sh b/mindspore/lite/examples/quick_start_cpp/build.sh index f7a84319ab..b0a404d9fe 100644 --- a/mindspore/lite/examples/quick_start_cpp/build.sh +++ b/mindspore/lite/examples/quick_start_cpp/build.sh @@ -23,7 +23,9 @@ get_version() { } get_version MODEL_DOWNLOAD_URL="https://download.mindspore.cn/model_zoo/official/lite/mobilenetv2_imagenet/mobilenetv2.ms" -MINDSPORE_LITE_DOWNLOAD_URL="https://ms-release.obs.cn-north-4.myhuaweicloud.com/${VERSION_STR}/MindSpore/lite/release/linux/mindspore-lite-${VERSION_STR}-inference-linux-x64.tar.gz" +MINDSPORE_FILE_NAME="mindspore-lite-${VERSION_STR}-linux-x64" +MINDSPORE_FILE="${MINDSPORE_FILE_NAME}.tar.gz" +MINDSPORE_LITE_DOWNLOAD_URL="https://ms-release.obs.cn-north-4.myhuaweicloud.com/${VERSION_STR}/MindSpore/lite/release/linux/${MINDSPORE_FILE}" mkdir -p build mkdir -p lib @@ -31,13 +33,12 @@ mkdir -p model if [ ! -e ${BASEPATH}/model/mobilenetv2.ms ]; then wget -c -O ${BASEPATH}/model/mobilenetv2.ms --no-check-certificate ${MODEL_DOWNLOAD_URL} fi -if [ ! -e ${BASEPATH}/build/mindspore-lite-${VERSION_STR}-inference-linux-x64.tar.gz ]; then - wget -c -O ${BASEPATH}/build/mindspore-lite-${VERSION_STR}-inference-linux-x64.tar.gz --no-check-certificate ${MINDSPORE_LITE_DOWNLOAD_URL} +if [ ! -e ${BASEPATH}/build/${MINDSPORE_FILE} ]; then + wget -c -O ${BASEPATH}/build/${MINDSPORE_FILE} --no-check-certificate ${MINDSPORE_LITE_DOWNLOAD_URL} fi -tar xzvf ${BASEPATH}/build/mindspore-lite-${VERSION_STR}-inference-linux-x64.tar.gz -C ${BASEPATH}/build/ -cp -r ${BASEPATH}/build/mindspore-lite-${VERSION_STR}-inference-linux-x64-avx/lib/libmindspore-lite.a ${BASEPATH}/lib -cp -r ${BASEPATH}/build/mindspore-lite-${VERSION_STR}-inference-linux-x64-avx/include ${BASEPATH}/ - +tar xzvf ${BASEPATH}/build/${MINDSPORE_FILE} -C ${BASEPATH}/build/ +cp -r ${BASEPATH}/build/${MINDSPORE_FILE_NAME}/inference/lib/libmindspore-lite.a ${BASEPATH}/lib +cp -r ${BASEPATH}/build/${MINDSPORE_FILE_NAME}/inference/include ${BASEPATH}/ cd ${BASEPATH}/build cmake ${BASEPATH} -make \ No newline at end of file +make diff --git a/mindspore/lite/examples/quick_start_java/build.sh b/mindspore/lite/examples/quick_start_java/build.sh new file mode 100644 index 0000000000..78603d874b --- /dev/null +++ b/mindspore/lite/examples/quick_start_java/build.sh @@ -0,0 +1,43 @@ +#!/bin/bash +# Copyright 2021 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ + +BASEPATH=$(cd "$(dirname $0)"; pwd) +get_version() { + VERSION_MAJOR=$(grep "const int ms_version_major =" ${BASEPATH}/../../include/version.h | tr -dc "[0-9]") + VERSION_MINOR=$(grep "const int ms_version_minor =" ${BASEPATH}/../../include/version.h | tr -dc "[0-9]") + VERSION_REVISION=$(grep "const int ms_version_revision =" ${BASEPATH}/../../include/version.h | tr -dc "[0-9]") + VERSION_STR=${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_REVISION} +} +get_version +MODEL_DOWNLOAD_URL="https://download.mindspore.cn/model_zoo/official/lite/mobilenetv2_imagenet/mobilenetv2.ms" +MINDSPORE_FILE_NAME="mindspore-lite-${VERSION_STR}-linux-x64" +MINDSPORE_FILE="${MINDSPORE_FILE_NAME}.tar.gz" +MINDSPORE_LITE_DOWNLOAD_URL="https://ms-release.obs.cn-north-4.myhuaweicloud.com/${VERSION_STR}/MindSpore/lite/release/linux/${MINDSPORE_FILE}" + +mkdir -p build +mkdir -p lib +mkdir -p model +if [ ! -e ${BASEPATH}/model/mobilenetv2.ms ]; then + wget -c -O ${BASEPATH}/model/mobilenetv2.ms --no-check-certificate ${MODEL_DOWNLOAD_URL} +fi +if [ ! -e ${BASEPATH}/build/${MINDSPORE_FILE} ]; then + wget -c -O ${BASEPATH}/build/${MINDSPORE_FILE} --no-check-certificate ${MINDSPORE_LITE_DOWNLOAD_URL} +fi +tar xzvf ${BASEPATH}/build/${MINDSPORE_FILE} -C ${BASEPATH}/build/ +cp -r ${BASEPATH}/build/${MINDSPORE_FILE_NAME}/inference/lib/jar/* ${BASEPATH}/lib +cd ${BASEPATH}/ + +mvn package diff --git a/mindspore/lite/examples/runtime_cpp/build.sh b/mindspore/lite/examples/runtime_cpp/build.sh index 53f065f242..73bd50544c 100644 --- a/mindspore/lite/examples/runtime_cpp/build.sh +++ b/mindspore/lite/examples/runtime_cpp/build.sh @@ -26,7 +26,9 @@ get_version() { } get_version MODEL_DOWNLOAD_URL="https://download.mindspore.cn/model_zoo/official/lite/mobilenetv2_imagenet/mobilenetv2.ms" -MINDSPORE_LITE_DOWNLOAD_URL="https://ms-release.obs.cn-north-4.myhuaweicloud.com/${VERSION_STR}/MindSpore/lite/release/android/mindspore-lite-${VERSION_STR}-inference-android.tar.gz" +MINDSPORE_FILE_NAME="mindspore-lite-${VERSION_STR}-android-aarch64" +MINDSPORE_FILE="${MINDSPORE_FILE_NAME}.tar.gz" +MINDSPORE_LITE_DOWNLOAD_URL="https://ms-release.obs.cn-north-4.myhuaweicloud.com/${VERSION_STR}/MindSpore/lite/release/android/${MINDSPORE_FILE}" mkdir -p build mkdir -p lib @@ -34,14 +36,13 @@ mkdir -p model if [ ! -e ${BASEPATH}/model/mobilenetv2.ms ]; then wget -c -O ${BASEPATH}/model/mobilenetv2.ms --no-check-certificate ${MODEL_DOWNLOAD_URL} fi -if [ ! -e ${BASEPATH}/build/mindspore-lite-${VERSION_STR}-inference-android.tar.gz ]; then - wget -c -O ${BASEPATH}/build/mindspore-lite-${VERSION_STR}-inference-android.tar.gz --no-check-certificate ${MINDSPORE_LITE_DOWNLOAD_URL} +if [ ! -e ${BASEPATH}/build/${MINDSPORE_FILE} ]; then + wget -c -O ${BASEPATH}/build/${MINDSPORE_FILE} --no-check-certificate ${MINDSPORE_LITE_DOWNLOAD_URL} fi -tar xzvf ${BASEPATH}/build/mindspore-lite-${VERSION_STR}-inference-android.tar.gz -C ${BASEPATH}/build/ -cp -r ${BASEPATH}/build/mindspore-lite-${VERSION_STR}-inference-android/lib/aarch64/libmindspore-lite.a ${BASEPATH}/lib -cp -r ${BASEPATH}/build/mindspore-lite-${VERSION_STR}-inference-android/third_party/hiai_ddk/lib/aarch64/*.so ${BASEPATH}/lib -cp -r ${BASEPATH}/build/mindspore-lite-${VERSION_STR}-inference-android/include ${BASEPATH}/ - +tar xzvf ${BASEPATH}/build/${MINDSPORE_FILE} -C ${BASEPATH}/build/ +cp -r ${BASEPATH}/build/${MINDSPORE_FILE_NAME}/inference/lib/libmindspore-lite.a ${BASEPATH}/lib +cp -r ${BASEPATH}/build/${MINDSPORE_FILE_NAME}/inference/third_party/hiai_ddk/lib/*.so ${BASEPATH}/lib +cp -r ${BASEPATH}/build/${MINDSPORE_FILE_NAME}/inference/include ${BASEPATH}/ cd ${BASEPATH}/build cmake -DCMAKE_TOOLCHAIN_FILE="${ANDROID_NDK}/build/cmake/android.toolchain.cmake" -DANDROID_NATIVE_API_LEVEL="19" \ -DANDROID_NDK="${ANDROID_NDK}" -DANDROID_ABI="arm64-v8a" -DANDROID_STL="c++_shared" ${BASEPATH} diff --git a/mindspore/lite/examples/runtime_cpp/main.cc b/mindspore/lite/examples/runtime_cpp/main.cc index 9eef61e1ea..5bb3566152 100644 --- a/mindspore/lite/examples/runtime_cpp/main.cc +++ b/mindspore/lite/examples/runtime_cpp/main.cc @@ -53,6 +53,7 @@ std::string RealPath(const char *path) { std::string res = resolved_path.get(); return res; } + char *ReadFile(const char *file, size_t *size) { if (file == nullptr) { std::cerr << "file is nullptr." << std::endl; diff --git a/mindspore/lite/tools/cropper/cropper.cc b/mindspore/lite/tools/cropper/cropper.cc index c9c3ecc502..482d3b4758 100644 --- a/mindspore/lite/tools/cropper/cropper.cc +++ b/mindspore/lite/tools/cropper/cropper.cc @@ -14,7 +14,6 @@ * limitations under the License. */ -#include #include #include "tools/cropper/cropper.h" #include "tools/cropper/cropper_utils.h" @@ -31,7 +30,7 @@ int Cropper::ReadPackage() { in_file.close(); char buf[BUF_SIZE]; - String cmd = "ar -t " + this->flags_->package_file_; + std::string cmd = "ar -t " + this->flags_->package_file_; MS_LOG(DEBUG) << cmd; FILE *p_file = popen(cmd.c_str(), "r"); @@ -40,8 +39,8 @@ int Cropper::ReadPackage() { return RET_ERROR; } while (fgets(buf, BUF_SIZE, p_file) != nullptr) { - this->all_files_.push_back(String(buf).substr(0, String(buf).length() - 1)); - this->discard_files_.push_back(String(buf).substr(0, String(buf).length() - 1)); + this->all_files_.push_back(std::string(buf).substr(0, std::string(buf).length() - 1)); + this->discard_files_.push_back(std::string(buf).substr(0, std::string(buf).length() - 1)); } pclose(p_file); MS_LOG(DEBUG) << "file nums: " << this->all_files_.size(); @@ -85,9 +84,9 @@ int Cropper::RunCropper() { } return RET_OK; } + int Cropper::GetModelOps() { for (const auto &path : this->model_files_) { - auto context = std::make_shared(); size_t buffer_lens; char *graph_buf = ReadFile(path.c_str(), &buffer_lens); if (graph_buf == nullptr) { @@ -124,6 +123,7 @@ int Cropper::GetModelOps() { } return RET_OK; } + int Cropper::GetModelFiles() { if (!this->flags_->model_file_.empty()) { auto files = StringSplit(this->flags_->model_file_, std::string(DELIM_COMMA)); @@ -132,16 +132,16 @@ int Cropper::GetModelFiles() { return RET_INPUT_PARAM_INVALID; } MS_LOG(DEBUG) << file; - String realPath = RealPath(file.c_str()); - if (realPath.empty()) { + std::string real_path = RealPath(file.c_str()); + if (real_path.empty()) { return RET_INPUT_PARAM_INVALID; } - this->model_files_.push_back(realPath); + this->model_files_.push_back(real_path); } } // get models from folder if (!this->flags_->model_folder_path_.empty()) { - String cmd = "find " + this->flags_->model_folder_path_ + " -name '*.ms'"; + std::string cmd = "find " + this->flags_->model_folder_path_ + " -name '*.ms'"; MS_LOG(DEBUG) << cmd; char buf[BUF_SIZE]; @@ -151,12 +151,12 @@ int Cropper::GetModelFiles() { return RET_ERROR; } while (fgets(buf, BUF_SIZE, p_file) != nullptr) { - String realPath = RealPath(String(buf).substr(0, String(buf).length() - 1).c_str()); - if (realPath.empty()) { + std::string real_path = RealPath(std::string(buf).substr(0, std::string(buf).length() - 1).c_str()); + if (real_path.empty()) { pclose(p_file); return RET_INPUT_PARAM_INVALID; } - this->model_files_.emplace_back(realPath); + this->model_files_.emplace_back(real_path); } pclose(p_file); } @@ -177,9 +177,9 @@ int Cropper::GetOpMatchFiles() { std::string buf_str = buf; auto mapping = StringSplit(buf_str, DELIM_COMMA); if (!mapping.empty()) { - String primitive = mapping[0]; - String type = mapping[1]; - String file = mapping[2]; + std::string primitive = mapping.at(0); + std::string type = mapping.at(1); + std::string file = mapping.at(2); if (type == "kNumberTypeFloat32" || type == "kNumberTypeFloat16" || type == "kNumberTypeInt32") { for (auto op : this->fp32_operators_) { if (schema::EnumNamePrimitiveType(op) == primitive) { @@ -219,6 +219,7 @@ int Cropper::GetOpMatchFiles() { } return RET_OK; } + int Cropper::GetDiscardFileList() { // discard_files_=all_files_-archive_files_ for (const auto &archive : this->archive_files_) { @@ -233,13 +234,13 @@ int Cropper::GetDiscardFileList() { return RET_OK; } int Cropper::CutPackage() { - String copy_bak_cmd = "cp " + this->flags_->package_file_ + " " + this->flags_->package_file_ + ".bak"; - String ar_cmd = "ar -d " + this->flags_->package_file_ + ".bak "; + std::string copy_bak_cmd = "cp " + this->flags_->package_file_ + " " + this->flags_->package_file_ + ".bak"; + std::string ar_cmd = "ar -d " + this->flags_->package_file_ + ".bak "; for (const auto &file : this->discard_files_) { ar_cmd.append(file).append(" "); } - String copy_to_output_cmd = "cp " + this->flags_->package_file_ + ".bak " + this->flags_->output_file_; - String rm_bak_cmd = "rm " + this->flags_->package_file_ + ".bak"; + std::string copy_to_output_cmd = "cp " + this->flags_->package_file_ + ".bak " + this->flags_->output_file_; + std::string rm_bak_cmd = "rm " + this->flags_->package_file_ + ".bak"; int status; status = system(copy_bak_cmd.c_str()); if (status != 0) { diff --git a/mindspore/lite/tools/cropper/cropper.h b/mindspore/lite/tools/cropper/cropper.h index 320a160dce..ae790c825d 100644 --- a/mindspore/lite/tools/cropper/cropper.h +++ b/mindspore/lite/tools/cropper/cropper.h @@ -20,17 +20,15 @@ #include #include #include -#include "include/model.h" #include "tools/common/flag_parser.h" #include "src/common/file_utils.h" #include "src/common/utils.h" #include "schema/model_generated.h" -#include "include/lite_session.h" #include "tools/cropper/cropper_flags.h" namespace mindspore::lite::cropper { -class MS_API Cropper { +class Cropper { public: explicit Cropper(CropperFlags *flags) : flags_(flags) {} @@ -63,6 +61,6 @@ class MS_API Cropper { CropperFlags *flags_; }; -int MS_API RunCropper(int argc, const char **argv); +int RunCropper(int argc, const char **argv); } // namespace mindspore::lite::cropper #endif // MINDSPORE_LITE_TOOLS_CROPPER_CROPPER_H_