Linux ARM架构编译Python版本Paddle-Lite(2021.1.21)
Linux ARM架构编译Python版本Paddle-Lite(2021.1.21)
目录
官方文档:https://paddle-lite.readthedocs.io/zh/latest/index.html
1. 编译环境
- Ubuntu 18.04 aarch64;
- python3.7;
2. 准备工作
2.1 安装 Python3.7
Paddle-Lite 编译 Python 版本根据官方文档介绍只支持 Python2.7、Python3.5 和 Python3.7 版本,Ubuntu 18.04 默认 Python 版本为 3.6,因此需要先安装 Python3.7 或其它支持版本。
-
安装相关依赖包
# 更新本地索引 $ sudo apt update # 安装相关依赖 $ sudo apt install software-properties-common
-
添加 Python 官方 PPA
# 添加python ppa $ sudo add-apt-repository ppa:deadsnakes/ppa # 更新本地索引 $ sudo apt update
-
安装 Python3.7
# 安装 python3.7 相关工具包 $ sudo apt install python3.7 python3.7-dev python3.7-venv python3-pip # 清除本地包缓存,释放磁盘空间 $ sudo apt clean
2.2 准备编译环境
编译环境要求:
- gcc、g++、git、make、wget、patchelf
- cmake(建议使用3.10或以上版本)
具体操作过程如下:
# 更新本地索引
$ sudo apt update
# 安装基础依赖包
$ sudo apt install gcc g++ make wget unzip patchelf
# 安装 cmake3.10 或更高版本
$ wget https://www.cmake.org/files/v3.10/cmake-3.10.3.tar.gz
$ tar -zxvf cmake-3.10.3.tar.gz
$ cd cmake-3.10.3
$ ./configure
$ make
$ sudo make install
3. 编译过程
下文中涉及到从 Github 下载源码的部分可能会因为网络问题比较慢,可以使用国内的镜像进行加速下载。此处提供一个国内镜像地址(https://hub.fastgit.org),利用该地址替换下文中的 https://github.com 即可。
3.1 下载源码
# 下载Paddle-Lite源码 并切换到release分支
$ git clone https://github.com/PaddlePaddle/Paddle-Lite.git
$ cd Paddle-Lite
$ git checkout -t origin/release/v2.6
3.2 准备第三方库文件
# 删除原来第三方库下的文件
$ rm third-party/*
# 准备第三方库文件
$ git clone https://github.com/google/flatbuffers.git third-party/flatbuffers
$ git clone https://github.com/gflags/gflags.git third-party/gflags
$ git clone https://github.com/google/googletest.git third-party/googletest
$ git clone https://github.com/protocolbuffers/protobuf.git third-party/protobuf-host
$ git clone https://github.com/tensor-tang/protobuf.git third-party/protobuf-mobile
3.3 开始编译
# 查看编译可选参数
$ ./lite/tools/build_linux.sh help
# 开始编译,等待编译完成
$ ./lite/tools/build_linux.sh --with_python=ON --python_version=3.7 --with_extra=ON --with_cv=ON
3.4 编译结果
# 查看编译结果
$ sudo apt install tree
$ tree build.lite.linux.armv8.gcc/inference_lite_lib.armlinux.armv8/
build.lite.linux.armv8.gcc/inference_lite_lib.armlinux.armv8/
|-- bin
| |-- benchmark_bin
| |-- paddle_code_generator
| `-- test_model_bin
|-- cxx
| |-- include
| | |-- paddle_api.h
| | |-- paddle_image_preprocess.h
| | |-- paddle_lite_factory_helper.h
| | |-- paddle_place.h
| | |-- paddle_use_kernels.h
| | |-- paddle_use_ops.h
| | `-- paddle_use_passes.h
| `-- lib
| |-- libpaddle_api_full_bundled.a
| |-- libpaddle_api_light_bundled.a
| |-- libpaddle_full_api_shared.so
| `-- libpaddle_light_api_shared.so
|-- demo
| `-- python
| |-- mobilenetv1_full_api.py
| `-- mobilenetv1_light_api.py
`-- python
|-- install
| |-- build
| | |-- bdist.linux-aarch64
| | |-- lib
| | | `-- paddlelite
| | | |-- __init__.py
| | | `-- lite.so
| | `-- scripts-3.7
| | `-- paddle_lite_opt
| |-- dist
| | `-- paddlelite-2708c2fe-cp37-cp37m-linux_aarch64.whl
| |-- libs
| |-- lite
| | |-- __init__.py
| | |-- lite.so
| | `-- paddle_lite_opt
| |-- paddlelite.egg-info
| | |-- PKG-INFO
| | |-- SOURCES.txt
| | |-- dependency_links.txt
| | `-- top_level.txt
| `-- setup.py
`-- lib
`-- lite.so
3.5 安装 Paddle-Lite
编译生成的安装包在 build.lite.linux.armv8.gcc/inference_lite_lib.armlinux.armv8/python/install/dist/paddlelite-2708c2fe-cp37-cp37m-linux_aarch64.whl
目录下,通过 Pip 离线安装 Paddle-Lite:
# 离线安装 Paddle-Lite
$ python3.7 -m pip install build.lite.linux.armv8.gcc/inference_lite_lib.armlinux.armv8/python/install/dist/paddlelite-2708c2fe-cp37-cp37m-linux_aarch64.whl
# 查看安装结果
$ python3.7 -m pip list
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 一文读懂知识蒸馏
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下