From 73c128b432b5fc6b3a158644e44e841ddd5138d2 Mon Sep 17 00:00:00 2001 From: silingtong123 <35439432+silingtong123@users.noreply.github.com> Date: Mon, 25 May 2020 01:59:55 +0800 Subject: [PATCH] fix the demo of opt saved can't work on windows (#3686) fix the demo of opt saved can't work on windows fix the doc --- docs/demo_guides/python_demo.md | 11 +++++++++-- docs/demo_guides/x86.md | 8 ++++---- lite/model_parser/model_parser.cc | 2 +- lite/utils/io.h | 9 ++++++++- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/docs/demo_guides/python_demo.md b/docs/demo_guides/python_demo.md index 24ce217e57..4370a6fbbf 100644 --- a/docs/demo_guides/python_demo.md +++ b/docs/demo_guides/python_demo.md @@ -27,12 +27,19 @@ tar zxf mobilenet_v1.tar.gz - 非combined形式:模型文件夹model_dir下存在一个模型文件和多个参数文件时,传入模型文件夹路径,模型文件名默认为__model__。 ```shell - paddle_lite_opt --model_dir=./mobilenet_v1 --valid_targets=mobilenet_v1_opt --valid_targets=x86 + paddle_lite_opt --model_dir=./mobilenet_v1 \ + --optimize_out=mobilenet_v1_opt \ + --optimize_out_type=naive_buffer \ + --valid_targets=x86 ``` - combined形式:模型文件夹model_dir下只有一个模型文件__model__和一个参数文件__params__时,传入模型文件和参数文件路径 ```shell - paddle_lite_opt --model_file=./mobilenet_v1/__model__ --param_file=./mobilenet_v1/__params__ --valid_targets=mobilenet_v1_opt --valid_targets=x86 + paddle_lite_opt --model_file=./mobilenet_v1/__model__ \ + --param_file=./mobilenet_v1/__params__ \ + --optimize_out=mobilenet_v1_opt \ + --optimize_out_type=naive_buffer \ + --valid_targets=x86 ``` - windows环境 diff --git a/docs/demo_guides/x86.md b/docs/demo_guides/x86.md index a8a4c117b6..d551daa892 100644 --- a/docs/demo_guides/x86.md +++ b/docs/demo_guides/x86.md @@ -209,9 +209,9 @@ git checkout release/v2.6.0 ``` 2、 源码编译(需要按照提示输入对应的参数) -```bash +```dos cd Paddle-Lite -lite/tools/build_windows.bat +lite\tools\build_windows.bat ``` ### 编译结果说明 @@ -269,8 +269,8 @@ build.bat cd build ``` 编译结果为当前目录下的 `Release\mobilenet_full_api.exe ` -``` bash +``` dos # 2、执行预测 -Release\\mobilenet_full_api.exe mobilenet_v1 +Release\mobilenet_full_api.exe mobilenet_v1 ``` 下载并解压模型[`mobilenet_v1`](http://paddle-inference-dist.bj.bcebos.com/mobilenet_v1.tar.gz)到`build`目录,执行以上命令进行预测。 diff --git a/lite/model_parser/model_parser.cc b/lite/model_parser/model_parser.cc index 8bf3f87c61..77c7543d6b 100644 --- a/lite/model_parser/model_parser.cc +++ b/lite/model_parser/model_parser.cc @@ -323,7 +323,7 @@ void SaveCombinedParamsPb(const std::string &path, std::sort(paramlist.begin(), paramlist.end()); // Load vars - std::ofstream file(path); + std::ofstream file(path, std::ios::binary); CHECK(file.is_open()); for (size_t i = 0; i < paramlist.size(); ++i) { SerializeTensor(file, exec_scope, paramlist[i]); diff --git a/lite/utils/io.h b/lite/utils/io.h index 92405cae86..506901bad5 100644 --- a/lite/utils/io.h +++ b/lite/utils/io.h @@ -38,10 +38,17 @@ static bool IsFileExists(const std::string& path) { // ARM mobile not support mkdir in C++ static void MkDirRecur(const std::string& path) { #ifndef LITE_WITH_ARM + +#ifdef _WIN32 + if (system(string_format("md %s", path.c_str()).c_str()) != 0) { + LOG(ERROR) << "Cann't mkdir " << path; + } +#else if (system(string_format("mkdir -p %s", path.c_str()).c_str()) != 0) { LOG(ERROR) << "Cann't mkdir " << path; } -#else // On ARM +#endif // _WIN32 +#else // On ARM CHECK_NE(mkdir(path.c_str(), S_IRWXU), -1) << "Cann't mkdir " << path; #endif } -- GitLab