diff --git a/slim/prune/README.md b/slim/prune/README.md index 227b87a75d0d91525d428bdbe889c32341f25f2f..d000c329b066e7a09dee1b33a2fe96ec568d6e71 100644 --- a/slim/prune/README.md +++ b/slim/prune/README.md @@ -90,3 +90,26 @@ python export_model.py \ 如果需要对自己的模型进行修改,可以参考`prune.py`中对`paddleslim.prune.Pruner`接口的调用方式,基于自己的模型训练脚本进行修改。 本节我们介绍的剪裁示例,需要用户根据先验知识指定每层的剪裁率,除此之外,PaddleSlim还提供了敏感度分析等功能,协助用户选择合适的剪裁率。更多详情请参考:[PaddleSlim使用文档](https://paddlepaddle.github.io/PaddleSlim/) + +## 9. 更多示例与注意事项 + +## 9.1 faster_rcnn与mask_rcnn + +**当前PaddleSlim的剪裁功能不支持剪裁循环体或条件判断语句块内的卷积层,请避免剪裁循环和判断语句块前的一个卷积和语句块内部的卷积。** + +对于[faster_rcnn_r50](../../configs/faster_rcnn_r50_1x.yml)或[mask_rcnn_r50](../../configs/mask_rcnn_r50_1x.yml)网络,请剪裁卷积`res4f_branch2c`之前的卷积。 + +对[faster_rcnn_r50](../../configs/faster_rcnn_r50_1x.yml)剪裁示例如下: + +``` +# demo for faster_rcnn_r50 +python prune.py -c ../../configs/faster_rcnn_r50_1x.yml --pruned_params "res4f_branch2b_weights,res4f_branch2a_weights" --pruned_ratios="0.3,0.4" --eval +``` + +对[mask_rcnn_r50](../../configs/mask_rcnn_r50_1x.yml)剪裁示例如下: + +``` +# demo for mask_rcnn_r50 +python prune.py -c ../../configs/mask_rcnn_r50_1x.yml --pruned_params "res4f_branch2b_weights,res4f_branch2a_weights" --pruned_ratios="0.2,0.3" --eval + +``` diff --git a/slim/prune/prune.py b/slim/prune/prune.py index 606b29e7cc76ac6538737acde2fce2bb99bfd241..657edc2129887734e7d3d44c804014bcef7371f7 100644 --- a/slim/prune/prune.py +++ b/slim/prune/prune.py @@ -252,12 +252,19 @@ def main(): tb_mAP_step = 0 if FLAGS.eval: - # evaluation - results = eval_run(exe, compiled_eval_prog, eval_loader, eval_keys, - eval_values, eval_cls) resolution = None - if 'mask' in results[0]: + if 'Mask' in cfg.architecture: resolution = model.mask_head.resolution + # evaluation + results = eval_run( + exe, + compiled_eval_prog, + eval_loader, + eval_keys, + eval_values, + eval_cls, + cfg, + resolution=resolution) dataset = cfg['EvalReader']['dataset'] box_ap_stats = eval_results( results,