From 70ccf3851018fc67303c57b34d068fcce3527c3a Mon Sep 17 00:00:00 2001 From: Bai Yifan Date: Mon, 30 Sep 2019 19:16:24 +0800 Subject: [PATCH] fix scripts and docs (#3465) --- .../classification/distillation/README.md | 2 + PaddleSlim/classification/distillation/run.sh | 34 +-------- PaddleSlim/classification/pruning/README.md | 2 + PaddleSlim/classification/pruning/run.sh | 53 ++++++++++--- .../classification/quantization/README.md | 2 + PaddleSlim/classification/quantization/run.sh | 76 +++++++++++++------ 6 files changed, 105 insertions(+), 64 deletions(-) diff --git a/PaddleSlim/classification/distillation/README.md b/PaddleSlim/classification/distillation/README.md index f8b12a2b..a9ee6f3d 100755 --- a/PaddleSlim/classification/distillation/README.md +++ b/PaddleSlim/classification/distillation/README.md @@ -5,6 +5,8 @@ ## 概述 该示例使用PaddleSlim提供的[蒸馏策略]([https://github.com/PaddlePaddle/models/blob/develop/PaddleSlim/docs/tutorial.md#3-%E8%92%B8%E9%A6%8F](https://github.com/PaddlePaddle/models/blob/develop/PaddleSlim/docs/tutorial.md#3-蒸馏))对分类模型进行知识蒸馏。 +>本文默认使用ILSVRC2012数据集,数据集存放在`models/PaddleSlim/data/`路径下, 可以参考[数据准备](https://github.com/PaddlePaddle/models/tree/develop/PaddleCV/image_classification#数据准备)在执行训练脚本run.sh前配置好您的数据集 + 在阅读该示例前,建议您先了解以下内容: - [分类模型的常规训练方法](https://github.com/PaddlePaddle/models/tree/develop/PaddleCV/image_classification) diff --git a/PaddleSlim/classification/distillation/run.sh b/PaddleSlim/classification/distillation/run.sh index 248061f0..e9d88f50 100644 --- a/PaddleSlim/classification/distillation/run.sh +++ b/PaddleSlim/classification/distillation/run.sh @@ -2,9 +2,6 @@ # download pretrain model root_url="http://paddle-imagenet-models-name.bj.bcebos.com" -MobileNetV1="MobileNetV1_pretrained.tar" -MobileNetV2="MobileNetV2_pretrained.tar" -ResNet34="ResNet34_pretrained.tar" ResNet50="ResNet50_pretrained.tar" pretrain_dir='../pretrain' @@ -14,15 +11,6 @@ fi cd ${pretrain_dir} -if [ ! -f ${MobileNetV2} ]; then - wget ${root_url}/${MobileNetV2} - tar xf ${MobileNetV2} -fi - -if [ ! -f ${ResNet34} ]; then - wget ${root_url}/${ResNet34} - tar xf ${ResNet34} -fi if [ ! -f ${ResNet50} ]; then wget ${root_url}/${ResNet50} tar xf ${ResNet50} @@ -62,7 +50,7 @@ for files in $(ls res50_*) done cd - -# for mobilenet_v2 distillation +## for mobilenet_v2 distillation #cd ${pretrain_dir}/ResNet50_pretrained #for files in $(ls res50_*) # do mv $files ${files#*_} @@ -86,7 +74,7 @@ cd - #done #cd - -# for resnet34 distillation +## for resnet34 distillation #cd ${pretrain_dir}/ResNet50_pretrained #for files in $(ls res50_*) # do mv $files ${files#*_} @@ -96,16 +84,7 @@ cd - #done #cd - # -#cd ${pretrain_dir}/ResNet34_pretrained -#for files in $(ls res34_*) -# do mv $files ${files#*_} -#done -#for files in $(ls *) -# do mv $files "res34_"$files -#done -#cd - -# -#python compress.py \ +#python -u compress.py \ #--model "ResNet34" \ #--teacher_model "ResNet50" \ #--teacher_pretrained_model ../pretrain/ResNet50_pretrained \ @@ -118,10 +97,3 @@ cd - # do mv $files ${files#*_} #done #cd - -# -#cd ${pretrain_dir}/ResNet34_pretrained -#for files in $(ls res34_*) -# do mv $files ${files#*_} -#done -#cd - - diff --git a/PaddleSlim/classification/pruning/README.md b/PaddleSlim/classification/pruning/README.md index ad92c3be..e8d29118 100644 --- a/PaddleSlim/classification/pruning/README.md +++ b/PaddleSlim/classification/pruning/README.md @@ -5,6 +5,8 @@ ## 概述 该示例使用PaddleSlim提供的[卷积通道剪裁压缩策略](https://github.com/PaddlePaddle/models/blob/develop/PaddleSlim/docs/tutorial.md#2-%E5%8D%B7%E7%A7%AF%E6%A0%B8%E5%89%AA%E8%A3%81%E5%8E%9F%E7%90%86)对分类模型进行压缩。 +>本文默认使用ILSVRC2012数据集,数据集存放在`models/PaddleSlim/data/`路径下, 可以参考[数据准备](https://github.com/PaddlePaddle/models/tree/develop/PaddleCV/image_classification#数据准备)在执行训练脚本run.sh前配置好您的数据集 + 在阅读该示例前,建议您先了解以下内容: - [分类模型的常规训练方法](https://github.com/PaddlePaddle/models/tree/develop/PaddleCV/image_classification) diff --git a/PaddleSlim/classification/pruning/run.sh b/PaddleSlim/classification/pruning/run.sh index 24cc4ece..9549ea8c 100644 --- a/PaddleSlim/classification/pruning/run.sh +++ b/PaddleSlim/classification/pruning/run.sh @@ -1,32 +1,63 @@ +#!/usr/bin/env bash + export CUDA_VISIBLE_DEVICES=0 -nohup python compress.py \ +# download pretrain model +root_url="http://paddle-imagenet-models-name.bj.bcebos.com" +MobileNetV1="MobileNetV1_pretrained.tar" +MobileNetV2="MobileNetV2_pretrained.tar" +ResNet50="ResNet50_pretrained.tar" +pretrain_dir='../pretrain' + +if [ ! -d ${pretrain_dir} ]; then + mkdir ${pretrain_dir} +fi + +cd ${pretrain_dir} + +if [ ! -f ${MobileNetV1} ]; then + wget ${root_url}/${MobileNetV1} + tar xf ${MobileNetV1} +fi + +if [ ! -f ${MobileNetV2} ]; then + wget ${root_url}/${MobileNetV2} + tar xf ${MobileNetV2} +fi + +if [ ! -f ${ResNet50} ]; then + wget ${root_url}/${ResNet50} + tar xf ${ResNet50} +fi + +cd - + +nohup python -u compress.py \ --model "MobileNet" \ ---use_gpu 0 \ ---batch_size 1 \ +--use_gpu 1 \ +--batch_size 256 \ --pretrained_model ../pretrain/MobileNetV1_pretrained \ --config_file "./configs/mobilenet_v1.yaml" \ > mobilenet_v1.log 2>&1 & tailf mobilenet_v1.log # for compression of mobilenet_v2 -#nohup python compress.py \ +#nohup python -u compress.py \ #--model "MobileNetV2" \ -#--use_gpu 0 \ -#--batch_size 1 \ +#--use_gpu 1 \ +#--batch_size 256 \ #--pretrained_model ../pretrain/MobileNetV2_pretrained \ #--config_file "./configs/mobilenet_v2.yaml" \ #> mobilenet_v2.log 2>&1 & #tailf mobilenet_v2.log -# for compression of resnet50 -#python compress.py \ +## for compression of resnet50 +#python -u compress.py \ #--model "ResNet50" \ -#--use_gpu 0 \ -#--batch_size 1 \ +#--use_gpu 1 \ +#--batch_size 256 \ #--pretrained_model ../pretrain/ResNet50_pretrained \ #--config_file "./configs/resnet50.yaml" \ #> resnet50.log 2>&1 & #tailf resnet50.log - diff --git a/PaddleSlim/classification/quantization/README.md b/PaddleSlim/classification/quantization/README.md index 00208014..a6f19ecf 100644 --- a/PaddleSlim/classification/quantization/README.md +++ b/PaddleSlim/classification/quantization/README.md @@ -5,6 +5,8 @@ ## 概述 该示例使用PaddleSlim提供的[量化压缩策略](https://github.com/PaddlePaddle/models/blob/develop/PaddleSlim/docs/tutorial.md#1-quantization-aware-training%E9%87%8F%E5%8C%96%E4%BB%8B%E7%BB%8D)对分类模型进行压缩。 +>本文默认使用ILSVRC2012数据集,数据集存放在`models/PaddleSlim/data/`路径下, 可以参考[数据准备](https://github.com/PaddlePaddle/models/tree/develop/PaddleCV/image_classification#数据准备)在执行训练脚本run.sh前配置好您的数据集 + 在阅读该示例前,建议您先了解以下内容: - [分类模型的常规训练方法](https://github.com/PaddlePaddle/models/tree/develop/PaddleCV/image_classification) diff --git a/PaddleSlim/classification/quantization/run.sh b/PaddleSlim/classification/quantization/run.sh index 0849973c..adf67f38 100644 --- a/PaddleSlim/classification/quantization/run.sh +++ b/PaddleSlim/classification/quantization/run.sh @@ -1,19 +1,53 @@ #!/usr/bin/env bash -#export CUDA_VISIBLE_DEVICES=0 +# download pretrain model +root_url="http://paddle-imagenet-models-name.bj.bcebos.com" +MobileNetV1="MobileNetV1_pretrained.tar" +MobileNetV2="MobileNetV2_pretrained.tar" +ResNet50="ResNet50_pretrained.tar" +pretrain_dir='../pretrain' -# for quantization for mobilenet_v1 -#python compress.py \ -# --model "MobileNet" \ -# --use_gpu 1 \ -# --batch_size 32 \ -# --pretrained_model ../pretrain/MobileNetV1_pretrained \ -# --config_file "./configs/mobilenet_v1.yaml" \ -#> mobilenet_v1.log 2>&1 & -#tailf mobilenet_v1.log +if [ ! -d ${pretrain_dir} ]; then + mkdir ${pretrain_dir} +fi + +cd ${pretrain_dir} + +if [ ! -f ${MobileNetV1} ]; then + wget ${root_url}/${MobileNetV1} + tar xf ${MobileNetV1} +fi + +if [ ! -f ${MobileNetV2} ]; then + wget ${root_url}/${MobileNetV2} + tar xf ${MobileNetV2} +fi + +if [ ! -f ${ResNet50} ]; then + wget ${root_url}/${ResNet50} + tar xf ${ResNet50} +fi + +cd - + +# enable GC strategy +export FLAGS_fast_eager_deletion_mode=1 +export FLAGS_eager_delete_tensor_gb=0.0 + +export CUDA_VISIBLE_DEVICES=0 -# for quantization of mobilenet_v2 -# python compress.py \ +## for quantization for mobilenet_v1 +python -u compress.py \ + --model "MobileNet" \ + --use_gpu 1 \ + --batch_size 32 \ + --pretrained_model ../pretrain/MobileNetV1_pretrained \ + --config_file "./configs/mobilenet_v1.yaml" \ +> mobilenet_v1.log 2>&1 & +tailf mobilenet_v1.log + +## for quantization of mobilenet_v2 +#python -u compress.py \ # --model "MobileNetV2" \ # --use_gpu 1 \ # --batch_size 32 \ @@ -22,14 +56,12 @@ # > mobilenet_v2.log 2>&1 & #tailf mobilenet_v2.log - # for compression of resnet50 -python compress.py \ - --model "ResNet50" \ - --use_gpu 1 \ - --batch_size 32 \ - --pretrained_model ../pretrain/ResNet50_pretrained \ - --config_file "./configs/resnet50.yaml" \ - > resnet50.log 2>&1 & -tailf resnet50.log - +#python -u compress.py \ +# --model "ResNet50" \ +# --use_gpu 1 \ +# --batch_size 32 \ +# --pretrained_model ../pretrain/ResNet50_pretrained \ +# --config_file "./configs/resnet50.yaml" \ +# > resnet50.log 2>&1 & +#tailf resnet50.log -- GitLab