Repository: PaddlePaddle/PaddleDetection

Issue:
运行检测模型卷积通道剪裁示例时报错
当我运行python compress.py \
    -s yolov3_mobilenet_v1_slim.yaml \
    -c ../../configs/yolov3_mobilenet_v1.yml \
    -o max_iters=20 \
    num_classes=4 \
    YoloTrainFeed.batch_size=32 \
    pretrain_weights=/home/aistudio/PaddleDetection/output/yolov3_mobilenet_v1/best_model \
    -d "/home/aistudio/work/coco"
这个命令时一直报错以下错误，经定位是eval_utils.py将gt_box的值转换成im_id异常，异常信息如下


loading annotations into memory...
Done (t=0.01s)
creating index...
index created!
[ 16. 115. 218. 374.]
Traceback (most recent call last):
  File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/contrib/slim/core/compressor.py", line 593, in run
    self._eval(context)
  File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/contrib/slim/core/compressor.py", line 542, in _eval
    func(self.eval_graph.program, self.scope))
  File "compress.py", line 207, in eval_func
    FLAGS.output_eval)
  File "../../ppdet/utils/eval_utils.py", line 205, in eval_results
    is_bbox_normalized=is_bbox_normalized)
  File "../../ppdet/utils/coco_eval.py", line 86, in bbox_eval
    results, clsid2catid, is_bbox_normalized=is_bbox_normalized)
  File "../../ppdet/utils/coco_eval.py", line 215, in bbox2out
    im_id = int(im_ids[i][0])
TypeError: only size-1 arrays can be converted to Python scalars
2019-11-20 20:32:00,491-ERROR: None
2019-11-20 20:32:00,491-ERROR: None
2019-11-20 20:32:01,633-INFO: epoch:1; batch_id:0; odict_keys(['loss', 'lr']) = [117.678, 0.0]


后面通过排查发现compress.py 将gt_box的值当成im_id出入导致报错，
在第79行新增outs.append(data['im_id']) 解决问题

![QQ图片20191120204048](https://user-images.githubusercontent.com/56528375/69239822-0e5b6900-0bd6-11ea-9fa2-ee8d95eb183d.png)



Discussion:
@liu36259069 感谢反馈，我们修复下~

Resolving patch:
diff --git a/slim/prune/compress.py b/slim/prune/compress.py
--- a/slim/prune/compress.py
+++ b/slim/prune/compress.py
@@ -52,7 +52,7 @@ def set_paddle_flags(**kwargs):
 logger = logging.getLogger(__name__)
 
 
-def eval_run(exe, compile_program, reader, keys, values, cls, test_feed):
+def eval_run(exe, compile_program, reader, keys, values, cls, test_feed, cfg):
     """
     Run evaluation program, return program outputs.
     """
@@ -75,9 +75,16 @@ def eval_run(exe, compile_program, reader, keys, values, cls, test_feed):
                        feed=feed_data,
                        fetch_list=[values[0]],
                        return_numpy=False)
-        outs.append(data['gt_box'])
-        outs.append(data['gt_label'])
-        outs.append(data['is_difficult'])
+
+        if cfg.metric == 'VOC':
+            outs.append(data['gt_box'])
+            outs.append(data['gt_label'])
+            outs.append(data['is_difficult'])
+        elif cfg.metric == 'COCO':
+            outs.append(data['im_info'])
+            outs.append(data['im_id'])
+            outs.append(data['im_shape'])
+
         res = {
             k: (np.array(v), v.recursive_sequence_lengths())
             for k, v in zip(keys, outs)
@@ -195,7 +202,7 @@ def eval_func(program, scope):
         #place = fluid.CPUPlace()
         #exe = fluid.Executor(place)
         results = eval_run(exe, program, eval_reader, eval_keys, eval_values,
-                           eval_cls, test_data_feed)
+                           eval_cls, test_data_feed, cfg)
 
         resolution = None
         if 'mask' in results[0]:


Test patch: