diff --git a/demo/auto_compression/hyperparameter_tutorial.md b/demo/auto_compression/hyperparameter_tutorial.md index 8a428ce2a2fef0dd7121e3b18b3dcfd72693a4da..6c632f84f6ce8dc750b697bb6458414d9f4dbf8b 100644 --- a/demo/auto_compression/hyperparameter_tutorial.md +++ b/demo/auto_compression/hyperparameter_tutorial.md @@ -56,7 +56,7 @@ Prune: # pruned_ratio: 裁剪比例 pruned_ratio: 0.25 # prune_params_name: 需要裁剪的参数名字 - prune_params_name: + prune_params_name: - conv1_weights # criterion: 评估一个卷积层内通道重要性所参考的指标 criterion: l1_norm @@ -79,12 +79,12 @@ UnstructurePrune: threshold: 0.001 # gmp_config: 传入额外的训练超参用以指导GMP训练过程 gmp_config: - - stable_iterations: 0 - - pruning_iterations: 4500 # total_iters * 0.4~0.45 - - tunning_iterations: 4500 # total_iters * 0.4~0.45 - - resume_iteration: -1 - - pruning_steps: 100 - - initial_ratio: 0.15 + stable_iterations: 0 + pruning_iterations: 4500 # total_iters * 0.4~0.45 + tunning_iterations: 4500 # total_iters * 0.4~0.45 + resume_iteration: -1 + pruning_steps: 100 + initial_ratio: 0.15 # prune_params_type: 用以指定哪些类型的参数参与稀疏。 prune_params_type: conv1x1_only # local_sparsity: 剪裁比例(ratio)应用的范围 diff --git a/demo/auto_compression/semantic_segmentation/README.md b/demo/auto_compression/semantic_segmentation/README.md index 88b802b2358d1a4bd13f70380b7cfd4592245e84..f8d2507245fa57372ff66ab582f91623e1a537f8 100644 --- a/demo/auto_compression/semantic_segmentation/README.md +++ b/demo/auto_compression/semantic_segmentation/README.md @@ -61,7 +61,7 @@ pip install paddleseg #### 3.2 准备数据集 -开发者可下载开源数据集或自定义语义分割数据集,例如PP-HumanSeg-Lite模型中使用的语义分割数据集[PP-HumanSeg14K](https://github.com/PaddlePaddle/PaddleSeg/blob/release/2.5/contrib/PP-HumanSeg/paper.md#pp-humanseg14k-a-large-scale-teleconferencing-video-dataset)可从官方渠道下载。 +开发者可下载开源数据集 ([AIsegment](https://github.com/aisegmentcn/matting_human_datasets)) 或自定义语义分割数据集,例如PP-HumanSeg-Lite模型中使用的语义分割数据集[PP-HumanSeg14K](https://github.com/PaddlePaddle/PaddleSeg/blob/release/2.5/contrib/PP-HumanSeg/paper.md#pp-humanseg14k-a-large-scale-teleconferencing-video-dataset)可从官方渠道下载。 如果是自定义数据,请参考[PaddleSeg数据准备文档](https://github.com/PaddlePaddle/PaddleSeg/blob/release/2.5/docs/data/marker/marker_cn.md)来检查对齐数据格式即可。 @@ -74,7 +74,7 @@ pip install paddleseg - 如果想快速体验,可直接下载PP-HumanSeg-Lite 的预测模型: ```shell -wget https://paddleseg.bj.bcebos.com/dygraph/ppseg/ppseg_lite_portrait_398x224_with_softmax.tar.gz +wget https://bj.bcebos.com/v1/paddlemodels/PaddleSlim/analysis/ppseg_lite_portrait_398x224_with_softmax.tar.gz tar -xzf ppseg_lite_portrait_398x224_with_softmax.tar.gz ``` @@ -87,6 +87,7 @@ tar -xzf ppseg_lite_portrait_398x224_with_softmax.tar.gz 当只设置训练参数,并传入``deploy_hardware``字段时,将自动搜索压缩策略进行压缩。以骁龙710(SD710)为部署硬件,进行自动压缩的运行命令如下: ```shell +# 单卡启动 export CUDA_VISIBLE_DEVICES=0 python run.py \ --model_dir='./ppseg_lite_portrait_398x224_with_softmax' \ @@ -95,9 +96,20 @@ python run.py \ --save_dir='./save_model' \ --config_path='configs/pp_humanseg_auto.yaml' \ --deploy_hardware='SD710' + +# 多卡启动 +export CUDA_VISIBLE_DEVICES=0,1 +python -m paddle.distributed.launch run.py \ + --model_dir='./ppseg_lite_portrait_398x224_with_softmax' \ + --model_filename='model.pdmodel' \ + --params_filename='model.pdiparams' \ + --save_dir='./save_model' \ + --config_path='configs/pp_humanseg_auto.yaml' + --deploy_hardware='SD710' ``` - 自行配置稀疏参数进行非结构化稀疏和蒸馏训练,配置参数含义详见[自动压缩超参文档](https://github.com/PaddlePaddle/PaddleSlim/blob/27dafe1c722476f1b16879f7045e9215b6f37559/demo/auto_compression/hyperparameter_tutorial.md)。具体命令如下所示: ```shell +# 单卡启动 export CUDA_VISIBLE_DEVICES=0 python run.py \ --model_dir='./ppseg_lite_portrait_398x224_with_softmax' \ @@ -105,10 +117,20 @@ python run.py \ --params_filename='model.pdiparams' \ --save_dir='./save_model' \ --config_path='configs/pp_humanseg_sparse_dis.yaml' + +# 多卡启动 +export CUDA_VISIBLE_DEVICES=0,1 +python -m paddle.distributed.launch run.py \ + --model_dir='./ppseg_lite_portrait_398x224_with_softmax' \ + --model_filename='model.pdmodel' \ + --params_filename='model.pdiparams' \ + --save_dir='./save_model' \ + --config_path='configs/pp_humanseg_sparse_dis.yaml' ``` - 自行配置量化参数进行量化和蒸馏训练,配置参数含义详见[自动压缩超参文档](https://github.com/PaddlePaddle/PaddleSlim/blob/27dafe1c722476f1b16879f7045e9215b6f37559/demo/auto_compression/hyperparameter_tutorial.md)。具体命令如下所示: ```shell +# 单卡启动 export CUDA_VISIBLE_DEVICES=0 python run.py \ --model_dir='./ppseg_lite_portrait_398x224_with_softmax' \ @@ -116,6 +138,15 @@ python run.py \ --params_filename='model.pdiparams' \ --save_dir='./save_model' \ --config_path='configs/pp_humanseg_quant_dis.yaml' + +# 多卡启动 +export CUDA_VISIBLE_DEVICES=0,1 +python -m paddle.distributed.launch run.py \ + --model_dir='./ppseg_lite_portrait_398x224_with_softmax' \ + --model_filename='model.pdmodel' \ + --params_filename='model.pdiparams' \ + --save_dir='./save_model' \ + --config_path='configs/pp_humanseg_quant_dis.yaml' ``` 压缩完成后会在`save_dir`中产出压缩好的预测模型,可直接预测部署。 diff --git a/demo/auto_compression/semantic_segmentation/configs/pp_humanseg_sparse_dis.yaml b/demo/auto_compression/semantic_segmentation/configs/pp_humanseg_sparse_dis.yaml index 59072363e07dcf57c4abe4fe55230a4095b8378d..953d8f30df3aa7f484b086fea139a832001dee08 100644 --- a/demo/auto_compression/semantic_segmentation/configs/pp_humanseg_sparse_dis.yaml +++ b/demo/auto_compression/semantic_segmentation/configs/pp_humanseg_sparse_dis.yaml @@ -27,7 +27,10 @@ UnstructurePrune: TrainConfig: epochs: 14 eval_iter: 400 - learning_rate: 5.0e-03 + learning_rate: + type: PiecewiseDecay + boundaries: [4500] + values: [0.005, 0.0005] optim_args: weight_decay: 0.0005 optimizer: SGD