!15730 [MS][LITE][TOD] fix crash in transfer_learning code example

From: @ehaleva
Reviewed-by: @HilbertDavid,@hangangqiang
Signed-off-by: @HilbertDavid
This commit is contained in:
mindspore-ci-bot 2021-04-27 09:04:06 +08:00 committed by Gitee
commit a03bc179a2
4 changed files with 6 additions and 12 deletions

View File

@ -1,6 +1,6 @@
BASE_DIR=$(realpath ../../../../)
APP:=bin/net_runner
MSLIB:=mindspore-lite
LMSLIB:=-lmindspore-lite-train
LMDLIB:=-lminddata-lite
MSDIR:=$(realpath package-$(TARGET)/lib)
ifneq ("$(wildcard $(MSDIR)/libhiai.so)","")
@ -23,10 +23,10 @@ ifeq ($(TARGET),arm64)
CXX := ${ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++
CFLAGS += --target=aarch64-none-linux-android21 --gcc-toolchain=${ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64 --sysroot=${ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/sysroot -fdata-sections -ffunction-sections
LDFLAGS := --target=aarch64-none-linux-android21 --gcc-toolchain=${ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64 --sysroot=${ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/sysroot -Wl,--gc-sections
LDFLAGS += -L$(MSDIR) -l$(MSLIB) $(LMDLIB) $(LHIAILIB) -pthread -llog -latomic -lm -Wl,-rpath,$(MSDIR)
LDFLAGS += -L$(MSDIR) $(LMSLIB) $(LMDLIB) $(LHIAILIB) -pthread -llog -latomic -lm -Wl,-rpath,$(MSDIR)
else
CFLAGS += -g
LDFLAGS := -L$(MSDIR) -l$(MSLIB) $(LMDLIB) $(LHIAILIB) -lpthread -Wl,-rpath,$(MSDIR)
LDFLAGS := -L$(MSDIR) $(LMSLIB) $(LMDLIB) $(LHIAILIB) -lpthread -Wl,-rpath,$(MSDIR)
endif
LD := ${CXX}

View File

@ -95,6 +95,7 @@ mv mindspore-* msl/
cp -r dataset ${PACKAGE}
echo "==========Compiling============"
make clean
make TARGET=${TARGET}
# Copy the executable to the package
@ -112,10 +113,6 @@ if [ "${TARGET}" == "arm64" ]; then
echo "========Training on Device====="
adb shell "cd /data/local/tmp/package-arm64 && /system/bin/sh train.sh"
echo
echo "===Evaluating trained Model====="
adb shell "cd /data/local/tmp/package-arm64 && /system/bin/sh eval.sh"
echo
else
cd ${PACKAGE} || exit 1
echo "==Evaluating Untrained Model==="
@ -124,8 +121,5 @@ else
echo "======Training Locally========="
./train.sh
echo "===Evaluating trained Model====="
./eval.sh
cd ..
fi

View File

@ -14,4 +14,4 @@
# limitations under the License.
# ============================================================================
LD_LIBRARY_PATH=./lib/ bin/net_runner -b model/transfer_learning_tod_backbone.ms -f model/transfer_learning_tod_head.ms -e 100 -d dataset -s 20
LD_LIBRARY_PATH=./lib/ bin/net_runner -b model/transfer_learning_tod_backbone.ms -f model/transfer_learning_tod_head.ms -e 100 -d dataset

View File

@ -211,7 +211,7 @@ int NetRunner::Main() {
float acc = CalculateAccuracy(ds_.val_data());
std::cout << "accuracy on validation data = " << acc << std::endl;
if (cycles_ > 0) {
if (cycles_ > 0 && head_model_ != nullptr) {
auto trained_fn = ms_head_file_.substr(0, ms_head_file_.find_last_of('.')) + "_trained.ms";
mindspore::lite::Model::Export(head_model_, trained_fn.c_str());
}