-
Notifications
You must be signed in to change notification settings - Fork 643
136 lines (130 loc) · 4.91 KB
/
backend-ncnn.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
name: backend-ncnn
on:
push:
paths-ignore:
- "demo/**"
- "tools/**"
pull_request:
paths-ignore:
- "demo/**"
- "tools/**"
- "docs/**"
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
test_onnx2ncnn:
runs-on: ubuntu-20.04
strategy:
matrix:
python-version: [3.7]
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: 'recursive'
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
sudo apt update
sudo apt install wget gcc-multilib g++-multilib wget libprotobuf-dev protobuf-compiler
python -m pip install cmake onnx
- name: Install ncnn
run: |
wget https://github.com/Tencent/ncnn/archive/refs/tags/20220420.tar.gz
tar xf 20220420.tar.gz
pushd ncnn-20220420
mkdir build && pushd build
cmake -DCMAKE_INSTALL_PREFIX=$(pwd)/../install -DNCNN_BUILD_TESTS=OFF -DNCNN_BUILD_TOOLS=OFF -DNCNN_BUILD_EXAMPLES=OFF ..
cmake --build . -j2
make install
popd && popd
- name: Install mmdeploy with ncnn backend
run: |
mkdir -p build && pushd build
export LD_LIBRARY_PATH=/home/runner/work/mmdeploy/mmdeploy/ncnn-20220420/install/lib/:$LD_LIBRARY_PATH
cmake -DMMDEPLOY_TARGET_BACKENDS=ncnn -Dncnn_DIR=/home/runner/work/mmdeploy/mmdeploy/ncnn-20220420/install/lib/cmake/ncnn/ ..
make mmdeploy_onnx2ncnn -j2
popd
- name: Test onnx2ncnn
run: |
echo $(pwd)
ln -s build/bin/mmdeploy_onnx2ncnn ./
python .github/scripts/test_onnx2ncnn.py --run 1
build_ncnn:
runs-on: ubuntu-20.04
strategy:
matrix:
python-version: [3.7]
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: 'recursive'
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install mmdeploy
run: |
python -m pip install torch==1.8.2 torchvision==0.9.2 --extra-index-url https://download.pytorch.org/whl/lts/1.8/cpu
python -m pip install mmcv-lite
python tools/scripts/build_ubuntu_x64_ncnn.py 8
python -c 'import mmdeploy.apis.ncnn as ncnn_api; assert ncnn_api.is_available(with_custom_ops=True)'
test_ncnn_ptq:
runs-on: [self-hosted, linux-3090]
container:
image: openmmlab/mmdeploy:ubuntu20.04-cuda11.3
options: "--gpus=all --ipc=host"
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: recursive
- name: Install dependencies
run: |
apt-get update
apt-get install ninja-build -y
python3 -V
python3 -m pip install openmim
python3 -m pip install -r requirements.txt
python3 -m mim install $(cat requirements/codebases.txt | grep mmpretrain)
python3 -m pip install numpy==1.22.0
python3 -m pip list
- name: Install mmdeploy
run: |
rm -rf .eggs && python3 -m pip install -e .
python3 tools/check_env.py
- name: Install ppq
run: |
git clone -b v0.6.6 --depth 1 https://github.com/openppl-public/ppq
cd ppq
python3 -m pip install -r requirements.txt
python3 setup.py install
- name: Test ncnn + ppq pipeline
run: |
export PYTHONPATH=${PWD}/ppq:${PYTHONPATH}
export LD_LIBRARY_PATH="/root/workspace/mmdeploy/build/lib:${LD_LIBRARY_PATH}"
export LD_LIBRARY_PATH="/root/workspace/mmdeploy/mmdeploy/lib:${LD_LIBRARY_PATH}"
export work_dir=./work_dir
mkdir -p $work_dir
export model_cfg=$work_dir/resnet18_8xb32_in1k.py
export deploy_cfg=configs/mmpretrain/classification_ncnn-int8_static.py
export checkpoint=$work_dir/resnet18_8xb32_in1k_20210831-fbbb1da6.pth
export input_img=tests/data/tiger.jpeg
python3 -m mim download mmpretrain --config resnet18_8xb32_in1k --dest $work_dir
python3 tools/torch2onnx.py $deploy_cfg $model_cfg $checkpoint $input_img --work-dir $work_dir
wget https://github.com/open-mmlab/mmdeploy/releases/download/v0.1.0/dataset.tar
tar xvf dataset.tar
python3 tools/onnx2ncnn_quant_table.py \
--onnx $work_dir/end2end.onnx \
--deploy-cfg $deploy_cfg \
--model-cfg $model_cfg \
--out-onnx $work_dir/quant.onnx \
--out-table $work_dir/ncnn.table \
--image-dir ./dataset
ls -sha $work_dir/quant.onnx
cat $work_dir/ncnn.table