|
1 | 1 | # Docker编译安装Paddle2ONNX
|
2 | 2 |
|
3 |
| -Paddle2ONNX编译安装需要确保环境满足以下需求 |
4 |
| -- cmake >= 3.18.0 |
5 |
| -- protobuf == 3.16.0 |
| 3 | +## 1 拉取manylinux镜像 |
6 | 4 |
|
7 |
| -注意:Paddle2ONNX产出的模型,在使用ONNX Runtime推理时,要求使用最新版本(1.10.0版本以及上),如若需要使用低版本(1.6~1.10之间),则需要将ONNX版本降至1.8.2,在执行完`git submodule update`后,执行如下命令,然后再进行编译 |
| 5 | +根据系统架构拉取不同的manylinux镜像 |
| 6 | + |
| 7 | +```bash |
| 8 | +# Pull manylinux2014_x86_64 |
| 9 | +docker pull quay.io/pypa/manylinux2014_x86_64 |
| 10 | +docker create --name p2o_build -it quay.io/pypa/manylinux2014_x86_64 /bin/bash |
| 11 | +# Pull manylinux2014_x86_64 |
| 12 | +docker pull quay.io/pypa/manylinux2014_aarch64 |
| 13 | +docker create --name p2o_build -it quay.io/pypa/manylinux2014_aarch64 /bin/bash |
8 | 14 | ```
|
9 |
| -cd Paddle2ONNX/third/onnx |
10 |
| -git checkout v1.8.1 |
| 15 | + |
| 16 | +## 2 创建并进入容器 |
| 17 | + |
| 18 | +创建并进入 Docker 容器 |
| 19 | + |
| 20 | +```bash |
| 21 | +docker start p2o_build |
| 22 | +docker exec -it p2o_build /bin/bash |
11 | 23 | ```
|
12 | 24 |
|
13 |
| -拉取manylinux镜像并创建容器 |
| 25 | +## 3 拉取 Paddle2ONNX 仓库 |
| 26 | + |
| 27 | +执行以下命令来拉取并初始化 Paddle2ONNX 仓库 |
14 | 28 |
|
15 | 29 | ```bash
|
16 |
| -docker pull quay.io/pypa/manylinux2014_x86_64 |
17 |
| -docker run --name p2o_build -d quay.io/pypa/manylinux2014_x86_64 |
| 30 | +git clone https://github.com/PaddlePaddle/Paddle2ONNX.git |
| 31 | +cd Paddle2ONNX |
| 32 | +git submodule init |
| 33 | +git submodule update |
| 34 | +``` |
| 35 | + |
| 36 | +## 4 获取 protobuf 依赖库 |
| 37 | + |
| 38 | +### 4.1 使用 protobuf 预编译库 |
| 39 | + |
| 40 | +执行以下命令来下载 protobuf 依赖库 |
| 41 | + |
| 42 | +```bash |
| 43 | +source .github/workflows/scripts/download_protobuf.sh |
18 | 44 | ```
|
19 | 45 |
|
20 |
| -创建容器并运行 |
| 46 | +### 4.2 下载并编译 protobuf 预编译库 |
| 47 | + |
| 48 | +执行以下命令来下载并编译 protobuf 预编译库 |
21 | 49 |
|
22 | 50 | ```bash
|
23 |
| -docker start p2o_build |
24 |
| -docker exec -it p2o_build bash |
| 51 | +git clone https://github.com/protocolbuffers/protobuf.git |
| 52 | +cd protobuf |
| 53 | +git checkout v3.16.0 |
| 54 | +mkdir build_source && cd build_source |
| 55 | +cmake ../cmake -DCMAKE_INSTALL_PREFIX=${PWD}/installed_protobuf_lib -Dprotobuf_BUILD_SHARED_LIBS=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=ON -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Release |
| 56 | +make -j8 |
| 57 | +make install |
| 58 | + |
| 59 | +# 将编译目录加入环境变量 |
| 60 | +export PATH=${PWD}/installed_protobuf_lib/bin:${PATH} |
25 | 61 | ```
|
26 | 62 |
|
| 63 | +## 5 执行编译和安装 |
| 64 | + |
| 65 | +```bash |
| 66 | +/opt/python/cp38-cp38/bin/pip install setuptools wheel auditwheel auditwheel-symbols build |
| 67 | +cd /path/to/Paddle2ONNX |
| 68 | +/opt/python/cp38-cp38/bin/python -m build |
| 69 | +/opt/python/cp38-cp38/bin/pip install dist/*.whl |
| 70 | +``` |
0 commit comments