We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
跑敏感度分析时报错
按文档执行如下指令：
python3 slim/sensitive/sensitive.py -c configs/yolov3_mobilenet_v1_voc.yml -o weights=https://paddlemodels.bj.bcebos.com/object_detection/yolov3_mobilenet_v1_voc.tar --pruned_params "yolo_block.0.0.0.conv.weights,yolo_block.0.0.1.conv.weights,yolo_block.0.1.0.conv.weights,yolo_block.0.1.1.conv.weights,yolo_block.0.2.conv.weights,yolo_block.0.tip.conv.weights,yolo_block.1.0.0.conv.weights,yolo_block.1.0.1.conv.weights,yolo_block.1.1.0.conv.weights,yolo_block.1.1.1.conv.weights,yolo_block.1.2.conv.weights,yolo_block.1.tip.conv.weights,yolo_block.2.0.0.conv.weights,yolo_block.2.0.1.conv.weights,yolo_block.2.1.0.conv.weights,yolo_block.2.1.1.conv.weights,yolo_block.2.2.conv.weights,yolo_block.2.tip.conv.weights" --sensitivities_file "./demo.data"
报以下错误：2020-03-18 14:40:01,847-INFO: pruned params: ['yolo_block.0.0.0.conv.weights', 'yolo_block.0.0.1.conv.weights', 'yolo_block.0.1.0.conv.weights', 'yolo_block.0.1.1.conv.weights', 'yolo_block.0.2.conv.weights', 'yolo_block.0.tip.conv.weights', 'yolo_block.1.0.0.conv.weights', 'yolo_block.1.0.1.conv.weights', 'yolo_block.1.1.0.conv.weights', 'yolo_block.1.1.1.conv.weights', 'yolo_block.1.2.conv.weights', 'yolo_block.1.tip.conv.weights', 'yolo_block.2.0.0.conv.weights', 'yolo_block.2.0.1.conv.weights', 'yolo_block.2.1.0.conv.weights', 'yolo_block.2.1.1.conv.weights', 'yolo_block.2.2.conv.weights', 'yolo_block.2.tip.conv.weights']
2020-03-18 14:40:01,847-INFO: pruned ratios: [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]
I0318 14:40:01.860719 14780 parallel_executor.cc:440] The Program will be executed on CUDA using ParallelExecutor, 1 cards are used, so 1 programs are executed in parallel.
I0318 14:40:01.868165 14780 build_strategy.cc:365] SeqOnlyAllReduceOps:0, num_trainers:1
I0318 14:40:01.874647 14780 parallel_executor.cc:307] Inplace strategy is enabled, when build_strategy.enable_inplace = True
I0318 14:40:01.879664 14780 parallel_executor.cc:375] Garbage collection strategy is enabled, when FLAGS_eager_delete_tensor_gb = 0
2020-03-18 14:40:02,443-INFO: Test iter 0
2020-03-18 14:40:10,603-INFO: Test iter 100
2020-03-18 14:40:21,551-INFO: Test iter 200
2020-03-18 14:40:28,985-INFO: Test iter 300
2020-03-18 14:39:54,955-INFO: Test iter 400
2020-03-18 14:40:02,477-INFO: Test iter 500
2020-03-18 14:40:09,807-INFO: Test iter 600
2020-03-18 14:40:11,114-INFO: Test finish iter 619
2020-03-18 14:40:11,114-INFO: Total number of images: 4952, inference time: 534.683212877132 fps.
2020-03-18 14:40:11,115-INFO: Start evaluate...
Traceback (most recent call last):
  File "slim/sensitive/sensitive.py", line 214, in <module>
    main()
  File "slim/sensitive/sensitive.py", line 172, in main
    pruned_ratios=pruned_ratios)
  File "/usr/local/lib/python3.5/dist-packages/paddleslim/prune/sensitive.py", line 86, in sensitivity
    baseline = eval_func(graph.program)
  File "slim/sensitive/sensitive.py", line 154, in test
    dataset=dataset)
  File "/home/chenchaocun/PaddleDetection_slim/slim/sensitive/ppdet/utils/eval_utils.py", line 222, in eval_results
    map_type=map_type)
  File "/home/chenchaocun/PaddleDetection_slim/slim/sensitive/ppdet/utils/voc_eval.py", line 72, in bbox_eval
    gt_boxes = t['gt_bbox'][0]
KeyError: 'gt_bbox'
这个voc_eval.py在其他任务验证时没有出现过错误，请请教下这是啥问题导致的？

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `slim/sensitive/sensitive.py`
Content:
```
1 # Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 
15 from __future__ import absolute_import
16 from __future__ import division
17 from __future__ import print_function
18 
19 import os
20 import time
21 import numpy as np
22 import datetime
23 from collections import deque
24 
25 
26 def set_paddle_flags(**kwargs):
27     for key, value in kwargs.items():
28         if os.environ.get(key, None) is None:
29             os.environ[key] = str(value)
30 
31 
32 # NOTE(paddle-dev): All of these flags should be set before
33 # `import paddle`. Otherwise, it would not take any effect.
34 set_paddle_flags(
35     FLAGS_eager_delete_tensor_gb=0,  # enable GC to save memory
36 )
37 
38 from paddle import fluid
39 from ppdet.experimental import mixed_precision_context
40 from ppdet.core.workspace import load_config, merge_config, create
41 #from ppdet.data.data_feed import create_reader
42 
43 from ppdet.data.reader import create_reader
44 
45 from ppdet.utils.cli import print_total_cfg
46 from ppdet.utils import dist_utils
47 from ppdet.utils.eval_utils import parse_fetches, eval_run, eval_results
48 from ppdet.utils.stats import TrainingStats
49 from ppdet.utils.cli import ArgsParser
50 from ppdet.utils.check import check_gpu, check_version
51 import ppdet.utils.checkpoint as checkpoint
52 from ppdet.modeling.model_input import create_feed
53 from paddleslim.prune import sensitivity
54 import logging
55 FORMAT = '%(asctime)s-%(levelname)s: %(message)s'
56 logging.basicConfig(level=logging.INFO, format=FORMAT)
57 logger = logging.getLogger(__name__)
58 
59 
60 def main():
61     env = os.environ
62 
63     print("FLAGS.config: {}".format(FLAGS.config))
64     cfg = load_config(FLAGS.config)
65     assert 'architecture' in cfg
66     main_arch = cfg.architecture
67 
68     merge_config(FLAGS.opt)
69 
70     print_total_cfg(cfg)
71 
72     place = fluid.CUDAPlace(0)
73     exe = fluid.Executor(place)
74 
75     # build program
76     startup_prog = fluid.Program()
77     eval_prog = fluid.Program()
78     with fluid.program_guard(eval_prog, startup_prog):
79         with fluid.unique_name.guard():
80             model = create(main_arch)
81             inputs_def = cfg['EvalReader']['inputs_def']
82             feed_vars, eval_loader = model.build_inputs(**inputs_def)
83             fetches = model.eval(feed_vars)
84     eval_prog = eval_prog.clone(True)
85 
86     if FLAGS.print_params:
87         print(
88             "-------------------------All parameters in current graph----------------------"
89         )
90         for block in eval_prog.blocks:
91             for param in block.all_parameters():
92                 print("parameter name: {}\tshape: {}".format(param.name,
93                                                              param.shape))
94         print(
95             "------------------------------------------------------------------------------"
96         )
97         return
98 
99     eval_reader = create_reader(cfg.EvalReader)
100     eval_loader.set_sample_list_generator(eval_reader, place)
101 
102     # parse eval fetches
103     extra_keys = []
104     if cfg.metric == 'COCO':
105         extra_keys = ['im_info', 'im_id', 'im_shape']
106     if cfg.metric == 'VOC':
107         extra_keys = ['gt_box', 'gt_label', 'is_difficult']
108     if cfg.metric == 'WIDERFACE':
109         extra_keys = ['im_id', 'im_shape', 'gt_box']
110     eval_keys, eval_values, eval_cls = parse_fetches(fetches, eval_prog,
111                                                      extra_keys)
112 
113     exe.run(startup_prog)
114 
115     fuse_bn = getattr(model.backbone, 'norm_type', None) == 'affine_channel'
116 
117     ignore_params = cfg.finetune_exclude_pretrained_params \
118                  if 'finetune_exclude_pretrained_params' in cfg else []
119 
120     start_iter = 0
121 
122     if cfg.weights:
123         checkpoint.load_params(exe, eval_prog, cfg.weights)
124     else:
125         logger.warn("Please set cfg.weights to load trained model.")
126 
127     # whether output bbox is normalized in model output layer
128     is_bbox_normalized = False
129     if hasattr(model, 'is_bbox_normalized') and \
130             callable(model.is_bbox_normalized):
131         is_bbox_normalized = model.is_bbox_normalized()
132 
133     # if map_type not set, use default 11point, only use in VOC eval
134     map_type = cfg.map_type if 'map_type' in cfg else '11point'
135 
136     def test(program):
137 
138         compiled_eval_prog = fluid.compiler.CompiledProgram(program)
139 
140         results = eval_run(exe, compiled_eval_prog, eval_loader, eval_keys,
141                            eval_values, eval_cls)
142         resolution = None
143         if 'mask' in results[0]:
144             resolution = model.mask_head.resolution
145         dataset = cfg['EvalReader']['dataset']
146         box_ap_stats = eval_results(
147             results,
148             cfg.metric,
149             cfg.num_classes,
150             resolution,
151             is_bbox_normalized,
152             FLAGS.output_eval,
153             map_type,
154             dataset=dataset)
155         return box_ap_stats[0]
156 
157     pruned_params = FLAGS.pruned_params
158 
159     assert (
160         FLAGS.pruned_params is not None
161     ), "FLAGS.pruned_params is empty!!! Please set it by '--pruned_params' option."
162     pruned_params = FLAGS.pruned_params.strip().split(",")
163     logger.info("pruned params: {}".format(pruned_params))
164     pruned_ratios = [float(n) for n in FLAGS.pruned_ratios.strip().split(" ")]
165     logger.info("pruned ratios: {}".format(pruned_ratios))
166     sensitivity(
167         eval_prog,
168         place,
169         pruned_params,
170         test,
171         sensitivities_file=FLAGS.sensitivities_file,
172         pruned_ratios=pruned_ratios)
173 
174 
175 if __name__ == '__main__':
176     parser = ArgsParser()
177     parser.add_argument(
178         "--output_eval",
179         default=None,
180         type=str,
181         help="Evaluation directory, default is current directory.")
182     parser.add_argument(
183         "-d",
184         "--dataset_dir",
185         default=None,
186         type=str,
187         help="Dataset path, same as DataFeed.dataset.dataset_dir")
188     parser.add_argument(
189         "-s",
190         "--sensitivities_file",
191         default="sensitivities.data",
192         type=str,
193         help="The file used to save sensitivities.")
194     parser.add_argument(
195         "-p",
196         "--pruned_params",
197         default=None,
198         type=str,
199         help="The parameters to be pruned when calculating sensitivities.")
200     parser.add_argument(
201         "-r",
202         "--pruned_ratios",
203         default="0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9",
204         type=str,
205         help="The ratios pruned iteratively for each parameter when calculating sensitivities."
206     )
207     parser.add_argument(
208         "-P",
209         "--print_params",
210         default=False,
211         action='store_true',
212         help="Whether to only print the parameters' names and shapes.")
213     FLAGS = parser.parse_args()
214     main()
215
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/slim/sensitive/sensitive.py b/slim/sensitive/sensitive.py
--- a/slim/sensitive/sensitive.py
+++ b/slim/sensitive/sensitive.py
@@ -82,7 +82,6 @@
             feed_vars, eval_loader = model.build_inputs(**inputs_def)
             fetches = model.eval(feed_vars)
     eval_prog = eval_prog.clone(True)
-
     if FLAGS.print_params:
         print(
             "-------------------------All parameters in current graph----------------------"
@@ -104,7 +103,7 @@
     if cfg.metric == 'COCO':
         extra_keys = ['im_info', 'im_id', 'im_shape']
     if cfg.metric == 'VOC':
-        extra_keys = ['gt_box', 'gt_label', 'is_difficult']
+        extra_keys = ['gt_bbox', 'gt_class', 'is_difficult']
     if cfg.metric == 'WIDERFACE':
         extra_keys = ['im_id', 'im_shape', 'gt_box']
     eval_keys, eval_values, eval_cls = parse_fetches(fetches, eval_prog,

{"golden_diff": "diff --git a/slim/sensitive/sensitive.py b/slim/sensitive/sensitive.py\n--- a/slim/sensitive/sensitive.py\n+++ b/slim/sensitive/sensitive.py\n@@ -82,7 +82,6 @@\n             feed_vars, eval_loader = model.build_inputs(**inputs_def)\n             fetches = model.eval(feed_vars)\n     eval_prog = eval_prog.clone(True)\n-\n     if FLAGS.print_params:\n         print(\n             \"-------------------------All parameters in current graph----------------------\"\n@@ -104,7 +103,7 @@\n     if cfg.metric == 'COCO':\n         extra_keys = ['im_info', 'im_id', 'im_shape']\n     if cfg.metric == 'VOC':\n-        extra_keys = ['gt_box', 'gt_label', 'is_difficult']\n+        extra_keys = ['gt_bbox', 'gt_class', 'is_difficult']\n     if cfg.metric == 'WIDERFACE':\n         extra_keys = ['im_id', 'im_shape', 'gt_box']\n     eval_keys, eval_values, eval_cls = parse_fetches(fetches, eval_prog,\n", "issue": "\u8dd1\u654f\u611f\u5ea6\u5206\u6790\u65f6\u62a5\u9519\n\u6309\u6587\u6863\u6267\u884c\u5982\u4e0b\u6307\u4ee4\uff1a\r\npython3 slim/sensitive/sensitive.py -c configs/yolov3_mobilenet_v1_voc.yml -o weights=https://paddlemodels.bj.bcebos.com/object_detection/yolov3_mobilenet_v1_voc.tar --pruned_params \"yolo_block.0.0.0.conv.weights,yolo_block.0.0.1.conv.weights,yolo_block.0.1.0.conv.weights,yolo_block.0.1.1.conv.weights,yolo_block.0.2.conv.weights,yolo_block.0.tip.conv.weights,yolo_block.1.0.0.conv.weights,yolo_block.1.0.1.conv.weights,yolo_block.1.1.0.conv.weights,yolo_block.1.1.1.conv.weights,yolo_block.1.2.conv.weights,yolo_block.1.tip.conv.weights,yolo_block.2.0.0.conv.weights,yolo_block.2.0.1.conv.weights,yolo_block.2.1.0.conv.weights,yolo_block.2.1.1.conv.weights,yolo_block.2.2.conv.weights,yolo_block.2.tip.conv.weights\" --sensitivities_file \"./demo.data\"\r\n\u62a5\u4ee5\u4e0b\u9519\u8bef\uff1a2020-03-18 14:40:01,847-INFO: pruned params: ['yolo_block.0.0.0.conv.weights', 'yolo_block.0.0.1.conv.weights', 'yolo_block.0.1.0.conv.weights', 'yolo_block.0.1.1.conv.weights', 'yolo_block.0.2.conv.weights', 'yolo_block.0.tip.conv.weights', 'yolo_block.1.0.0.conv.weights', 'yolo_block.1.0.1.conv.weights', 'yolo_block.1.1.0.conv.weights', 'yolo_block.1.1.1.conv.weights', 'yolo_block.1.2.conv.weights', 'yolo_block.1.tip.conv.weights', 'yolo_block.2.0.0.conv.weights', 'yolo_block.2.0.1.conv.weights', 'yolo_block.2.1.0.conv.weights', 'yolo_block.2.1.1.conv.weights', 'yolo_block.2.2.conv.weights', 'yolo_block.2.tip.conv.weights']\r\n2020-03-18 14:40:01,847-INFO: pruned ratios: [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]\r\nI0318 14:40:01.860719 14780 parallel_executor.cc:440] The Program will be executed on CUDA using ParallelExecutor, 1 cards are used, so 1 programs are executed in parallel.\r\nI0318 14:40:01.868165 14780 build_strategy.cc:365] SeqOnlyAllReduceOps:0, num_trainers:1\r\nI0318 14:40:01.874647 14780 parallel_executor.cc:307] Inplace strategy is enabled, when build_strategy.enable_inplace = True\r\nI0318 14:40:01.879664 14780 parallel_executor.cc:375] Garbage collection strategy is enabled, when FLAGS_eager_delete_tensor_gb = 0\r\n2020-03-18 14:40:02,443-INFO: Test iter 0\r\n2020-03-18 14:40:10,603-INFO: Test iter 100\r\n2020-03-18 14:40:21,551-INFO: Test iter 200\r\n2020-03-18 14:40:28,985-INFO: Test iter 300\r\n2020-03-18 14:39:54,955-INFO: Test iter 400\r\n2020-03-18 14:40:02,477-INFO: Test iter 500\r\n2020-03-18 14:40:09,807-INFO: Test iter 600\r\n2020-03-18 14:40:11,114-INFO: Test finish iter 619\r\n2020-03-18 14:40:11,114-INFO: Total number of images: 4952, inference time: 534.683212877132 fps.\r\n2020-03-18 14:40:11,115-INFO: Start evaluate...\r\nTraceback (most recent call last):\r\n  File \"slim/sensitive/sensitive.py\", line 214, in <module>\r\n    main()\r\n  File \"slim/sensitive/sensitive.py\", line 172, in main\r\n    pruned_ratios=pruned_ratios)\r\n  File \"/usr/local/lib/python3.5/dist-packages/paddleslim/prune/sensitive.py\", line 86, in sensitivity\r\n    baseline = eval_func(graph.program)\r\n  File \"slim/sensitive/sensitive.py\", line 154, in test\r\n    dataset=dataset)\r\n  File \"/home/chenchaocun/PaddleDetection_slim/slim/sensitive/ppdet/utils/eval_utils.py\", line 222, in eval_results\r\n    map_type=map_type)\r\n  File \"/home/chenchaocun/PaddleDetection_slim/slim/sensitive/ppdet/utils/voc_eval.py\", line 72, in bbox_eval\r\n    gt_boxes = t['gt_bbox'][0]\r\nKeyError: 'gt_bbox'\r\n\u8fd9\u4e2avoc_eval.py\u5728\u5176\u4ed6\u4efb\u52a1\u9a8c\u8bc1\u65f6\u6ca1\u6709\u51fa\u73b0\u8fc7\u9519\u8bef\uff0c\u8bf7\u8bf7\u6559\u4e0b\u8fd9\u662f\u5565\u95ee\u9898\u5bfc\u81f4\u7684\uff1f\n", "before_files": [{"content": "# Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nfrom __future__ import absolute_import\nfrom __future__ import division\nfrom __future__ import print_function\n\nimport os\nimport time\nimport numpy as np\nimport datetime\nfrom collections import deque\n\n\ndef set_paddle_flags(**kwargs):\n    for key, value in kwargs.items():\n        if os.environ.get(key, None) is None:\n            os.environ[key] = str(value)\n\n\n# NOTE(paddle-dev): All of these flags should be set before\n# `import paddle`. Otherwise, it would not take any effect.\nset_paddle_flags(\n    FLAGS_eager_delete_tensor_gb=0,  # enable GC to save memory\n)\n\nfrom paddle import fluid\nfrom ppdet.experimental import mixed_precision_context\nfrom ppdet.core.workspace import load_config, merge_config, create\n#from ppdet.data.data_feed import create_reader\n\nfrom ppdet.data.reader import create_reader\n\nfrom ppdet.utils.cli import print_total_cfg\nfrom ppdet.utils import dist_utils\nfrom ppdet.utils.eval_utils import parse_fetches, eval_run, eval_results\nfrom ppdet.utils.stats import TrainingStats\nfrom ppdet.utils.cli import ArgsParser\nfrom ppdet.utils.check import check_gpu, check_version\nimport ppdet.utils.checkpoint as checkpoint\nfrom ppdet.modeling.model_input import create_feed\nfrom paddleslim.prune import sensitivity\nimport logging\nFORMAT = '%(asctime)s-%(levelname)s: %(message)s'\nlogging.basicConfig(level=logging.INFO, format=FORMAT)\nlogger = logging.getLogger(__name__)\n\n\ndef main():\n    env = os.environ\n\n    print(\"FLAGS.config: {}\".format(FLAGS.config))\n    cfg = load_config(FLAGS.config)\n    assert 'architecture' in cfg\n    main_arch = cfg.architecture\n\n    merge_config(FLAGS.opt)\n\n    print_total_cfg(cfg)\n\n    place = fluid.CUDAPlace(0)\n    exe = fluid.Executor(place)\n\n    # build program\n    startup_prog = fluid.Program()\n    eval_prog = fluid.Program()\n    with fluid.program_guard(eval_prog, startup_prog):\n        with fluid.unique_name.guard():\n            model = create(main_arch)\n            inputs_def = cfg['EvalReader']['inputs_def']\n            feed_vars, eval_loader = model.build_inputs(**inputs_def)\n            fetches = model.eval(feed_vars)\n    eval_prog = eval_prog.clone(True)\n\n    if FLAGS.print_params:\n        print(\n            \"-------------------------All parameters in current graph----------------------\"\n        )\n        for block in eval_prog.blocks:\n            for param in block.all_parameters():\n                print(\"parameter name: {}\\tshape: {}\".format(param.name,\n                                                             param.shape))\n        print(\n            \"------------------------------------------------------------------------------\"\n        )\n        return\n\n    eval_reader = create_reader(cfg.EvalReader)\n    eval_loader.set_sample_list_generator(eval_reader, place)\n\n    # parse eval fetches\n    extra_keys = []\n    if cfg.metric == 'COCO':\n        extra_keys = ['im_info', 'im_id', 'im_shape']\n    if cfg.metric == 'VOC':\n        extra_keys = ['gt_box', 'gt_label', 'is_difficult']\n    if cfg.metric == 'WIDERFACE':\n        extra_keys = ['im_id', 'im_shape', 'gt_box']\n    eval_keys, eval_values, eval_cls = parse_fetches(fetches, eval_prog,\n                                                     extra_keys)\n\n    exe.run(startup_prog)\n\n    fuse_bn = getattr(model.backbone, 'norm_type', None) == 'affine_channel'\n\n    ignore_params = cfg.finetune_exclude_pretrained_params \\\n                 if 'finetune_exclude_pretrained_params' in cfg else []\n\n    start_iter = 0\n\n    if cfg.weights:\n        checkpoint.load_params(exe, eval_prog, cfg.weights)\n    else:\n        logger.warn(\"Please set cfg.weights to load trained model.\")\n\n    # whether output bbox is normalized in model output layer\n    is_bbox_normalized = False\n    if hasattr(model, 'is_bbox_normalized') and \\\n            callable(model.is_bbox_normalized):\n        is_bbox_normalized = model.is_bbox_normalized()\n\n    # if map_type not set, use default 11point, only use in VOC eval\n    map_type = cfg.map_type if 'map_type' in cfg else '11point'\n\n    def test(program):\n\n        compiled_eval_prog = fluid.compiler.CompiledProgram(program)\n\n        results = eval_run(exe, compiled_eval_prog, eval_loader, eval_keys,\n                           eval_values, eval_cls)\n        resolution = None\n        if 'mask' in results[0]:\n            resolution = model.mask_head.resolution\n        dataset = cfg['EvalReader']['dataset']\n        box_ap_stats = eval_results(\n            results,\n            cfg.metric,\n            cfg.num_classes,\n            resolution,\n            is_bbox_normalized,\n            FLAGS.output_eval,\n            map_type,\n            dataset=dataset)\n        return box_ap_stats[0]\n\n    pruned_params = FLAGS.pruned_params\n\n    assert (\n        FLAGS.pruned_params is not None\n    ), \"FLAGS.pruned_params is empty!!! Please set it by '--pruned_params' option.\"\n    pruned_params = FLAGS.pruned_params.strip().split(\",\")\n    logger.info(\"pruned params: {}\".format(pruned_params))\n    pruned_ratios = [float(n) for n in FLAGS.pruned_ratios.strip().split(\" \")]\n    logger.info(\"pruned ratios: {}\".format(pruned_ratios))\n    sensitivity(\n        eval_prog,\n        place,\n        pruned_params,\n        test,\n        sensitivities_file=FLAGS.sensitivities_file,\n        pruned_ratios=pruned_ratios)\n\n\nif __name__ == '__main__':\n    parser = ArgsParser()\n    parser.add_argument(\n        \"--output_eval\",\n        default=None,\n        type=str,\n        help=\"Evaluation directory, default is current directory.\")\n    parser.add_argument(\n        \"-d\",\n        \"--dataset_dir\",\n        default=None,\n        type=str,\n        help=\"Dataset path, same as DataFeed.dataset.dataset_dir\")\n    parser.add_argument(\n        \"-s\",\n        \"--sensitivities_file\",\n        default=\"sensitivities.data\",\n        type=str,\n        help=\"The file used to save sensitivities.\")\n    parser.add_argument(\n        \"-p\",\n        \"--pruned_params\",\n        default=None,\n        type=str,\n        help=\"The parameters to be pruned when calculating sensitivities.\")\n    parser.add_argument(\n        \"-r\",\n        \"--pruned_ratios\",\n        default=\"0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9\",\n        type=str,\n        help=\"The ratios pruned iteratively for each parameter when calculating sensitivities.\"\n    )\n    parser.add_argument(\n        \"-P\",\n        \"--print_params\",\n        default=False,\n        action='store_true',\n        help=\"Whether to only print the parameters' names and shapes.\")\n    FLAGS = parser.parse_args()\n    main()\n", "path": "slim/sensitive/sensitive.py"}], "after_files": [{"content": "# Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nfrom __future__ import absolute_import\nfrom __future__ import division\nfrom __future__ import print_function\n\nimport os\nimport time\nimport numpy as np\nimport datetime\nfrom collections import deque\n\n\ndef set_paddle_flags(**kwargs):\n    for key, value in kwargs.items():\n        if os.environ.get(key, None) is None:\n            os.environ[key] = str(value)\n\n\n# NOTE(paddle-dev): All of these flags should be set before\n# `import paddle`. Otherwise, it would not take any effect.\nset_paddle_flags(\n    FLAGS_eager_delete_tensor_gb=0,  # enable GC to save memory\n)\n\nfrom paddle import fluid\nfrom ppdet.experimental import mixed_precision_context\nfrom ppdet.core.workspace import load_config, merge_config, create\n#from ppdet.data.data_feed import create_reader\n\nfrom ppdet.data.reader import create_reader\n\nfrom ppdet.utils.cli import print_total_cfg\nfrom ppdet.utils import dist_utils\nfrom ppdet.utils.eval_utils import parse_fetches, eval_run, eval_results\nfrom ppdet.utils.stats import TrainingStats\nfrom ppdet.utils.cli import ArgsParser\nfrom ppdet.utils.check import check_gpu, check_version\nimport ppdet.utils.checkpoint as checkpoint\nfrom ppdet.modeling.model_input import create_feed\nfrom paddleslim.prune import sensitivity\nimport logging\nFORMAT = '%(asctime)s-%(levelname)s: %(message)s'\nlogging.basicConfig(level=logging.INFO, format=FORMAT)\nlogger = logging.getLogger(__name__)\n\n\ndef main():\n    env = os.environ\n\n    print(\"FLAGS.config: {}\".format(FLAGS.config))\n    cfg = load_config(FLAGS.config)\n    assert 'architecture' in cfg\n    main_arch = cfg.architecture\n\n    merge_config(FLAGS.opt)\n\n    print_total_cfg(cfg)\n\n    place = fluid.CUDAPlace(0)\n    exe = fluid.Executor(place)\n\n    # build program\n    startup_prog = fluid.Program()\n    eval_prog = fluid.Program()\n    with fluid.program_guard(eval_prog, startup_prog):\n        with fluid.unique_name.guard():\n            model = create(main_arch)\n            inputs_def = cfg['EvalReader']['inputs_def']\n            feed_vars, eval_loader = model.build_inputs(**inputs_def)\n            fetches = model.eval(feed_vars)\n    eval_prog = eval_prog.clone(True)\n    if FLAGS.print_params:\n        print(\n            \"-------------------------All parameters in current graph----------------------\"\n        )\n        for block in eval_prog.blocks:\n            for param in block.all_parameters():\n                print(\"parameter name: {}\\tshape: {}\".format(param.name,\n                                                             param.shape))\n        print(\n            \"------------------------------------------------------------------------------\"\n        )\n        return\n\n    eval_reader = create_reader(cfg.EvalReader)\n    eval_loader.set_sample_list_generator(eval_reader, place)\n\n    # parse eval fetches\n    extra_keys = []\n    if cfg.metric == 'COCO':\n        extra_keys = ['im_info', 'im_id', 'im_shape']\n    if cfg.metric == 'VOC':\n        extra_keys = ['gt_bbox', 'gt_class', 'is_difficult']\n    if cfg.metric == 'WIDERFACE':\n        extra_keys = ['im_id', 'im_shape', 'gt_box']\n    eval_keys, eval_values, eval_cls = parse_fetches(fetches, eval_prog,\n                                                     extra_keys)\n\n    exe.run(startup_prog)\n\n    fuse_bn = getattr(model.backbone, 'norm_type', None) == 'affine_channel'\n\n    ignore_params = cfg.finetune_exclude_pretrained_params \\\n                 if 'finetune_exclude_pretrained_params' in cfg else []\n\n    start_iter = 0\n\n    if cfg.weights:\n        checkpoint.load_params(exe, eval_prog, cfg.weights)\n    else:\n        logger.warn(\"Please set cfg.weights to load trained model.\")\n\n    # whether output bbox is normalized in model output layer\n    is_bbox_normalized = False\n    if hasattr(model, 'is_bbox_normalized') and \\\n            callable(model.is_bbox_normalized):\n        is_bbox_normalized = model.is_bbox_normalized()\n\n    # if map_type not set, use default 11point, only use in VOC eval\n    map_type = cfg.map_type if 'map_type' in cfg else '11point'\n\n    def test(program):\n\n        compiled_eval_prog = fluid.compiler.CompiledProgram(program)\n\n        results = eval_run(exe, compiled_eval_prog, eval_loader, eval_keys,\n                           eval_values, eval_cls)\n        resolution = None\n        if 'mask' in results[0]:\n            resolution = model.mask_head.resolution\n        dataset = cfg['EvalReader']['dataset']\n        box_ap_stats = eval_results(\n            results,\n            cfg.metric,\n            cfg.num_classes,\n            resolution,\n            is_bbox_normalized,\n            FLAGS.output_eval,\n            map_type,\n            dataset=dataset)\n        return box_ap_stats[0]\n\n    pruned_params = FLAGS.pruned_params\n\n    assert (\n        FLAGS.pruned_params is not None\n    ), \"FLAGS.pruned_params is empty!!! Please set it by '--pruned_params' option.\"\n    pruned_params = FLAGS.pruned_params.strip().split(\",\")\n    logger.info(\"pruned params: {}\".format(pruned_params))\n    pruned_ratios = [float(n) for n in FLAGS.pruned_ratios.strip().split(\" \")]\n    logger.info(\"pruned ratios: {}\".format(pruned_ratios))\n    sensitivity(\n        eval_prog,\n        place,\n        pruned_params,\n        test,\n        sensitivities_file=FLAGS.sensitivities_file,\n        pruned_ratios=pruned_ratios)\n\n\nif __name__ == '__main__':\n    parser = ArgsParser()\n    parser.add_argument(\n        \"--output_eval\",\n        default=None,\n        type=str,\n        help=\"Evaluation directory, default is current directory.\")\n    parser.add_argument(\n        \"-d\",\n        \"--dataset_dir\",\n        default=None,\n        type=str,\n        help=\"Dataset path, same as DataFeed.dataset.dataset_dir\")\n    parser.add_argument(\n        \"-s\",\n        \"--sensitivities_file\",\n        default=\"sensitivities.data\",\n        type=str,\n        help=\"The file used to save sensitivities.\")\n    parser.add_argument(\n        \"-p\",\n        \"--pruned_params\",\n        default=None,\n        type=str,\n        help=\"The parameters to be pruned when calculating sensitivities.\")\n    parser.add_argument(\n        \"-r\",\n        \"--pruned_ratios\",\n        default=\"0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9\",\n        type=str,\n        help=\"The ratios pruned iteratively for each parameter when calculating sensitivities.\"\n    )\n    parser.add_argument(\n        \"-P\",\n        \"--print_params\",\n        default=False,\n        action='store_true',\n        help=\"Whether to only print the parameters' names and shapes.\")\n    FLAGS = parser.parse_args()\n    main()\n", "path": "slim/sensitive/sensitive.py"}]}