Repository: PaddlePaddle/PaddleDetection

Issue:
训练centernet报错
使用python tool/train.py -c configs/centernet/centernet_dla34_140e_coco.yml --eval，报错如下

Traceback (most recent call last):
  File "tools/train.py", line 171, in <module>
    main()
  File "tools/train.py", line 167, in main
    run(FLAGS, cfg)
  File "tools/train.py", line 127, in run
    trainer.train(FLAGS.eval)
  File "/home/yilin/project/PaddleDetection2.3/ppdet/engine/trainer.py", line 393, in train
    outputs = model(data)
  File "/home/yilin/software/anaconda3/envs/paddle2/lib/python3.7/site-packages/paddle/fluid/dygraph/layers.py", line 914, in __call__
    outputs = self.forward(*inputs, **kwargs)
  File "/home/yilin/project/PaddleDetection2.3/ppdet/modeling/architectures/meta_arch.py", line 54, in forward
    out = self.get_loss()
  File "/home/yilin/project/PaddleDetection2.3/ppdet/modeling/architectures/centernet.py", line 108, in get_loss
    return self._forward()
  File "/home/yilin/project/PaddleDetection2.3/ppdet/modeling/architectures/centernet.py", line 72, in _forward
    head_out = self.head(neck_feat, self.inputs)
  File "/home/yilin/software/anaconda3/envs/paddle2/lib/python3.7/site-packages/paddle/fluid/dygraph/layers.py", line 914, in __call__
    outputs = self.forward(*inputs, **kwargs)
  File "/home/yilin/project/PaddleDetection2.3/ppdet/modeling/heads/centernet_head.py", line 163, in forward
    inputs, self.weights, heatmap, size, offset, iou=iou)
  File "/home/yilin/project/PaddleDetection2.3/ppdet/modeling/heads/centernet_head.py", line 205, in get_loss
    2:]
  File "/home/yilin/software/anaconda3/envs/paddle2/lib/python3.7/site-packages/paddle/fluid/dygraph/varbase_patch_methods.py", line 598, in __getitem__
    return self._getitem_index_not_tensor(item)
ValueError: (InvalidArgument) When step > 0, end should be greater than start, but received end = 2, start = 2.
  [Hint: Expected end > start, but received end:2 <= start:2.] (at /paddle/paddle/fluid/operators/slice_utils.h:59)
  [operator < slice > error]





Discussion:
请问您使用的ppdet的版本是多少？运行命令是什么呢？
ppdet的版本是2.3 paddlepaddle的版本是paddlepaddle_gpu-2.2.0.post101-cp37-cp37m-linux_x86_64，运行的命令是python tool/train.py -c configs/centernet/centernet_dla34_140e_coco.yml --eval

Resolving patch:
diff --git a/ppdet/modeling/heads/centernet_head.py b/ppdet/modeling/heads/centernet_head.py
--- a/ppdet/modeling/heads/centernet_head.py
+++ b/ppdet/modeling/heads/centernet_head.py
@@ -201,9 +201,14 @@ def get_loss(self, inputs, weights, heatmap, size, offset, iou=None):
                 size_target = inputs['size']
                 # shape: [bs, max_per_img, 4]
             else:
-                size_target = inputs['size'][:, :, 0:2] + inputs['size'][:, :,
-                                                                         2:]
-                # shape: [bs, max_per_img, 2]
+                if inputs['size'].shape[-1] == 2:
+                    # inputs['size'] is wh, and regress as wh
+                    # shape: [bs, max_per_img, 2]
+                    size_target = inputs['size']
+                else:
+                    # inputs['size'] is ltrb, but regress as wh
+                    # shape: [bs, max_per_img, 4]
+                    size_target = inputs['size'][:, :, 0:2] + inputs['size'][:, :, 2:]
 
             size_target.stop_gradient = True
             size_loss = F.l1_loss(


Test patch: