fix(tools/scripts): find env file failed (#1385)
* fix(tools/scripts): find env file failed * Update quantize_model.mdpull/1420/head
parent
b5b0dcfcff
commit
b23411d907
|
@ -8,8 +8,8 @@ The fixed-point model has many advantages over the fp32 model:
|
|||
- Benefit from the smaller model, the Cache hit rate is improved and inference would be faster
|
||||
- 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)
|
||||
|
||||
The size of the installation package and the heat generation are the key indicators of the mobile terminal evaluation APP;
|
||||
On the server side, quantization means that you can maintain the same QPS and improve model precision in exchange for improved accuracy.
|
||||
APK file size and heat generation are key indicators while evaluating mobile APP;
|
||||
On server side, quantization means that you can increase model size in exchange for precision and keep the same QPS.
|
||||
|
||||
## Post training quantization scheme
|
||||
|
||||
|
@ -21,7 +21,7 @@ Taking ncnn backend as an example, the complete workflow is as follows:
|
|||
|
||||
mmdeploy generates quantization table based on static graph (onnx) and uses backend tools to convert fp32 model to fixed point.
|
||||
|
||||
Currently mmdeploy support ncnn with PTQ.
|
||||
mmdeploy currently support ncnn with PTQ.
|
||||
|
||||
## How to convert model
|
||||
|
||||
|
@ -38,10 +38,15 @@ Back in mmdeploy, enable quantization with the option 'tools/deploy.py --quant'.
|
|||
|
||||
```bash
|
||||
cd /path/to/mmdeploy
|
||||
export MODEL_PATH=/path/to/mmclassification/configs/resnet/resnet18_8xb16_cifar10.py
|
||||
export MODEL_CONFIG=https://download.openmmlab.com/mmclassification/v0/resnet/resnet18_b16x8_cifar10_20210528-bd6371c8.pth
|
||||
|
||||
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
|
||||
export MODEL_CONFIG=/home/rg/konghuanjun/mmclassification/configs/resnet/resnet18_8xb32_in1k.py
|
||||
export MODEL_PATH=https://download.openmmlab.com/mmclassification/v0/resnet/resnet18_8xb32_in1k_20210831-fbbb1da6.pth
|
||||
|
||||
# get some imagenet sample images
|
||||
git clone https://github.com/nihui/imagenet-sample-images --depth=1
|
||||
|
||||
# quantize
|
||||
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
|
||||
...
|
||||
```
|
||||
|
||||
|
@ -56,7 +61,7 @@ Description
|
|||
|
||||
Calibration set is used to calculate quantization layer parameters. Some DFQ (Data Free Quantization) methods do not even require a dataset.
|
||||
|
||||
- Create a new folder, just put in the picture (no directory structure required, no negative example required, no filename format required)
|
||||
- Create a folder, just put in some images (no directory structure, no negative example, no special filename format)
|
||||
- The image needs to be the data comes from real scenario otherwise the accuracy would be drop
|
||||
- You can not quantize model with test dataset
|
||||
| Type | Train dataset | Validation dataset | Test dataset | Calibration dataset |
|
||||
|
|
|
@ -40,7 +40,11 @@ cd /path/to/mmdeploy
|
|||
export MODEL_CONFIG=/path/to/mmclassification/configs/resnet/resnet18_8xb16_cifar10.py
|
||||
export MODEL_PATH=https://download.openmmlab.com/mmclassification/v0/resnet/resnet18_b16x8_cifar10_20210528-bd6371c8.pth
|
||||
|
||||
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
|
||||
# 找一些 imagenet 样例图
|
||||
git clone https://github.com/nihui/imagenet-sample-images --depth=1
|
||||
|
||||
# 量化模型
|
||||
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
|
||||
...
|
||||
```
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
import os
|
||||
import sys
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
from ubuntu_utils import cmd_result, ensure_base_env, get_job
|
||||
|
||||
|
@ -175,7 +176,7 @@ def main():
|
|||
if install_mmdeploy(work_dir, dep_dir, ncnn_cmake_dir) != 0:
|
||||
return -1
|
||||
|
||||
if os.path.exists('~/mmdeploy.env'):
|
||||
if os.path.exists(Path('~/mmdeploy.env').expanduser()):
|
||||
print('Please source ~/mmdeploy.env to setup your env !')
|
||||
os.system('cat ~/mmdeploy.env')
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
import os
|
||||
import sys
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
from ubuntu_utils import ensure_base_env, get_job
|
||||
|
||||
|
@ -94,7 +95,7 @@ def main():
|
|||
if install_mmdeploy(work_dir, ort_dir) != 0:
|
||||
return -1
|
||||
|
||||
if os.path.exists('~/mmdeploy.env'):
|
||||
if os.path.exists(Path('~/mmdeploy.env').expanduser()):
|
||||
print('Please source ~/mmdeploy.env to setup your env !')
|
||||
os.system('cat ~/mmdeploy.env')
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
import os
|
||||
import sys
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
from ubuntu_utils import cmd_result, ensure_base_env, get_job
|
||||
|
||||
|
@ -65,7 +66,7 @@ def install_pplnn(dep_dir, build_cuda):
|
|||
|
||||
os.system('cd python/package && ./build.sh')
|
||||
os.system(
|
||||
'cd /tmp/pyppl-package/dist && python3 -m pip install pyppl*.whl --force-reinstall' # noqa: E501
|
||||
'cd /tmp/pyppl-package/dist && python3 -m pip install pyppl*.whl --force-reinstall --user' # noqa: E501
|
||||
)
|
||||
|
||||
pplnn_cmake_dir = os.path.join(pplnn_dir,
|
||||
|
@ -150,7 +151,7 @@ def main():
|
|||
build_cuda) != 0:
|
||||
return -1
|
||||
|
||||
if os.path.exists('~/mmdeploy.env'):
|
||||
if os.path.exists(Path('~/mmdeploy.env').expanduser()):
|
||||
print('Please source ~/mmdeploy.env to setup your env !')
|
||||
os.system('cat ~/mmdeploy.env')
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
import os
|
||||
import sys
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
from ubuntu_utils import (cmd_result, cu_version_name, ensure_base_env,
|
||||
get_job, pytorch_version)
|
||||
|
@ -118,7 +119,7 @@ def main():
|
|||
if install_mmdeploy(work_dir, libtorch_dir) != 0:
|
||||
return -1
|
||||
|
||||
if os.path.exists('~/mmdeploy.env'):
|
||||
if os.path.exists(Path('~/mmdeploy.env').expanduser()):
|
||||
print('Please source ~/mmdeploy.env to setup your env !')
|
||||
os.system('cat ~/mmdeploy.env')
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ build_ocv() {
|
|||
fi
|
||||
cd opencv/platforms/linux/cross_build_aarch64
|
||||
rm -rf CMakeCache.txt
|
||||
cmake ../../.. -DCMAKE_INSTALL_PREFIX=/tmp/ocv-aarch64 -DCMAKE_TOOLCHAIN_FILE=../aarch64-gnu.toolchain.cmake
|
||||
cmake ../../.. -DBUILD_TIFF=ON -DCMAKE_INSTALL_PREFIX=/tmp/ocv-aarch64 -DCMAKE_TOOLCHAIN_FILE=../aarch64-gnu.toolchain.cmake
|
||||
good_nproc
|
||||
jobs=$?
|
||||
make -j${jobs}
|
||||
|
|
|
@ -60,7 +60,7 @@ build_ocv_arm_gnueabi() {
|
|||
cd opencv/build_arm_gnueabi
|
||||
rm -rf CMakeCache.txt
|
||||
cmake .. -DCMAKE_INSTALL_PREFIX=install -DCMAKE_TOOLCHAIN_FILE=../platforms/linux/arm-gnueabi.toolchain.cmake \
|
||||
-DBUILD_PERF_TESTS=OFF -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Release
|
||||
-DBUILD_TIFF=ON -DBUILD_PERF_TESTS=OFF -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Release
|
||||
good_nproc
|
||||
jobs=$?
|
||||
make -j${jobs} && make install
|
||||
|
|
Loading…
Reference in New Issue