From 1895534c94c95a622d9dcdfd15372a559ff04890 Mon Sep 17 00:00:00 2001 From: MegEngine Date: Sat, 9 Oct 2021 16:53:05 +0800 Subject: [PATCH 1/2] feat(examples): support aarch64 --- README.md | 2 +- .../build-on-aarch64.zh.md | 106 ++++++++++++++++++ .../warehouse/detection_yolox/lite.py | 6 +- 3 files changed, 112 insertions(+), 2 deletions(-) create mode 100644 docs/how-to-build-and-run/build-on-aarch64.zh.md diff --git a/README.md b/README.md index 465ca3d..2148617 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ MegFlow 提供快速视觉应用落地流程,最快 15 分钟搭建起视频 | x86 Ubuntu16.04 有 GPU | ✔️ | | x86 Ubuntu18.04 无 GPU | ✔️ | | x86 macos | ✔️ | -| ARM | / | +| ARM | ✔️ | | Python 版本 | 支持情况 | | - | - | diff --git a/docs/how-to-build-and-run/build-on-aarch64.zh.md b/docs/how-to-build-and-run/build-on-aarch64.zh.md new file mode 100644 index 0000000..df479e9 --- /dev/null +++ b/docs/how-to-build-and-run/build-on-aarch64.zh.md @@ -0,0 +1,106 @@ +# aarch64 源码编译 + +## 一、测试环境 +华为鲲鹏 ARM 服务器,centOS 7.9 + +## 二、环境安装 +**gcc 需要 >= 7.5 版本,默认的 `aarch64-redhat-linux-gcc 4.8.5` 缺 `__ARM_NEON` 没法用** +```bash +$ yum install -y centos-release-scl +$ yum install -y devtoolset-8-gcc devtoolset-8-gcc-c++ +$ source /opt/rh/devtoolset-8/enable +$ gcc --version +gcc (GCC) 8.3.1 20190311 (Red Hat 8.3.1-3) +... +``` + +### 安装 Rust +```bash +$ curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh +``` + +成功后,`cargo` 应该可以正常执行 +```bash +$ cargo --version +cargo 1.53.0 (4369396ce 2021-04-27) +``` + +> `cargo` 是 Rust 的包管理器兼编译辅助工具。类似 Java maven/go pkg/C++ CMake 的角色,更易使用。 + +### 安装 python3.x (推荐 conda) + +打开 [miniconda 官网](https://docs.conda.io/en/latest/miniconda.html) 下载 miniconda 安装包,修改权限并安装。 + +```bash +$ wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh +$ chmod a+x Miniconda3-latest-Linux-x86_64.sh +$ ./Miniconda3-latest-Linux-x86_64.sh +``` + +安装时接受 conda 修改默认 .bashrc 环境变量(zsh 用户还需自行修改 .zshrc 中的 conda initialize 配置)。成功后 `conda` 可正常运行 +```bash +$ conda --version +conda 4.10.3 +``` + +创建一个 Python3.x(这里以 3.8 为例) 的环境,激活。 +```bash +$ conda create --name py38 python=3.8 +$ conda activate py38 +``` + + +## 三、编译 + +编译底层 Rust 组件,安装 Python module + +```bash +$ git clone --recursive https://github.com/MegEngine/MegFlow --depth=1 +$ cd MegFlow +$ cargo build +waiting ... +$ cd flow-python +$ python3 setup.py install --user +``` + +P.S. 默认 ffmpeg 依赖自动从 github 上拉取源码构建,这会使得首次构建的时间较长。若希望缩短首次构建时间,或者希望依赖一个指定版本的 ffmpeg,可以启用环境变量`CARGO_FEATURE_PREBUILD`并参考[rust-ffmpeg](https://github.com/zmwangx/rust-ffmpeg/wiki/Notes-on-building)自行构建 + + +## 四、Python“开机自检” +```bash +$ cd examples +$ cargo build --example run_with_plugins --release # 编译出 megflow bin +$ ln -s ../../target/example/run_with_plugins +$ ./run_with_plugins -p logical_test +``` +`logical_test` 是 examples 下最基础的计算图测试用例,运行能正常结束表示 MegFlow 编译成功、基本语义无问题。 + +`run_with_plugins` 是计算图的实现。编译完成之后不再需要 `cargo` 和 `Rust`,使用者只需要 + + * `import megflow`成功 + * `run_with_plugins -h` 正常 + + +## 五、Python Built-in Applications + +接下来开始运行好玩的 Python 应用 + +* [猫猫围栏运行手册](../../flow-python/examples/cat_finder/README.md) + * 图片注册猫猫 + * 部署视频围栏,注册的猫离开围栏时会发通知 + * 未注册的不会提示 +* [电梯电瓶车告警](../../flow-python/examples/electric_bicycle/README.md) + * 电梯里看到电瓶车立即报警 +* Comming Soon + * OCR: 通用字符识别 + + +## 六、其他选项 +```bash +$ cargo run --example graph -- ${args} # 测试 MegFlow 的延迟/吞吐/调度开销, 更多使用说明通过--help 查看 +$ cargo run --example run_with_plugins -- ${args} # 基于插件 + 参数文件形式运行 MegFlow, 更多说明通过--help 查看 +$ export RUST_LOG=LOG_LEVEL // 设置日志级别, 例如 INFO, TRACE.. +$ cargo build [--release] // 编译 +$ cargo check // 快速编译,不执行 link +$ cargo test [target] // 执行单元测试 +``` diff --git a/flow-python/examples/warehouse/detection_yolox/lite.py b/flow-python/examples/warehouse/detection_yolox/lite.py index bf38653..bca3610 100644 --- a/flow-python/examples/warehouse/detection_yolox/lite.py +++ b/flow-python/examples/warehouse/detection_yolox/lite.py @@ -88,6 +88,7 @@ def __init__( net.load(path) self.net = net + self.device = device self.cls_names = cls_names self.decoder = decoder self.num_classes = 80 @@ -154,7 +155,10 @@ def inference(self, img): outputs = self.lite_postprocess(outputs[0], list(self.test_size)) outputs = outputs[np.newaxis, :] - output = mge.tensor(outputs) + if "gpu" in self.device: + output = mge.tensor(outputs) + else: + output = mge.tensor(outputs, device="cpux") ret = postprocess(output, self.num_classes, self.confthre, self.nmsthre) From 6a8e61f7599087bfe376ce8fcec8a9baf2e7a9c6 Mon Sep 17 00:00:00 2001 From: MegEngine Date: Sat, 9 Oct 2021 16:55:26 +0800 Subject: [PATCH 2/2] feat(docs): update README --- README.md | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 2148617..c3512fd 100644 --- a/README.md +++ b/README.md @@ -14,10 +14,11 @@ MegFlow 提供快速视觉应用落地流程,最快 15 分钟搭建起视频 ## HowTo * how to build and run - * [run in 15 minutes](docs/how-to-build-and-run/run-in-15-minutes.zh.md) + * [run with prebuilt .whl](docs/how-to-build-and-run/run-in-15-minutes.zh.md) * [build with docker](docs/how-to-build-and-run/build-with-docker.zh.md) * [build from source](docs/how-to-build-and-run/build-from-source.zh.md) * [build on win10](docs/how-to-build-and-run/build-on-win10.zh.md) + * [build on armv8](docs/how-to-build-and-run/build-on-aarch64.zh.md) * [generate rtsp](docs/how-to-build-and-run/generate-rtsp.zh.md) * how to use * [tutorial01: image classification service](docs/how-to-add-my-service/01-single-classification-model.zh.md) @@ -28,21 +29,21 @@ MegFlow 提供快速视觉应用落地流程,最快 15 分钟搭建起视频 ## Current Support List -| 系统环境 | 支持情况 | -| - | - | -| Windows 10 wsl2 | ✔️ | -| Windows 10 docker | ✔️ | -| x86 Ubuntu16.04 有 GPU | ✔️ | -| x86 Ubuntu18.04 无 GPU | ✔️ | -| x86 macos | ✔️ | +| 系统环境 | 支持情况 | +| ---------------------- | -------- | +| Windows 10 wsl2 | ✔️ | +| Windows 10 docker | ✔️ | +| x86 Ubuntu16.04 有 GPU | ✔️ | +| x86 Ubuntu18.04 无 GPU | ✔️ | +| x86 macos | ✔️ | | ARM | ✔️ | | Python 版本 | 支持情况 | -| - | - | -| 3.6 | ✔️ | -| 3.7 | ✔️ | -| 3.8 | ✔️ | -| 3.9 | / | +| ----------- | -------- | +| 3.6 | ✔️ | +| 3.7 | ✔️ | +| 3.8 | ✔️ | +| 3.9 | / | ## Built-in Applications * 猫猫围栏