未验证 提交 daebeb0a 编写于 作者: Y Yuan Shuai 提交者: GitHub

[LITE][DEMO] add input check for demo (#2444)

* Add CheckInput. test=develop

* Fix android_log_ undef when using .a. test=develop

* add guide of how to use shared library in demo. test=develop
上级 6b3c341f
......@@ -5,6 +5,7 @@ message(STATUS "LIGHT_FRAMEWORK:\t${LITE_WITH_LIGHT_WEIGHT_FRAMEWORK}")
message(STATUS "LITE_WITH_CUDA:\t${LITE_WITH_CUDA}")
message(STATUS "LITE_WITH_X86:\t${LITE_WITH_X86}")
message(STATUS "LITE_WITH_ARM:\t${LITE_WITH_ARM}")
message(STATUS "LITE_WITH_OPENCL:\t${LITE_WITH_OPENCL}")
message(STATUS "LITE_WITH_NPU:\t${LITE_WITH_NPU}")
message(STATUS "LITE_WITH_XPU:\t${LITE_WITH_XPU}")
message(STATUS "LITE_WITH_FPGA:\t${LITE_WITH_FPGA}")
......
......@@ -9,6 +9,25 @@ CXX_INCLUDES = $(INCLUDES) -I$(LITE_ROOT)/cxx/include
CXX_LIBS = $(THIRD_PARTY_LIBS) $(LITE_ROOT)/cxx/lib/libpaddle_api_full_bundled.a $(SYSTEM_LIBS)
###############################################################
# How to use one of shared libraries: #
# `libpaddle_full_api_shared.so` #
# `libpaddle_light_api_shared.so` #
###############################################################
# Note: default use lite's static library. #
###############################################################
# 1. Comment above line using `libpaddle_api_full_bundled.a`;
# 2. Undo comment below line and execute
# `export LD_LIBRARY_PATH=<libpaddle_full_api_shared.so dir>`
# in command line before `make`;
# 3. After `adb push` model and mobilenetv1_full_api files to
# android devices, execute
# `export LD_LIBRARY_PATH=<libpaddle_full_api_shared.so android dir>`
# and `mobilenetv1_full_api` in android `adb shell`;
# 4. Get executed result of `mobilenetv1_full_api` in android.
# CXX_LIBS = $(THIRD_PARTY_LIBS) -L$(LITE_ROOT)/cxx/lib/ -lpaddle_full_api_shared $(SYSTEM_LIBS)
mobilenetv1_full_api: mobilenetv1_full_api.o
$(CC) $(SYSROOT_LINK) $(CXXFLAGS_LINK) mobilenetv1_full_api.o -o mobilenetv1_full_api $(CXX_LIBS) $(LDFLAGS)
......
......@@ -9,6 +9,25 @@ CXX_INCLUDES = $(INCLUDES) -I$(LITE_ROOT)/cxx/include
CXX_LIBS = $(THIRD_PARTY_LIBS) $(LITE_ROOT)/cxx/lib/libpaddle_api_full_bundled.a $(SYSTEM_LIBS)
###############################################################
# How to use one of shared libraries: #
# `libpaddle_full_api_shared.so` #
# `libpaddle_light_api_shared.so` #
###############################################################
# Note: default use lite's static library. #
###############################################################
# 1. Comment above line using `libpaddle_api_full_bundled.a`;
# 2. Undo comment below line and execute
# `export LD_LIBRARY_PATH=<libpaddle_full_api_shared.so dir>`
# in command line before `make`;
# 3. After `adb push` model and mobilenetv1_full_api files to
# android devices, execute
# `export LD_LIBRARY_PATH=<libpaddle_full_api_shared.so android dir>`
# and `mobilenetv1_full_api` in android `adb shell`;
# 4. Get executed result of `mobilenetv1_full_api` in android.
# CXX_LIBS = $(THIRD_PARTY_LIBS) -L$(LITE_ROOT)/cxx/lib/ -lpaddle_full_api_shared $(SYSTEM_LIBS)
mobilenetv1_full_api: mobilenetv1_full_api.o
$(CC) $(SYSROOT_LINK) $(CXXFLAGS_LINK) mobilenetv1_full_api.o -o mobilenetv1_full_api $(CXX_LIBS) $(LDFLAGS)
......
......@@ -9,6 +9,25 @@ CXX_INCLUDES = $(INCLUDES) -I$(LITE_ROOT)/cxx/include
CXX_LIBS = $(THIRD_PARTY_LIBS) $(LITE_ROOT)/cxx/lib/libpaddle_api_light_bundled.a $(SYSTEM_LIBS)
###############################################################
# How to use one of shared libraries: #
# `libpaddle_light_api_shared.so` #
# `libpaddle_full_api_shared.so` #
###############################################################
# Note: default use lite's static library. #
###############################################################
# 1. Comment above line using `libpaddle_api_light_bundled.a`;
# 2. Undo comment below line and execute
# `export LD_LIBRARY_PATH=<libpaddle_light_api_shared.so dir>`
# in command line before `make`;
# 3. After `adb push` model and mobilenetv1_light_api files to
# android devices, execute
# `export LD_LIBRARY_PATH=<libpaddle_light_api_shared.so android dir>`
# and `mobilenetv1_light_api` in android `adb shell`;
# 4. Get executed result of `mobilenetv1_light_api` in android.
# CXX_LIBS = $(THIRD_PARTY_LIBS) -L$(LITE_ROOT)/cxx/lib/ -lpaddle_light_api_shared $(SYSTEM_LIBS)
mobilenetv1_light_api: mobilenetv1_light_api.o
$(CC) $(SYSROOT_LINK) $(CXXFLAGS_LINK) mobilenetv1_light_api.o -o mobilenetv1_light_api $(CXX_LIBS) $(LDFLAGS)
......
......@@ -9,6 +9,25 @@ CXX_INCLUDES = $(INCLUDES) -I$(LITE_ROOT)/cxx/include
CXX_LIBS = $(THIRD_PARTY_LIBS) $(LITE_ROOT)/cxx/lib/libpaddle_api_light_bundled.a $(SYSTEM_LIBS)
###############################################################
# How to use one of shared libaray: #
# `libpaddle_light_api_shared.so` #
# `libpaddle_full_api_shared.so` #
###############################################################
# Note: default use lite's tatic library. #
###############################################################
# 1. Comment above line using `libpaddle_api_light_bundled.a`;
# 2. Undo comment below line and execute
# `export LD_LIBRARY_PATH=<libpaddle_light_api_shared dir>`
# in command line before `make`;
# 3. After `adb push` model and mobilenetv1_light_api files to
# android devices, execute
# `export LD_LIBRARY_PATH=<libpaddle_light_api_shared android dir>` and
# `mobilenetv1_light_api` in android `adb shell`;
# 4. Get executed result of `mobilenetv1_light_api` in android.
# CXX_LIBS = $(THIRD_PARTY_LIBS) -L$(LITE_ROOT)/cxx/lib/ -lpaddle_light_api_shared $(SYSTEM_LIBS)
mobilenetv1_light_api: mobilenetv1_light_api.o
$(CC) $(SYSROOT_LINK) $(CXXFLAGS_LINK) mobilenetv1_light_api.o -o mobilenetv1_light_api $(CXX_LIBS) $(LDFLAGS)
......
......@@ -32,6 +32,27 @@ int64_t ShapeProduction(const shape_t& shape) {
return res;
}
void CheckInput(char*** argv) {
if (FLAGS_model_dir == "") {
printf(
"Usage: %s --model_dir=<your-model-directory> "
"--optimized_model_dir=<your-optmized-model-directory> "
"--prefer_int8_kernel=[true|false]\n",
*argv[0]);
exit(1);
}
if (FLAGS_optimized_model_dir == "") {
FLAGS_optimized_model_dir = FLAGS_model_dir;
printf(
"[WARN] no `optimized_model_dir` provided. set `optimized_model_dir` "
":= `model_dir`:%s\n",
FLAGS_optimized_model_dir.c_str());
}
printf("[WARN] model_dir:%s\n", FLAGS_model_dir.c_str());
printf("[WARN] optimized_model_dir:%s\n", FLAGS_optimized_model_dir.c_str());
printf("[WARN] prefer_int8_kernel:%s\n", FLAGS_prefer_int8_kernel);
}
// 0. Enable OpenCL, if needed
// Enable `DEMO_WITH_OPENCL` macro below, if user need use gpu(opencl)
// #define DEMO_WITH_OPENCL
......@@ -86,6 +107,7 @@ void RunModel() {
int main(int argc, char** argv) {
google::ParseCommandLineFlags(&argc, &argv, true);
CheckInput(&argv);
RunModel();
return 0;
}
......@@ -29,6 +29,14 @@ int64_t ShapeProduction(const shape_t& shape) {
return res;
}
void CheckInput(char*** argv) {
if (FLAGS_model_dir == "") {
printf("Usage: %s --model_dir=<your-nb-model-directory>\n", *argv[0]);
exit(1);
}
printf("[WARN] model_dir:%s\n", FLAGS_model_dir.c_str());
}
void RunModel() {
// 1. Set MobileConfig
MobileConfig config;
......@@ -60,6 +68,7 @@ void RunModel() {
int main(int argc, char** argv) {
google::ParseCommandLineFlags(&argc, &argv, true);
CheckInput(&argv);
RunModel();
return 0;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册