diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5a750a0aef715e1c89d6dfe7de51f41b8918950f..6c881969b76d907ca804b0e73a0dc913c56d2bee 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -35,6 +35,6 @@ - id: cpplint-cpp-source name: cpplint description: Check C++ code style using cpplint.py. - entry: bash cpplint_pre_commit.hook + entry: bash ./tools/codestyle/cpplint_pre_commit.hook language: system files: \.(c|cc|cxx|cpp|cu|h|hpp|hxx)$ diff --git a/deploy/cpp/include/paddlex/results.h b/deploy/cpp/include/paddlex/results.h index de90c4a85130f42c0201f0d671fd3e2d53b0f37d..1643c9249e8e8e993017c7702d1d490352c2d9a8 100644 --- a/deploy/cpp/include/paddlex/results.h +++ b/deploy/cpp/include/paddlex/results.h @@ -63,9 +63,10 @@ class SegResult : public BaseResult { public: Mask label_map; Mask score_map; + std::string type = "seg"; void clear() { label_map.clear(); score_map.clear(); } }; -} // namespce of PaddleX +} // namespace PaddleX diff --git a/deploy/lite/export_lite.py b/deploy/lite/export_lite.py index b56aee9ee803b943473178b67f38c0f8d41a00da..0286d8733868dfbbaceadbfcf7d6728e367341df 100644 --- a/deploy/lite/export_lite.py +++ b/deploy/lite/export_lite.py @@ -19,30 +19,30 @@ import argparse def export_lite(): opt = lite.Opt() - model_file = os.path.join(FLAGS.model_path, '__model__') - params_file = os.path.join(FLAGS.model_path, '__params__') - opt.run_optimize("", model_file, params_file, FLAGS.place, FLAGS.save_dir) + model_file = os.path.join(FLAGS.model_dir, '__model__') + params_file = os.path.join(FLAGS.model_dir, '__params__') + opt.run_optimize("", model_file, params_file, FLAGS.place, FLAGS.save_file) if __name__ == '__main__': parser = argparse.ArgumentParser(description=__doc__) parser.add_argument( - "--model_path", + "--model_dir", type=str, default="", - help="model path.", + help="path of '__model__' and '__params__'.", required=True) parser.add_argument( "--place", type=str, default="arm", - help="preprocess config path.", + help="run place: 'arm|opencl|x86|npu|xpu|rknpu|apu'.", required=True) parser.add_argument( - "--save_dir", + "--save_file", type=str, default="paddlex.onnx", - help="Directory for storing the output visualization files.", + help="file name for storing the output files.", required=True) FLAGS = parser.parse_args() export_lite() diff --git a/docs/tutorials/deploy/deploy_lite.md b/docs/tutorials/deploy/deploy_lite.md index 0c4b1ec3600a90f8d112f0bf2487a2ee063b74fb..5419aed636545b95e9f98fdd45109592b7a6d9d6 100644 --- a/docs/tutorials/deploy/deploy_lite.md +++ b/docs/tutorials/deploy/deploy_lite.md @@ -1,5 +1,12 @@ # 移动端部署 +PaddleX的移动端部署由PaddleLite实现,部署的流程如下,首先将训练好的模型导出为inference model,然后使用PaddleLite的python接口对模型进行优化,最后使用PaddleLite的预测库进行部署, +PaddleLite的详细介绍和使用可参考:[PaddleLite文档](https://paddle-lite.readthedocs.io/zh/latest/) + +> PaddleX --> Inference Model --> PaddleLite Opt --> PaddleLite Inference + +以下介绍如何将PaddleX导出为inference model,然后使用PaddleLite的OPT模块对模型进行优化: + step 1: 安装PaddleLite ``` @@ -9,15 +16,21 @@ pip install paddlelite step 2: 将PaddleX模型导出为inference模型 参考[导出inference模型](deploy_server/deploy_python.html#inference)将模型导出为inference格式模型。 -**注意:由于PaddleX代码的持续更新,版本低于1.0.0的模型暂时无法直接用于预测部署,参考[模型版本升级](../upgrade_version.md)对模型版本进行升级。** +**注意:由于PaddleX代码的持续更新,版本低于1.0.0的模型暂时无法直接用于预测部署,参考[模型版本升级](./upgrade_version.md)对模型版本进行升级。** step 3: 将inference模型转换成PaddleLite模型 ``` -python /path/to/PaddleX/deploy/lite/export_lite.py --model_path /path/to/inference_model --save_dir /path/to/onnx_model +python /path/to/PaddleX/deploy/lite/export_lite.py --model_dir /path/to/inference_model --save_file /path/to/onnx_model --place place/to/run + ``` -`--model_path`用于指定inference模型的路径,`--save_dir`用于指定Lite模型的保存路径。 +| 参数 | 说明 | +| ---- | ---- | +| model_dir | 预测模型所在路径,包含"__model__", "__params__"文件 | +| save_file | 模型输出的名称,默认为"paddlex.nb" | +| place | 运行的平台,可选:arm|opencl|x86|npu|xpu|rknpu|apu | + step 4: 预测 diff --git a/tools/codestyle/clang_format.hook b/tools/codestyle/clang_format.hook new file mode 100755 index 0000000000000000000000000000000000000000..1d928216867c0ba3897d71542fea44debf8d72a0 --- /dev/null +++ b/tools/codestyle/clang_format.hook @@ -0,0 +1,15 @@ +#!/bin/bash +set -e + +readonly VERSION="3.8" + +version=$(clang-format -version) + +if ! [[ $version == *"$VERSION"* ]]; then + echo "clang-format version check failed." + echo "a version contains '$VERSION' is needed, but get '$version'" + echo "you can install the right version, and make an soft-link to '\$PATH' env" + exit -1 +fi + +clang-format $@ diff --git a/tools/codestyle/cpplint_pre_commit.hook b/tools/codestyle/cpplint_pre_commit.hook new file mode 100755 index 0000000000000000000000000000000000000000..630aeb8caaf88139fe8efae5c1f7e27f258d25c1 --- /dev/null +++ b/tools/codestyle/cpplint_pre_commit.hook @@ -0,0 +1,27 @@ +#!/bin/bash + +TOTAL_ERRORS=0 +if [[ ! $TRAVIS_BRANCH ]]; then + # install cpplint on local machine. + if [[ ! $(which cpplint) ]]; then + pip install cpplint + fi + # diff files on local machine. + files=$(git diff --cached --name-status | awk '$1 != "D" {print $2}') +else + # diff files between PR and latest commit on Travis CI. + branch_ref=$(git rev-parse "$TRAVIS_BRANCH") + head_ref=$(git rev-parse HEAD) + files=$(git diff --name-status $branch_ref $head_ref | awk '$1 != "D" {print $2}') +fi +# The trick to remove deleted files: https://stackoverflow.com/a/2413151 +for file in $files; do + if [[ $file =~ ^(patches/.*) ]]; then + continue; + else + cpplint --filter=-readability/fn_size $file; + TOTAL_ERRORS=$(expr $TOTAL_ERRORS + $?); + fi +done + +exit $TOTAL_ERRORS