Skip to content

Commit 44e69a8

Browse files
ceci3wanghaoshuang
andauthored
Update figure in README (PaddlePaddle#1117) (PaddlePaddle#1125)
Co-authored-by: whs <[email protected]>
1 parent d98c773 commit 44e69a8

File tree

17 files changed

+101
-79
lines changed

17 files changed

+101
-79
lines changed

demo/auto_compression/detection/README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
| 模型 | 策略 | 输入尺寸 | mAP<sup>val<br>0.5:0.95 | 预测时延<sup><small>FP32</small><sup><br><sup>(ms) |预测时延<sup><small>FP32</small><sup><br><sup>(ms) | 预测时延<sup><small>INT8</small><sup><br><sup>(ms) | 配置文件 | Inference模型 |
2424
| :-------- |:-------- |:--------: | :---------------------: | :----------------: | :----------------: | :---------------: | :-----------------------------: | :-----------------------------: |
2525
| PP-YOLOE-l | Base模型 | 640*640 | 50.9 | 11.2 | 7.7ms | - | [config](https://github.com/PaddlePaddle/PaddleDetection/blob/develop/configs/ppyoloe/ppyoloe_crn_l_300e_coco.yml) | [Model](https://bj.bcebos.com/v1/paddle-slim-models/detection/ppyoloe_crn_l_300e_coco.tar) |
26-
| PP-YOLOE-l | 量化+蒸馏 | 640*640 | 50.6 | - | - | 6.7ms | [config](https://github.com/PaddlePaddle/PaddleSlim/tree/develop/demo/auto_compression/detection/configs/ppyoloe_l_qat_dist.yaml) | [Model](https://bj.bcebos.com/v1/paddle-slim-models/act/ppyoloe_crn_l_300e_coco_quant.tar) |
26+
| PP-YOLOE-l | 量化+蒸馏 | 640*640 | 50.6 | - | - | 6.7ms | [config](https://github.com/PaddlePaddle/PaddleSlim/tree/develop/demo/auto_compression/detection/configs/ppyoloe_l_qat_dis.yaml) | [Model](https://bj.bcebos.com/v1/paddle-slim-models/act/ppyoloe_crn_l_300e_coco_quant.tar) |
2727

2828
- mAP的指标均在COCO val2017数据集中评测得到。
2929
- PP-YOLOE模型在Tesla V100的GPU环境下测试,测试脚本是[benchmark demo](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.4/deploy/python)
@@ -95,7 +95,8 @@ tar -xf ppyoloe_crn_l_300e_coco.tar
9595

9696
使用run.py脚本得到模型的mAP:
9797
```
98-
python run.py --config_path=./configs/ppyoloe_l_qat_dist.yaml --eval=True
98+
export CUDA_VISIBLE_DEVEICES=0
99+
python run.py --config_path=./configs/ppyoloe_l_qat_dis.yaml --eval=True
99100
```
100101

101102
**注意**:TinyPose模型暂不支持精度测试。
@@ -104,7 +105,8 @@ python run.py --config_path=./configs/ppyoloe_l_qat_dist.yaml --eval=True
104105

105106
蒸馏量化自动压缩示例通过run.py脚本启动,会使用接口```paddleslim.auto_compression.AutoCompression```对模型进行自动压缩。配置config文件中模型路径、蒸馏、量化、和训练等部分的参数,配置完成后便可对模型进行量化和蒸馏。具体运行命令为:
106107
```
107-
python run.py --config_path=./configs/ppyoloe_l_qat_dist.yaml --save_dir='./output/'
108+
export CUDA_VISIBLE_DEVEICES=0
109+
python run.py --config_path=./configs/ppyoloe_l_qat_dis.yaml --save_dir='./output/'
108110
```
109111

110112

demo/auto_compression/detection/run.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,16 @@ def gen():
6666
return gen
6767

6868

69-
def eval(compress_config):
69+
def eval(config):
7070

7171
place = paddle.CUDAPlace(0) if FLAGS.devices == 'gpu' else paddle.CPUPlace()
7272
exe = paddle.static.Executor(place)
7373

7474
val_program, feed_target_names, fetch_targets = paddle.fluid.io.load_inference_model(
75-
compress_config["model_dir"],
75+
config["model_dir"],
7676
exe,
77-
model_filename=compress_config["model_filename"],
78-
params_filename=compress_config["params_filename"], )
77+
model_filename=config["model_filename"],
78+
params_filename=config["params_filename"], )
7979
clsid2catid = {v: k for k, v in dataset.catid2clsid.items()}
8080

8181
anno_file = dataset.get_anno()
@@ -85,7 +85,7 @@ def eval(compress_config):
8585
data_all = {k: np.array(v) for k, v in data.items()}
8686
data_input = {}
8787
for k, v in data.items():
88-
if k in compress_config['input_list']:
88+
if k in config['input_list']:
8989
data_input[k] = np.array(v)
9090
outs = exe.run(val_program,
9191
feed=data_input,
@@ -142,13 +142,14 @@ def eval_function(exe, compiled_test_program, test_feed_names, test_fetch_list):
142142

143143

144144
def main():
145-
compress_config, train_config = load_slim_config(FLAGS.config_path)
146-
reader_cfg = load_config(compress_config['reader_config'])
145+
compress_config, train_config, global_config = load_slim_config(
146+
FLAGS.config_path)
147+
reader_cfg = load_config(global_config['reader_config'])
147148

148149
train_loader = create('EvalReader')(reader_cfg['TrainDataset'],
149150
reader_cfg['worker_num'],
150151
return_list=True)
151-
train_loader = reader_wrapper(train_loader, compress_config['input_list'])
152+
train_loader = reader_wrapper(train_loader, global_config['input_list'])
152153

153154
global dataset
154155
dataset = reader_cfg['EvalDataset']
@@ -158,18 +159,18 @@ def main():
158159
return_list=True)
159160

160161
if FLAGS.eval:
161-
eval(compress_config)
162+
eval(global_config)
162163
sys.exit(0)
163164

164-
if 'Evaluation' in compress_config.keys() and compress_config['Evaluation']:
165+
if 'Evaluation' in global_config.keys() and global_config['Evaluation']:
165166
eval_func = eval_function
166167
else:
167168
eval_func = None
168169

169170
ac = AutoCompression(
170-
model_dir=compress_config["model_dir"],
171-
model_filename=compress_config["model_filename"],
172-
params_filename=compress_config["params_filename"],
171+
model_dir=global_config["model_dir"],
172+
model_filename=global_config["model_filename"],
173+
params_filename=global_config["params_filename"],
173174
save_dir=FLAGS.save_dir,
174175
strategy_config=compress_config,
175176
train_config=train_config,

demo/auto_compression/image_classification/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ tar -xf MobileNetV1_infer.tar
6969

7070
```shell
7171
# 单卡启动
72+
export CUDA_VISIBLE_DEVEICES=0
7273
python run.py \
7374
--model_dir='MobileNetV1_infer' \
7475
--model_filename='inference.pdmodel' \
@@ -97,3 +98,4 @@ python -m paddle.distributed.launch run.py \
9798
- [Paddle Lite部署](https://github.com/PaddlePaddle/PaddleSeg/blob/release/2.5/docs/deployment/lite/lite.md)
9899

99100
## 5.FAQ
101+
[1.] 如果遇到报错 ```ValueError: var inputs not in this block``` ,则说明模型中的输入变量的名字不是 ```inputs``` ,可以先用netron可视化查看输入变量的名称,然后修改 ```run.py``` 中的第35行中 ``` yield {"inputs": imgs}``````yield {${input_tensor_name}: imgs}```。一般PaddleClas产出部署模型的输入名字如果不是 ```inputs```,则是 ```x```

demo/auto_compression/image_classification/run.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import sys
3-
sys.path[0] = os.path.join(os.path.dirname("__file__"), os.path.pardir, os.path.pardir)
3+
sys.path[0] = os.path.join(
4+
os.path.dirname("__file__"), os.path.pardir, os.path.pardir)
45
import argparse
56
import functools
67
from functools import partial
@@ -32,7 +33,7 @@ def reader_wrapper(reader):
3233
def gen():
3334
for i, data in enumerate(reader()):
3435
imgs = np.float32([item[0] for item in data])
35-
yield {"x": imgs}
36+
yield {"inputs": imgs}
3637

3738
return gen
3839

demo/auto_compression/image_classification/run.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# 单卡启动
2+
export CUDA_VISIBLE_DEVEICES=0
23
python run.py \
34
--model_dir='MobileNetV1_infer' \
45
--model_filename='inference.pdmodel' \

demo/auto_compression/nlp/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pip install paddleslim
6262
安装paddlenlp:
6363
```shell
6464
pip install paddlenlp
65-
```
65+
```
6666

6767
注:安装PaddleNLP的目的是为了下载PaddleNLP中的数据集和Tokenizer。
6868

@@ -88,6 +88,7 @@ tar -zxvf afqmc.tar
8888
数据集为CLUE,不同任务名称代表CLUE上不同的任务,可选择的任务名称有:afqmc, tnews, iflytek, ocnli, cmnli, cluewsc2020, csl。具体运行命令为
8989
9090
```shell
91+
export CUDA_VISIBLE_DEVEICES=0
9192
python run.py \
9293
--model_type='ppminilm' \
9394
--model_dir='./afqmc/' \
@@ -98,7 +99,7 @@ python run.py \
9899
--batch_size=16 \
99100
--max_seq_length=128 \
100101
--task_name='afqmc' \
101-
--config_path='./configs/afqmc.yaml'
102+
--config_path='./configs/afqmc.yaml'
102103
```
103104

104105
## 4. 压缩配置介绍
@@ -184,4 +185,3 @@ Quantization:
184185
- [Paddle Lite部署](https://github.com/PaddlePaddle/PaddleSeg/blob/release/2.5/docs/deployment/lite/lite.md)
185186
186187
## 6. FAQ
187-

demo/auto_compression/nlp/run.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import sys
3-
sys.path[0] = os.path.join(os.path.dirname("__file__"), os.path.pardir, os.path.pardir)
3+
sys.path[0] = os.path.join(
4+
os.path.dirname("__file__"), os.path.pardir, os.path.pardir)
45
import argparse
56
import functools
67
from functools import partial
@@ -58,7 +59,9 @@ def convert_example(example,
5859
label_list,
5960
max_seq_length=512,
6061
is_test=False):
61-
assert args.dataset in ['glue', 'clue'], "This demo only supports for dataset glue or clue"
62+
assert args.dataset in [
63+
'glue', 'clue'
64+
], "This demo only supports for dataset glue or clue"
6265
"""Convert a glue example into necessary features."""
6366
if args.dataset == 'glue':
6467
if not is_test:
@@ -74,13 +77,14 @@ def convert_example(example,
7477
return example['input_ids'], example['token_type_ids'], label
7578
else:
7679
return example['input_ids'], example['token_type_ids']
77-
78-
else: #if args.dataset == 'clue':
80+
81+
else: #if args.dataset == 'clue':
7982
if not is_test:
8083
# `label_list == None` is for regression task
8184
label_dtype = "int64" if label_list else "float32"
8285
# Get the label
83-
example['label'] = np.array(example["label"], dtype="int64").reshape((-1, 1))
86+
example['label'] = np.array(
87+
example["label"], dtype="int64").reshape((-1, 1))
8488
label = example['label']
8589
# Convert raw text to feature
8690
if 'keyword' in example: # CSL
@@ -91,12 +95,13 @@ def convert_example(example,
9195
'label': example['label']
9296
}
9397
elif 'target' in example: # wsc
94-
text, query, pronoun, query_idx, pronoun_idx = example['text'], example[
95-
'target']['span1_text'], example['target']['span2_text'], example[
96-
'target']['span1_index'], example['target']['span2_index']
98+
text, query, pronoun, query_idx, pronoun_idx = example[
99+
'text'], example['target']['span1_text'], example['target'][
100+
'span2_text'], example['target']['span1_index'], example[
101+
'target']['span2_index']
97102
text_list = list(text)
98-
assert text[pronoun_idx:(pronoun_idx + len(pronoun)
99-
)] == pronoun, "pronoun: {}".format(pronoun)
103+
assert text[pronoun_idx:(pronoun_idx + len(
104+
pronoun))] == pronoun, "pronoun: {}".format(pronoun)
100105
assert text[query_idx:(query_idx + len(query)
101106
)] == query, "query: {}".format(query)
102107
if pronoun_idx > query_idx:
@@ -125,8 +130,6 @@ def convert_example(example,
125130
else:
126131
return example['input_ids'], example['token_type_ids']
127132

128-
129-
130133

131134
def create_data_holder(task_name):
132135
"""
@@ -148,7 +151,7 @@ def reader():
148151
# Create the tokenizer and dataset
149152
if args.model_type == 'bert':
150153
tokenizer = BertTokenizer.from_pretrained(args.model_dir)
151-
else: # ppminilm
154+
else: # ppminilm
152155
tokenizer = PPMiniLMTokenizer.from_pretrained(args.model_dir)
153156
train_ds, dev_ds = load_dataset(
154157
args.dataset, args.task_name, splits=('train', 'dev'))
@@ -239,7 +242,7 @@ def apply_decay_param_fun(name):
239242
print_arguments(args)
240243
paddle.enable_static()
241244

242-
compress_config, train_config = load_config(args.config_path)
245+
compress_config, train_config, _ = load_config(args.config_path)
243246
if train_config is not None and 'optim_args' in train_config:
244247
train_config['optim_args'][
245248
'apply_decay_param_fun'] = apply_decay_param_fun
@@ -256,8 +259,8 @@ def apply_decay_param_fun(name):
256259
strategy_config=compress_config,
257260
train_config=train_config,
258261
train_dataloader=train_dataloader,
259-
eval_callback=eval_function
260-
if compress_config is None or 'HyperParameterOptimization' not in compress_config else
262+
eval_callback=eval_function if compress_config is None or
263+
'HyperParameterOptimization' not in compress_config else
261264
eval_dataloader,
262265
eval_dataloader=eval_dataloader)
263266

demo/auto_compression/semantic_segmentation/README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ pip install paddleseg
7474
- 如果想快速体验,可直接下载PP-HumanSeg-Lite 的预测模型:
7575

7676
```shell
77-
wegt https://paddleseg.bj.bcebos.com/dygraph/ppseg/ppseg_lite_portrait_398x224_with_softmax.tar.gz
77+
wget https://paddleseg.bj.bcebos.com/dygraph/ppseg/ppseg_lite_portrait_398x224_with_softmax.tar.gz
7878
tar -xzf ppseg_lite_portrait_398x224_with_softmax.tar.gz
7979
```
8080

@@ -87,16 +87,18 @@ tar -xzf ppseg_lite_portrait_398x224_with_softmax.tar.gz
8787
当只设置训练参数,并传入``deploy_hardware``字段时,将自动搜索压缩策略进行压缩。以骁龙710(SD710)为部署硬件,进行自动压缩的运行命令如下:
8888

8989
```shell
90+
export CUDA_VISIBLE_DEVICES=0
9091
python run.py \
9192
--model_dir='./ppseg_lite_portrait_398x224_with_softmax' \
9293
--model_filename='model.pdmodel' \
9394
--params_filename='model.pdiparams' \
9495
--save_dir='./save_model' \
95-
--config_path='configs/pp_humanseg_auto.yaml'
96+
--config_path='configs/pp_humanseg_auto.yaml' \
9697
--deploy_hardware='SD710'
9798
```
9899
- 自行配置稀疏参数进行非结构化稀疏和蒸馏训练,配置参数含义详见[自动压缩超参文档](https://github.com/PaddlePaddle/PaddleSlim/blob/27dafe1c722476f1b16879f7045e9215b6f37559/demo/auto_compression/hyperparameter_tutorial.md)。具体命令如下所示:
99100
```shell
101+
export CUDA_VISIBLE_DEVICES=0
100102
python run.py \
101103
--model_dir='./ppseg_lite_portrait_398x224_with_softmax' \
102104
--model_filename='model.pdmodel' \
@@ -107,6 +109,7 @@ python run.py \
107109

108110
- 自行配置量化参数进行量化和蒸馏训练,配置参数含义详见[自动压缩超参文档](https://github.com/PaddlePaddle/PaddleSlim/blob/27dafe1c722476f1b16879f7045e9215b6f37559/demo/auto_compression/hyperparameter_tutorial.md)。具体命令如下所示:
109111
```shell
112+
export CUDA_VISIBLE_DEVICES=0
110113
python run.py \
111114
--model_dir='./ppseg_lite_portrait_398x224_with_softmax' \
112115
--model_filename='model.pdmodel' \
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Global:
2-
reader_config: configs/pp_humanseg_lite.yml
2+
reader_config: configs/pp_humanseg_lite.yaml
33

44
TrainConfig:
55
epochs: 14
@@ -8,4 +8,4 @@ TrainConfig:
88
optim_args:
99
weight_decay: 0.0005
1010
optimizer: SGD
11-
11+

demo/auto_compression/semantic_segmentation/configs/pp_humanseg_lite.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ train_dataset:
2525
val_dataset:
2626
type: Dataset
2727
dataset_root: data/humanseg
28-
train_path: data/humanseg/val.txt
28+
val_path: data/humanseg/val.txt
2929
num_classes: 2
3030
transforms:
3131
- type: PaddingByAspectRatio

0 commit comments

Comments
 (0)