Skip to content

Commit b23411d

Browse files
authored
fix(tools/scripts): find env file failed (#1385)
* fix(tools/scripts): find env file failed * Update quantize_model.md
1 parent b5b0dcf commit b23411d

File tree

8 files changed

+28
-15
lines changed

8 files changed

+28
-15
lines changed

docs/en/02-how-to-run/quantize_model.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ The fixed-point model has many advantages over the fp32 model:
88
- Benefit from the smaller model, the Cache hit rate is improved and inference would be faster
99
- Chips tend to have corresponding fixed-point acceleration instructions which are faster and less energy consumed (int8 on a common CPU requires only about 10% of energy)
1010

11-
The size of the installation package and the heat generation are the key indicators of the mobile terminal evaluation APP;
12-
On the server side, quantization means that you can maintain the same QPS and improve model precision in exchange for improved accuracy.
11+
APK file size and heat generation are key indicators while evaluating mobile APP;
12+
On server side, quantization means that you can increase model size in exchange for precision and keep the same QPS.
1313

1414
## Post training quantization scheme
1515

@@ -21,7 +21,7 @@ Taking ncnn backend as an example, the complete workflow is as follows:
2121

2222
mmdeploy generates quantization table based on static graph (onnx) and uses backend tools to convert fp32 model to fixed point.
2323

24-
Currently mmdeploy support ncnn with PTQ.
24+
mmdeploy currently support ncnn with PTQ.
2525

2626
## How to convert model
2727

@@ -38,10 +38,15 @@ Back in mmdeploy, enable quantization with the option 'tools/deploy.py --quant'.
3838

3939
```bash
4040
cd /path/to/mmdeploy
41-
export MODEL_PATH=/path/to/mmclassification/configs/resnet/resnet18_8xb16_cifar10.py
42-
export MODEL_CONFIG=https://download.openmmlab.com/mmclassification/v0/resnet/resnet18_b16x8_cifar10_20210528-bd6371c8.pth
4341

44-
python3 tools/deploy.py configs/mmcls/classification_ncnn-int8_static.py ${MODEL_CONFIG} ${MODEL_PATH} /path/to/self-test.png --work-dir work_dir --device cpu --quant --quant-image-dir /path/to/images
42+
export MODEL_CONFIG=/home/rg/konghuanjun/mmclassification/configs/resnet/resnet18_8xb32_in1k.py
43+
export MODEL_PATH=https://download.openmmlab.com/mmclassification/v0/resnet/resnet18_8xb32_in1k_20210831-fbbb1da6.pth
44+
45+
# get some imagenet sample images
46+
git clone https://github.com/nihui/imagenet-sample-images --depth=1
47+
48+
# quantize
49+
python3 tools/deploy.py configs/mmcls/classification_ncnn-int8_static.py ${MODEL_CONFIG} ${MODEL_PATH} /path/to/self-test.png --work-dir work_dir --device cpu --quant --quant-image-dir /path/to/imagenet-sample-images
4550
...
4651
```
4752

@@ -56,7 +61,7 @@ Description
5661

5762
Calibration set is used to calculate quantization layer parameters. Some DFQ (Data Free Quantization) methods do not even require a dataset.
5863

59-
- Create a new folder, just put in the picture (no directory structure required, no negative example required, no filename format required)
64+
- Create a folder, just put in some images (no directory structure, no negative example, no special filename format)
6065
- The image needs to be the data comes from real scenario otherwise the accuracy would be drop
6166
- You can not quantize model with test dataset
6267
| Type | Train dataset | Validation dataset | Test dataset | Calibration dataset |

docs/zh_cn/02-how-to-run/quantize_model.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ cd /path/to/mmdeploy
4040
export MODEL_CONFIG=/path/to/mmclassification/configs/resnet/resnet18_8xb16_cifar10.py
4141
export MODEL_PATH=https://download.openmmlab.com/mmclassification/v0/resnet/resnet18_b16x8_cifar10_20210528-bd6371c8.pth
4242

43-
python3 tools/deploy.py configs/mmcls/classification_ncnn-int8_static.py ${MODEL_CONFIG} ${MODEL_PATH} /path/to/self-test.png --work-dir work_dir --device cpu --quant --quant-image-dir /path/to/images
43+
# 找一些 imagenet 样例图
44+
git clone https://github.com/nihui/imagenet-sample-images --depth=1
45+
46+
# 量化模型
47+
python3 tools/deploy.py configs/mmcls/classification_ncnn-int8_static.py ${MODEL_CONFIG} ${MODEL_PATH} /path/to/self-test.png --work-dir work_dir --device cpu --quant --quant-image-dir /path/to/imagenet-sample-images
4448
...
4549
```
4650

tools/scripts/build_ubuntu_x64_ncnn.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os
33
import sys
44
import time
5+
from pathlib import Path
56

67
from ubuntu_utils import cmd_result, ensure_base_env, get_job
78

@@ -175,7 +176,7 @@ def main():
175176
if install_mmdeploy(work_dir, dep_dir, ncnn_cmake_dir) != 0:
176177
return -1
177178

178-
if os.path.exists('~/mmdeploy.env'):
179+
if os.path.exists(Path('~/mmdeploy.env').expanduser()):
179180
print('Please source ~/mmdeploy.env to setup your env !')
180181
os.system('cat ~/mmdeploy.env')
181182

tools/scripts/build_ubuntu_x64_ort.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os
33
import sys
44
import time
5+
from pathlib import Path
56

67
from ubuntu_utils import ensure_base_env, get_job
78

@@ -94,7 +95,7 @@ def main():
9495
if install_mmdeploy(work_dir, ort_dir) != 0:
9596
return -1
9697

97-
if os.path.exists('~/mmdeploy.env'):
98+
if os.path.exists(Path('~/mmdeploy.env').expanduser()):
9899
print('Please source ~/mmdeploy.env to setup your env !')
99100
os.system('cat ~/mmdeploy.env')
100101

tools/scripts/build_ubuntu_x64_pplnn.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os
33
import sys
44
import time
5+
from pathlib import Path
56

67
from ubuntu_utils import cmd_result, ensure_base_env, get_job
78

@@ -65,7 +66,7 @@ def install_pplnn(dep_dir, build_cuda):
6566

6667
os.system('cd python/package && ./build.sh')
6768
os.system(
68-
'cd /tmp/pyppl-package/dist && python3 -m pip install pyppl*.whl --force-reinstall' # noqa: E501
69+
'cd /tmp/pyppl-package/dist && python3 -m pip install pyppl*.whl --force-reinstall --user' # noqa: E501
6970
)
7071

7172
pplnn_cmake_dir = os.path.join(pplnn_dir,
@@ -150,7 +151,7 @@ def main():
150151
build_cuda) != 0:
151152
return -1
152153

153-
if os.path.exists('~/mmdeploy.env'):
154+
if os.path.exists(Path('~/mmdeploy.env').expanduser()):
154155
print('Please source ~/mmdeploy.env to setup your env !')
155156
os.system('cat ~/mmdeploy.env')
156157

tools/scripts/build_ubuntu_x64_torchscript.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os
33
import sys
44
import time
5+
from pathlib import Path
56

67
from ubuntu_utils import (cmd_result, cu_version_name, ensure_base_env,
78
get_job, pytorch_version)
@@ -118,7 +119,7 @@ def main():
118119
if install_mmdeploy(work_dir, libtorch_dir) != 0:
119120
return -1
120121

121-
if os.path.exists('~/mmdeploy.env'):
122+
if os.path.exists(Path('~/mmdeploy.env').expanduser()):
122123
print('Please source ~/mmdeploy.env to setup your env !')
123124
os.system('cat ~/mmdeploy.env')
124125

tools/scripts/ubuntu_cross_build_aarch64.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ build_ocv() {
3333
fi
3434
cd opencv/platforms/linux/cross_build_aarch64
3535
rm -rf CMakeCache.txt
36-
cmake ../../.. -DCMAKE_INSTALL_PREFIX=/tmp/ocv-aarch64 -DCMAKE_TOOLCHAIN_FILE=../aarch64-gnu.toolchain.cmake
36+
cmake ../../.. -DBUILD_TIFF=ON -DCMAKE_INSTALL_PREFIX=/tmp/ocv-aarch64 -DCMAKE_TOOLCHAIN_FILE=../aarch64-gnu.toolchain.cmake
3737
good_nproc
3838
jobs=$?
3939
make -j${jobs}

tools/scripts/ubuntu_cross_build_rknn.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ build_ocv_arm_gnueabi() {
6060
cd opencv/build_arm_gnueabi
6161
rm -rf CMakeCache.txt
6262
cmake .. -DCMAKE_INSTALL_PREFIX=install -DCMAKE_TOOLCHAIN_FILE=../platforms/linux/arm-gnueabi.toolchain.cmake \
63-
-DBUILD_PERF_TESTS=OFF -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Release
63+
-DBUILD_TIFF=ON -DBUILD_PERF_TESTS=OFF -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Release
6464
good_nproc
6565
jobs=$?
6666
make -j${jobs} && make install

0 commit comments

Comments
 (0)