Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleClas
提交
4b0dd292
P
PaddleClas
项目概览
PaddlePaddle
/
PaddleClas
大约 1 年 前同步成功
通知
115
Star
4999
Fork
1114
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
19
列表
看板
标记
里程碑
合并请求
6
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleClas
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
19
Issue
19
列表
看板
标记
里程碑
合并请求
6
合并请求
6
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
4b0dd292
编写于
6月 28, 2022
作者:
H
HydrogenSulfate
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
debug
上级
e8fc16d7
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
278 addition
and
157 deletion
+278
-157
ppcls/configs/ImageNet/PPHGNet/PPHGNet_small_pact.yaml
ppcls/configs/ImageNet/PPHGNet/PPHGNet_small_pact.yaml
+0
-157
test_tipc/docs/test_train_ptq_inference_python.md
test_tipc/docs/test_train_ptq_inference_python.md
+105
-0
test_tipc/test_ptq_inference_python.sh
test_tipc/test_ptq_inference_python.sh
+173
-0
未找到文件。
ppcls/configs/ImageNet/PPHGNet/PPHGNet_small_pact.yaml
已删除
100644 → 0
浏览文件 @
e8fc16d7
# global configs
Global
:
checkpoints
:
null
pretrained_model
:
null
output_dir
:
./output/
device
:
gpu
save_interval
:
1
eval_during_train
:
True
eval_interval
:
1
epochs
:
600
print_batch_step
:
10
use_visualdl
:
False
# used for static mode and model export
image_shape
:
[
3
,
224
,
224
]
save_inference_dir
:
./inference
# training model under @to_static
to_static
:
False
use_dali
:
False
# model architecture
Arch
:
name
:
PPHGNet_small
class_num
:
1000
# loss function config for traing/eval process
Loss
:
Train
:
-
CELoss
:
weight
:
1.0
epsilon
:
0.1
Eval
:
-
CELoss
:
weight
:
1.0
Optimizer
:
name
:
Momentum
momentum
:
0.9
lr
:
name
:
Cosine
learning_rate
:
0.5
warmup_epoch
:
5
regularizer
:
name
:
'
L2'
coeff
:
0.00004
# data loader for train and eval
DataLoader
:
Train
:
dataset
:
name
:
ImageNetDataset
image_root
:
./dataset/ILSVRC2012/
cls_label_path
:
./dataset/ILSVRC2012/train_list.txt
transform_ops
:
-
DecodeImage
:
to_rgb
:
True
channel_first
:
False
-
RandCropImage
:
size
:
224
interpolation
:
bicubic
backend
:
pil
-
RandFlipImage
:
flip_code
:
1
-
TimmAutoAugment
:
config_str
:
rand-m7-mstd0.5-inc1
interpolation
:
bicubic
img_size
:
224
-
NormalizeImage
:
scale
:
1.0/255.0
mean
:
[
0.485
,
0.456
,
0.406
]
std
:
[
0.229
,
0.224
,
0.225
]
order
:
'
'
-
RandomErasing
:
EPSILON
:
0.25
sl
:
0.02
sh
:
1.0/3.0
r1
:
0.3
attempt
:
10
use_log_aspect
:
True
mode
:
pixel
batch_transform_ops
:
-
OpSampler
:
MixupOperator
:
alpha
:
0.2
prob
:
0.5
CutmixOperator
:
alpha
:
1.0
prob
:
0.5
sampler
:
name
:
DistributedBatchSampler
batch_size
:
128
drop_last
:
False
shuffle
:
True
loader
:
num_workers
:
16
use_shared_memory
:
True
Eval
:
dataset
:
name
:
ImageNetDataset
image_root
:
./dataset/ILSVRC2012/
cls_label_path
:
./dataset/ILSVRC2012/val_list.txt
transform_ops
:
-
DecodeImage
:
to_rgb
:
True
channel_first
:
False
-
ResizeImage
:
resize_short
:
236
interpolation
:
bicubic
backend
:
pil
-
CropImage
:
size
:
224
-
NormalizeImage
:
scale
:
1.0/255.0
mean
:
[
0.485
,
0.456
,
0.406
]
std
:
[
0.229
,
0.224
,
0.225
]
order
:
'
'
sampler
:
name
:
DistributedBatchSampler
batch_size
:
128
drop_last
:
False
shuffle
:
False
loader
:
num_workers
:
16
use_shared_memory
:
True
Infer
:
infer_imgs
:
docs/images/inference_deployment/whl_demo.jpg
batch_size
:
10
transforms
:
-
DecodeImage
:
to_rgb
:
True
channel_first
:
False
-
ResizeImage
:
resize_short
:
236
-
CropImage
:
size
:
224
-
NormalizeImage
:
scale
:
1.0/255.0
mean
:
[
0.485
,
0.456
,
0.406
]
std
:
[
0.229
,
0.224
,
0.225
]
order
:
'
'
-
ToCHWImage
:
PostProcess
:
name
:
Topk
topk
:
5
class_id_map_file
:
ppcls/utils/imagenet1k_label_list.txt
Metric
:
Train
:
-
TopkAcc
:
topk
:
[
1
,
5
]
Eval
:
-
TopkAcc
:
topk
:
[
1
,
5
]
test_tipc/docs/test_train_ptq_inference_python.md
0 → 100644
浏览文件 @
4b0dd292
# Linux GPU/CPU KL离线量化推理测试
Linux GPU/CPU KL离线量化推理测试的主程序为
`test_ptq_inference_python.sh`
,可以测试基于Python的模型KL离线量化推理等基本功能。
## 1. 测试结论汇总
-
KL离线量化:
| 算法名称 | 模型名称 | CPU |
| :-------------: | :-------------------------------------: | :----------: |
| MobileNetV3 | MobileNetV3_large_x1_0 | KL离线量化 |
| PP-ShiTu | GeneralRecognition_PPLCNet_x2_5 | KL离线量化 |
| PPHGNet | PPHGNet_small | KL离线量化 |
| PPHGNet | PPHGNet_tiny | KL离线量化 |
| PPLCNet | PPLCNet_x0_25 | KL离线量化 |
| PPLCNet | PPLCNet_x0_35 | KL离线量化 |
| PPLCNet | PPLCNet_x0_5 | KL离线量化 |
| PPLCNet | PPLCNet_x0_75 | KL离线量化 |
| PPLCNet | PPLCNet_x1_0 | KL离线量化 |
| PPLCNet | PPLCNet_x1_5 | KL离线量化 |
| PPLCNet | PPLCNet_x2_0 | KL离线量化 |
| PPLCNet | PPLCNet_x2_5 | KL离线量化 |
| PPLCNetV2 | PPLCNetV2_base | KL离线量化 |
| ResNet | ResNet50 | KL离线量化 |
| ResNet | ResNet50_vd | KL离线量化 |
| SwinTransformer | SwinTransformer_tiny_patch4_window7_224 | KL离线量化 |
-
推理相关:
| 算法名称 | 模型名称 | CPU |
| :-------------: | :-------------------------------------: | :----------: |
| MobileNetV3 | MobileNetV3_large_x1_0 | KL离线量化 |
| PP-ShiTu | GeneralRecognition_PPLCNet_x2_5 | KL离线量化 |
| PPHGNet | PPHGNet_small | KL离线量化 |
| PPHGNet | PPHGNet_tiny | KL离线量化 |
| PPLCNet | PPLCNet_x0_25 | KL离线量化 |
| PPLCNet | PPLCNet_x0_35 | KL离线量化 |
| PPLCNet | PPLCNet_x0_5 | KL离线量化 |
| PPLCNet | PPLCNet_x0_75 | KL离线量化 |
| PPLCNet | PPLCNet_x1_0 | KL离线量化 |
| PPLCNet | PPLCNet_x1_5 | KL离线量化 |
| PPLCNet | PPLCNet_x2_0 | KL离线量化 |
| PPLCNet | PPLCNet_x2_5 | KL离线量化 |
| PPLCNetV2 | PPLCNetV2_base | KL离线量化 |
| ResNet | ResNet50 | KL离线量化 |
| ResNet | ResNet50_vd | KL离线量化 |
| SwinTransformer | SwinTransformer_tiny_patch4_window7_224 | KL离线量化 |
## 2. 测试流程
一下测试流程以 MobileNetV3_large_x1_0 模型为例。
### 2.1 准备环境
-
安装PaddlePaddle:如果您已经安装了2.2或者以上版本的paddlepaddle,那么无需运行下面的命令安装paddlepaddle。
```
bash
# 需要安装2.2及以上版本的Paddle
# 安装GPU版本的Paddle
python3.7
-m
pip
install
paddlepaddle-gpu
==
2.2.0
# 安装CPU版本的Paddle
python3.7
-m
pip
install
paddlepaddle
==
2.2.0
```
-
安装PaddleSlim
```
bash
python3.7
-m
pip
install
paddleslim
==
2.2.0
```
-
安装依赖
```
bash
python3.7
-m
pip
install
-r
requirements.txt
-i
https://pypi.tuna.tsinghua.edu.cn/simple
```
-
安装AutoLog(规范化日志输出工具)
```
bash
python3.7
-m
pip
install
https://paddleocr.bj.bcebos.com/libs/auto_log-1.2.0-py3-none-any.whl
```
### 2.2 准备数据和模型
```
bash
bash test_tipc/prepare.sh test_tipc/config/MobileNetV3/MobileNetV3_large_x1_0_train_ptq_infer_python.txt whole_infer
```
离线量化的操作流程,可参考
[
文档
](
../../deploy/slim/README.md
)
。
### 2.3 功能测试
以
`MobileNetV3_large_x1_0`
的
`Linux GPU/CPU KL离线量化训练推理测试`
为例,命令如下所示。
```
bash
bash test_tipc/test_ptq_inference_python.sh test_tipc/config/MobileNetV3/MobileNetV3_large_x1_0_train_ptq_infer_python.txt whole_infer
```
输出结果如下,表示命令运行成功。
```
log
Run successfully with command - MobileNetV3_large_x1_0 - python3.7 deploy/slim/quant_post_static.py -c ppcls/configs/ImageNet/MobileNetV3/MobileNetV3_large_x1_0.yaml -o Global.save_inference_dir=./MobileNetV3_large_x1_0_infer!
Run successfully with command - MobileNetV3_large_x1_0 - python3.7 python/predict_cls.py -c configs/inference_cls.yaml -o Global.use_gpu=True -o Global.use_tensorrt=False -o Global.use_fp16=False -o Global.inference_model_dir=.././MobileNetV3_large_x1_0_infer//quant_post_static_model -o Global.batch_size=1 -o Global.infer_imgs=../deploy/images/ImageNet/ILSVRC2012_val_00000010.jpeg -o Global.benchmark=False > .././test_tipc/output/MobileNetV3_large_x1_0/whole_infer/infer_gpu_usetrt_False_precision_False_batchsize_1.log 2>&1 !
Run successfully with command - MobileNetV3_large_x1_0 - python3.7 python/predict_cls.py -c configs/inference_cls.yaml -o Global.use_gpu=False -o Global.enable_mkldnn=False -o Global.cpu_num_threads=1 -o Global.inference_model_dir=.././MobileNetV3_large_x1_0_infer//quant_post_static_model -o Global.batch_size=1 -o Global.infer_imgs=../deploy/images/ImageNet/ILSVRC2012_val_00000010.jpeg -o Global.benchmark=False > .././test_tipc/output/MobileNetV3_large_x1_0/whole_infer/infer_cpu_usemkldnn_False_threads_1_batchsize_1.log 2>&1 !
```
同时,测试过程中的日志保存在
`PaddleClas/test_tipc/output/MobileNetV3_large_x1_0/whole_infer`
下。
如果运行失败,也会在终端中输出运行失败的日志信息以及对应的运行命令。可以基于该命令,分析运行失败的原因。
test_tipc/test_ptq_inference_python.sh
0 → 100644
浏览文件 @
4b0dd292
#!/bin/bash
FILENAME
=
$1
source
test_tipc/common_func.sh
# MODE be one of ['whole_infer']
MODE
=
$2
dataline
=
$(
cat
${
FILENAME
}
)
# parser params
IFS
=
$'
\n
'
lines
=(
${
dataline
}
)
# The training params
model_name
=
$(
func_parser_value
"
${
lines
[1]
}
"
)
python
=
$(
func_parser_value
"
${
lines
[2]
}
"
)
gpu_list
=
$(
func_parser_value
"
${
lines
[3]
}
"
)
train_use_gpu_key
=
$(
func_parser_key
"
${
lines
[4]
}
"
)
train_use_gpu_value
=
$(
func_parser_value
"
${
lines
[4]
}
"
)
autocast_list
=
$(
func_parser_value
"
${
lines
[5]
}
"
)
autocast_key
=
$(
func_parser_key
"
${
lines
[5]
}
"
)
epoch_key
=
$(
func_parser_key
"
${
lines
[6]
}
"
)
epoch_num
=
$(
func_parser_params
"
${
lines
[6]
}
"
)
save_model_key
=
$(
func_parser_key
"
${
lines
[7]
}
"
)
train_batch_key
=
$(
func_parser_key
"
${
lines
[8]
}
"
)
train_batch_value
=
$(
func_parser_value
"
${
lines
[8]
}
"
)
pretrain_model_key
=
$(
func_parser_key
"
${
lines
[9]
}
"
)
pretrain_model_value
=
$(
func_parser_value
"
${
lines
[9]
}
"
)
train_model_name
=
$(
func_parser_value
"
${
lines
[10]
}
"
)
train_infer_img_dir
=
$(
func_parser_value
"
${
lines
[11]
}
"
)
train_param_key1
=
$(
func_parser_key
"
${
lines
[12]
}
"
)
train_param_value1
=
$(
func_parser_value
"
${
lines
[12]
}
"
)
trainer_list
=
$(
func_parser_value
"
${
lines
[14]
}
"
)
trainer_norm
=
$(
func_parser_key
"
${
lines
[15]
}
"
)
norm_trainer
=
$(
func_parser_value
"
${
lines
[15]
}
"
)
pact_key
=
$(
func_parser_key
"
${
lines
[16]
}
"
)
pact_trainer
=
$(
func_parser_value
"
${
lines
[16]
}
"
)
fpgm_key
=
$(
func_parser_key
"
${
lines
[17]
}
"
)
fpgm_trainer
=
$(
func_parser_value
"
${
lines
[17]
}
"
)
distill_key
=
$(
func_parser_key
"
${
lines
[18]
}
"
)
distill_trainer
=
$(
func_parser_value
"
${
lines
[18]
}
"
)
to_static_key
=
$(
func_parser_key
"
${
lines
[19]
}
"
)
to_static_trainer
=
$(
func_parser_value
"
${
lines
[19]
}
"
)
trainer_key2
=
$(
func_parser_key
"
${
lines
[20]
}
"
)
trainer_value2
=
$(
func_parser_value
"
${
lines
[20]
}
"
)
eval_py
=
$(
func_parser_value
"
${
lines
[23]
}
"
)
eval_key1
=
$(
func_parser_key
"
${
lines
[24]
}
"
)
eval_value1
=
$(
func_parser_value
"
${
lines
[24]
}
"
)
save_infer_key
=
$(
func_parser_key
"
${
lines
[27]
}
"
)
export_weight
=
$(
func_parser_key
"
${
lines
[28]
}
"
)
norm_export
=
$(
func_parser_value
"
${
lines
[29]
}
"
)
pact_export
=
$(
func_parser_value
"
${
lines
[30]
}
"
)
fpgm_export
=
$(
func_parser_value
"
${
lines
[31]
}
"
)
distill_export
=
$(
func_parser_value
"
${
lines
[32]
}
"
)
kl_quant_cmd_key
=
$(
func_parser_key
"
${
lines
[33]
}
"
)
kl_quant_cmd_value
=
$(
func_parser_value
"
${
lines
[33]
}
"
)
export_key2
=
$(
func_parser_key
"
${
lines
[34]
}
"
)
export_value2
=
$(
func_parser_value
"
${
lines
[34]
}
"
)
# parser inference model
infer_model_dir_list
=
$(
func_parser_value
"
${
lines
[36]
}
"
)
infer_export_flag
=
$(
func_parser_value
"
${
lines
[37]
}
"
)
infer_is_quant
=
$(
func_parser_value
"
${
lines
[38]
}
"
)
# parser inference
inference_py
=
$(
func_parser_value
"
${
lines
[39]
}
"
)
use_gpu_key
=
$(
func_parser_key
"
${
lines
[40]
}
"
)
use_gpu_list
=
$(
func_parser_value
"
${
lines
[40]
}
"
)
use_mkldnn_key
=
$(
func_parser_key
"
${
lines
[41]
}
"
)
use_mkldnn_list
=
$(
func_parser_value
"
${
lines
[41]
}
"
)
cpu_threads_key
=
$(
func_parser_key
"
${
lines
[42]
}
"
)
cpu_threads_list
=
$(
func_parser_value
"
${
lines
[42]
}
"
)
batch_size_key
=
$(
func_parser_key
"
${
lines
[43]
}
"
)
batch_size_list
=
$(
func_parser_value
"
${
lines
[43]
}
"
)
use_trt_key
=
$(
func_parser_key
"
${
lines
[44]
}
"
)
use_trt_list
=
$(
func_parser_value
"
${
lines
[44]
}
"
)
precision_key
=
$(
func_parser_key
"
${
lines
[45]
}
"
)
precision_list
=
$(
func_parser_value
"
${
lines
[45]
}
"
)
infer_model_key
=
$(
func_parser_key
"
${
lines
[46]
}
"
)
image_dir_key
=
$(
func_parser_key
"
${
lines
[47]
}
"
)
infer_img_dir
=
$(
func_parser_value
"
${
lines
[47]
}
"
)
save_log_key
=
$(
func_parser_key
"
${
lines
[48]
}
"
)
benchmark_key
=
$(
func_parser_key
"
${
lines
[49]
}
"
)
benchmark_value
=
$(
func_parser_value
"
${
lines
[49]
}
"
)
infer_key1
=
$(
func_parser_key
"
${
lines
[50]
}
"
)
infer_value1
=
$(
func_parser_value
"
${
lines
[50]
}
"
)
if
[
!
$epoch_num
]
;
then
epoch_num
=
2
fi
if
[[
$MODE
=
'benchmark_train'
]]
;
then
epoch_num
=
1
fi
LOG_PATH
=
"./test_tipc/output/
${
model_name
}
/
${
MODE
}
"
mkdir
-p
${
LOG_PATH
}
status_log
=
"
${
LOG_PATH
}
/results_python.log"
function
func_inference
()
{
IFS
=
'|'
_python
=
$1
_script
=
$2
_model_dir
=
$3
_log_path
=
$4
_img_dir
=
$5
_flag_quant
=
$6
# inference
for
use_gpu
in
${
use_gpu_list
[*]
}
;
do
if
[
${
use_gpu
}
=
"False"
]
||
[
${
use_gpu
}
=
"cpu"
]
;
then
for
use_mkldnn
in
${
use_mkldnn_list
[*]
}
;
do
for
threads
in
${
cpu_threads_list
[*]
}
;
do
for
batch_size
in
${
batch_size_list
[*]
}
;
do
_save_log_path
=
"
${
_log_path
}
/infer_cpu_usemkldnn_
${
use_mkldnn
}
_threads_
${
threads
}
_batchsize_
${
batch_size
}
.log"
set_infer_data
=
$(
func_set_params
"
${
image_dir_key
}
"
"
${
_img_dir
}
"
)
set_benchmark
=
$(
func_set_params
"
${
benchmark_key
}
"
"
${
benchmark_value
}
"
)
set_batchsize
=
$(
func_set_params
"
${
batch_size_key
}
"
"
${
batch_size
}
"
)
set_cpu_threads
=
$(
func_set_params
"
${
cpu_threads_key
}
"
"
${
threads
}
"
)
set_model_dir
=
$(
func_set_params
"
${
infer_model_key
}
"
"
${
_model_dir
}
"
)
set_infer_params1
=
$(
func_set_params
"
${
infer_key1
}
"
"
${
infer_value1
}
"
)
command
=
"
${
_python
}
${
_script
}
${
use_gpu_key
}
=
${
use_gpu
}
${
use_mkldnn_key
}
=
${
use_mkldnn
}
${
set_cpu_threads
}
${
set_model_dir
}
${
set_batchsize
}
${
set_infer_data
}
${
set_benchmark
}
${
set_infer_params1
}
>
${
_save_log_path
}
2>&1 "
eval
$command
last_status
=
${
PIPESTATUS
[0]
}
eval
"cat
${
_save_log_path
}
"
status_check
$last_status
"
${
command
}
"
"../
${
status_log
}
"
"
${
model_name
}
"
done
done
done
elif
[
${
use_gpu
}
=
"True"
]
||
[
${
use_gpu
}
=
"gpu"
]
;
then
for
use_trt
in
${
use_trt_list
[*]
}
;
do
for
precision
in
${
precision_list
[*]
}
;
do
if
[
${
precision
}
=
"True"
]
&&
[
${
use_trt
}
=
"False"
]
;
then
continue
fi
for
batch_size
in
${
batch_size_list
[*]
}
;
do
_save_log_path
=
"
${
_log_path
}
/infer_gpu_usetrt_
${
use_trt
}
_precision_
${
precision
}
_batchsize_
${
batch_size
}
.log"
set_infer_data
=
$(
func_set_params
"
${
image_dir_key
}
"
"
${
_img_dir
}
"
)
set_benchmark
=
$(
func_set_params
"
${
benchmark_key
}
"
"
${
benchmark_value
}
"
)
set_batchsize
=
$(
func_set_params
"
${
batch_size_key
}
"
"
${
batch_size
}
"
)
set_tensorrt
=
$(
func_set_params
"
${
use_trt_key
}
"
"
${
use_trt
}
"
)
set_precision
=
$(
func_set_params
"
${
precision_key
}
"
"
${
precision
}
"
)
set_model_dir
=
$(
func_set_params
"
${
infer_model_key
}
"
"
${
_model_dir
}
"
)
command
=
"
${
_python
}
${
_script
}
${
use_gpu_key
}
=
${
use_gpu
}
${
set_tensorrt
}
${
set_precision
}
${
set_model_dir
}
${
set_batchsize
}
${
set_infer_data
}
${
set_benchmark
}
>
${
_save_log_path
}
2>&1 "
eval
$command
last_status
=
${
PIPESTATUS
[0]
}
eval
"cat
${
_save_log_path
}
"
status_check
$last_status
"
${
command
}
"
"../
${
status_log
}
"
"
${
model_name
}
"
done
done
done
else
echo
"Does not support hardware other than CPU and GPU Currently!"
fi
done
}
# for kl_quant
if
[
${
kl_quant_cmd_value
}
!=
"null"
]
&&
[
${
kl_quant_cmd_value
}
!=
"False"
]
;
then
echo
"kl_quant"
command
=
"
${
python
}
${
kl_quant_cmd_value
}
"
echo
${
command
}
eval
$command
last_status
=
${
PIPESTATUS
[0]
}
status_check
$last_status
"
${
command
}
"
"
${
status_log
}
"
"
${
model_name
}
"
cd
${
infer_model_dir_list
}
/quant_post_static_model
ln
-s
__model__ inference.pdmodel
ln
-s
__params__ inference.pdiparams
cd
../../deploy
is_quant
=
True
func_inference
"
${
python
}
"
"
${
inference_py
}
"
"../
${
infer_model_dir_list
}
/quant_post_static_model"
"../
${
LOG_PATH
}
"
"
${
infer_img_dir
}
"
${
is_quant
}
cd
..
fi
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录