diff --git a/PaddleCV/PaddleDetection/slim/distillation/README.md b/PaddleCV/PaddleDetection/slim/distillation/README.md index de6a1eef06405626d2e570c9f964e6334b76dd20..88d753bbf3686ec8fd6a9c623607918c70584328 100755 --- a/PaddleCV/PaddleDetection/slim/distillation/README.md +++ b/PaddleCV/PaddleDetection/slim/distillation/README.md @@ -87,6 +87,16 @@ strategies: 如果不需要保存评估模型,可以在定义Compressor对象时,将`save_eval_model`选项设置为False(默认为True)。 +运行命令为: +``` +python ../eval.py \ + --model_path ${checkpoint_path}/${epoch_id}/eval_model/ \ + --model_name __model__ \ + --params_name __params__ \ + -c ../../configs/yolov3_mobilenet_v1_voc.yml \ + -d "../../dataset/voc" +``` + ## 预测 如果在配置文件中设置了`checkpoint_path`,并且在定义Compressor对象时指定了`prune_infer_model`选项,则每个epoch都会 @@ -101,6 +111,16 @@ strategies: 在脚本slim/infer.py中展示了如何使用fluid python API加载使用预测模型进行预测。 +运行命令为: +``` +python ../infer.py \ + --model_path ${checkpoint_path}/${epoch_id}/eval_model/ \ + --model_name __model__ \ + --params_name __params__ \ + -c ../../configs/yolov3_mobilenet_v1_voc.yml \ + --infer_dir ../../demo +``` + ### PaddleLite 该示例中产出的预测(inference)模型可以直接用PaddleLite进行加载使用。 diff --git a/PaddleCV/PaddleDetection/slim/prune/README.md b/PaddleCV/PaddleDetection/slim/prune/README.md index 22ebbd625c63094089c7bcbc483aa3c006dbe724..ee98765843e79086c17f8066497291d2f7ef426e 100644 --- a/PaddleCV/PaddleDetection/slim/prune/README.md +++ b/PaddleCV/PaddleDetection/slim/prune/README.md @@ -30,7 +30,7 @@ from paddle.fluid.framework import IrGraph from paddle.fluid import core graph = IrGraph(core.Graph(train_prog.desc), for_test=True) -marked_nodes = set() +marked_nodes = set() for op in graph.all_op_nodes(): print(op.name()) if op.name().find('conv') > -1: @@ -40,12 +40,12 @@ graph.draw('.', 'forward', marked_nodes) 该示例中MobileNetV1-YoloV3模型结构的可视化结果:MobileNetV1-YoloV3.pdf -同时通过以下命令观察目标卷积层的参数(parameters)的名称和shape: +同时通过以下命令观察目标卷积层的参数(parameters)的名称和shape: ``` for param in fluid.default_main_program().global_block().all_parameters(): if 'weights' in param.name: - print param.name, param.shape + print(param.name, param.shape) ``` @@ -121,7 +121,7 @@ python compress.py \ - **max_iters:** 一个`epoch`中batch的数量,需要设置为`total_num / batch_size`, 其中`total_num`为训练样本总数量,`batch_size`为多卡上总的batch size. - **YoloTrainFeed.batch_size:** 当使用DataLoader时,表示单张卡上的batch size; 当使用普通reader时,则表示多卡上的总的`batch_size`。`batch_size`受限于显存大小。 - **LeaningRate.base_lr:** 根据多卡的总`batch_size`调整`base_lr`,两者大小正相关,可以简单的按比例进行调整。 -- **LearningRate.schedulers.PiecewiseDecay.milestones:**请根据batch size的变化对其调整。 +- **LearningRate.schedulers.PiecewiseDecay.milestones:** 请根据batch size的变化对其调整。 - **LearningRate.schedulers.PiecewiseDecay.LinearWarmup.steps:** 请根据batch size的变化对其进行调整。 @@ -168,6 +168,16 @@ python compress.py \ 如果不需要保存评估模型,可以在定义Compressor对象时,将`save_eval_model`选项设置为False(默认为True)。 +运行命令为: +``` +python ../eval.py \ + --model_path ${checkpoint_path}/${epoch_id}/eval_model/ \ + --model_name __model__ \ + --params_name __params__ \ + -c ../../configs/yolov3_mobilenet_v1_voc.yml \ + -d "../../dataset/voc" +``` + ## 预测 如果在配置文件中设置了`checkpoint_path`,并且在定义Compressor对象时指定了`prune_infer_model`选项,则每个epoch都会 @@ -182,6 +192,16 @@ python compress.py \ 在脚本PaddleDetection/tools/infer.py中展示了如何使用fluid python API加载使用预测模型进行预测。 +运行命令为: +``` +python ../infer.py \ + --model_path ${checkpoint_path}/${epoch_id}/eval_model/ \ + --model_name __model__ \ + --params_name __params__ \ + -c ../../configs/yolov3_mobilenet_v1_voc.yml \ + --infer_dir ../../demo +``` + ### PaddleLite 该示例中产出的预测(inference)模型可以直接用PaddleLite进行加载使用。 diff --git a/PaddleSlim/classification/distillation/README.md b/PaddleSlim/classification/distillation/README.md index 1d5004699a060320ed5b08287e4e644476397212..6a097851cdb65ef27e7e0fc74419533ecc816606 100755 --- a/PaddleSlim/classification/distillation/README.md +++ b/PaddleSlim/classification/distillation/README.md @@ -34,12 +34,12 @@ ```python # 观察student model的Variable for v in fluid.default_main_program().list_vars(): - print v.name, v.shape + print(v.name, v.shape) ``` ```python # 观察teacher model的Variable for v in teacher_program.list_vars(): - print v.name, v.shape + print(v.name, v.shape) ``` 经过对比可以发现,`student model`和`teacher model`预测的输出分别为: @@ -111,6 +111,16 @@ strategies: 脚本PaddleSlim/classification/eval.py中为使用该模型在评估数据集上做评估的示例。 +运行命令示例: +```bash +python eval.py \ + --use_gpu True \ + --model_path ${save_path}/eval_model/ \ + --model_name __model__ \ + --params_name __params__ + +``` + ## 预测 如果在配置文件中设置了`checkpoint_path`,并且在定义Compressor对象时指定了`prune_infer_model`选项,则每个epoch都会 @@ -125,6 +135,15 @@ strategies: 在脚本PaddleSlim/classification/infer.py中展示了如何使用fluid python API加载使用预测模型进行预测。 +运行命令示例: +```bash +python infer.py \ + --use_gpu True \ + --model_path ${save_path}/eval_model/ \ + --model_name __model__ \ + --params_name __params__ +``` + ### PaddleLite 该示例中产出的预测(inference)模型可以直接用PaddleLite进行加载使用。 @@ -144,7 +163,7 @@ strategies: - batch size: 256 - lr_strategy: piecewise_decay - step_epochs: 30, 60, 90 -- num_epochs: 120 +- num_epochs: 130 - l2_decay: 4e-5 - init lr: 0.1 @@ -160,7 +179,7 @@ strategies: - batch size: 256 - lr_strategy: piecewise_decay - step_epochs: 30, 60, 90 -- num_epochs: 120 +- num_epochs: 130 - l2_decay: 4e-5 - init lr: 0.1 @@ -176,7 +195,7 @@ strategies: - batch size: 256 - lr_strategy: piecewise_decay - step_epochs: 30, 60, 90 -- num_epochs: 120 +- num_epochs: 130 - l2_decay: 4e-5 - init lr: 0.1 diff --git a/PaddleSlim/classification/distillation/compress.py b/PaddleSlim/classification/distillation/compress.py index 49a800f8cba00abf3faad5976c8a406ed6b1fd20..3cb8f2bcb6d1df87f8631bd69f1be3b16ea6defd 100644 --- a/PaddleSlim/classification/distillation/compress.py +++ b/PaddleSlim/classification/distillation/compress.py @@ -95,7 +95,6 @@ def compress(args): train_fetch_list = [('loss', avg_cost.name)] teacher_programs = [] - distiller_optimizer = None teacher_model = models.__dict__[args.teacher_model](prefix_name='res50') # define teacher program diff --git a/PaddleSlim/classification/distillation/configs/mobilenetv2_resnet50_distillation.yaml b/PaddleSlim/classification/distillation/configs/mobilenetv2_resnet50_distillation.yaml index 079d9231b427a8a270cfc719db68e4f17d712507..750cbae23928352fe0903f84327be0efab9b55ef 100644 --- a/PaddleSlim/classification/distillation/configs/mobilenetv2_resnet50_distillation.yaml +++ b/PaddleSlim/classification/distillation/configs/mobilenetv2_resnet50_distillation.yaml @@ -2,8 +2,8 @@ version: 1.0 distillers: l2_distiller: class: 'L2Distiller' - teacher_feature_map: 'res50_fc_0.tmp_1' - student_feature_map: 'fc_0.tmp_1' + teacher_feature_map: 'res50_fc_0.tmp_0' + student_feature_map: 'fc_0.tmp_0' distillation_loss_weight: 1 strategies: distillation_strategy: diff --git a/PaddleSlim/classification/distillation/run.sh b/PaddleSlim/classification/distillation/run.sh index c18e6eeed028aa4f95735decf9901afde2e8af1a..8668c5fb4df455308c0490a88afeb32f209180e6 100644 --- a/PaddleSlim/classification/distillation/run.sh +++ b/PaddleSlim/classification/distillation/run.sh @@ -58,7 +58,7 @@ tailf mobilenet_v1.log #--model "MobileNetV2" \ #--teacher_model "ResNet50" \ #--teacher_pretrained_model ../pretrain/ResNet50_pretrained \ -#--compress_config ./configs/mobilenetv2_resnet50_distillation.yaml\ +#--compress_config ./configs/mobilenetv2_resnet50_distillation.yaml \ #> mobilenet_v2.log 2>&1 & #tailf mobilenet_v2.log diff --git a/PaddleSlim/classification/pruning/README.md b/PaddleSlim/classification/pruning/README.md index 92082098b4e19e99c8ca9be4aa489515dbfd8394..6c4035d5d94e17e162ef95427bcbe49605c17620 100644 --- a/PaddleSlim/classification/pruning/README.md +++ b/PaddleSlim/classification/pruning/README.md @@ -37,7 +37,7 @@ PaddleSlim暂时无法对`depthwise convolution`直接进行剪裁, 因为`dep ``` for param in fluid.default_main_program().global_block().all_parameters(): if 'weights' in param.name: - print param.name, param.shape + print(param.name, param.shape) ``` 结果如下: @@ -100,6 +100,16 @@ fc10_weights (1280L, 1000L) 脚本PaddleSlim/classification/eval.py中为使用该模型在评估数据集上做评估的示例。 +运行命令示例: +```bash +python eval.py \ + --use_gpu True \ + --model_path ${save_path}/eval_model/ \ + --model_name __model__ \ + --params_name __params__ + +``` + ## 预测 如果在配置文件中设置了`checkpoint_path`,并且在定义Compressor对象时指定了`prune_infer_model`选项,则每个epoch都会 @@ -114,6 +124,15 @@ fc10_weights (1280L, 1000L) 在脚本PaddleSlim/classification/infer.py中展示了如何使用fluid python API加载使用预测模型进行预测。 +运行命令示例: +```bash +python infer.py \ + --use_gpu True \ + --model_path ${save_path}/eval_model/ \ + --model_name __model__ \ + --params_name __params__ +``` + ### PaddleLite 该示例中产出的预测(inference)模型可以直接用PaddleLite进行加载使用。