Repository: PaddlePaddle/PaddleDetection

Issue:
快速开始的第二步就走不通
下载PaddleDetection
下载数据集
什么都没改都走不通。
报错信息：
`Traceback (most recent call last):
  File "tools/train.py", line 137, in <module>
    main()
  File "tools/train.py", line 133, in main
    run(FLAGS, cfg)
  File "tools/train.py", line 111, in run
    trainer.train(FLAGS.eval)
  File "/home/jp/lihaibaoProjects/tmp/new_projects/demo/ppdet/engine/trainer.py", line 274, in train
    outputs = model(data)
  File "/home/jp/.conda/envs/lihaibao_tfp/lib/python3.7/site-packages/paddle/fluid/dygraph/layers.py", line 902, in __call__
    outputs = self.forward(*inputs, **kwargs)
  File "/home/jp/lihaibaoProjects/tmp/new_projects/demo/ppdet/modeling/architectures/meta_arch.py", line 27, in forward
    out = self.get_loss()
  File "/home/jp/lihaibaoProjects/tmp/new_projects/demo/ppdet/modeling/architectures/yolo.py", line 72, in get_loss
    return self._forward()
  File "/home/jp/lihaibaoProjects/tmp/new_projects/demo/ppdet/modeling/architectures/yolo.py", line 59, in _forward
    body_feats = self.backbone(self.inputs)
  File "/home/jp/.conda/envs/lihaibao_tfp/lib/python3.7/site-packages/paddle/fluid/dygraph/layers.py", line 902, in __call__
    outputs = self.forward(*inputs, **kwargs)
  File "/home/jp/lihaibaoProjects/tmp/new_projects/demo/ppdet/modeling/backbones/mobilenet_v1.py", line 391, in forward
    y = self.conv1(inputs['image'])
  File "/home/jp/.conda/envs/lihaibao_tfp/lib/python3.7/site-packages/paddle/fluid/dygraph/layers.py", line 902, in __call__
    outputs = self.forward(*inputs, **kwargs)
  File "/home/jp/lihaibaoProjects/tmp/new_projects/demo/ppdet/modeling/backbones/mobilenet_v1.py", line 76, in forward
    x = self._batch_norm(x)
  File "/home/jp/.conda/envs/lihaibao_tfp/lib/python3.7/site-packages/paddle/fluid/dygraph/layers.py", line 902, in __call__
    outputs = self.forward(*inputs, **kwargs)
  File "/home/jp/.conda/envs/lihaibao_tfp/lib/python3.7/site-packages/paddle/nn/layer/norm.py", line 1058, in forward
    variance_out, *attrs)
RuntimeError: (NotFound) Operator sync_batch_norm does not have kernel for data_type[float]:data_layout[ANY_LAYOUT]:place[CPUPlace]:library_type[PLAIN].
  [Hint: Expected kernel_iter != kernels.end(), but received kernel_iter == kernels.end().] (at /paddle/paddle/fluid/imperative/prepared_operator.cc:128)
  [operator < sync_batch_norm > error]
`


Discussion:
（1）请问您是用的是CPU训练的吗？您使用的Paddle 版本，ppdet版本分别是多少呢？
（2）sync_batch_norm 在CPU上报错是已知问题，建议您用GPU试一下。[AIStudio](https://aistudio.baidu.com/aistudio/index) 上有免费GPU可以使用，且环境是配置好的，建议您使用一下看看。
如果使用cpu训练，需要设置norm_type为bn，如下所示：
python tools/train.py -c configs/ppyolo/ppyolo_r50vd_dcn_1x_coco.yml -o use_gpu=false norm_type=bn

Resolving patch:
diff --git a/tools/eval.py b/tools/eval.py
--- a/tools/eval.py
+++ b/tools/eval.py
@@ -117,6 +117,9 @@ def main():
 
     place = paddle.set_device('gpu' if cfg.use_gpu else 'cpu')
 
+    if 'norm_type' in cfg and cfg['norm_type'] == 'sync_bn' and not cfg.use_gpu:
+        cfg['norm_type'] = 'bn'
+
     if FLAGS.slim_config:
         cfg = build_slim_model(cfg, FLAGS.slim_config, mode='eval')
 
diff --git a/tools/infer.py b/tools/infer.py
--- a/tools/infer.py
+++ b/tools/infer.py
@@ -141,6 +141,9 @@ def main():
 
     place = paddle.set_device('gpu' if cfg.use_gpu else 'cpu')
 
+    if 'norm_type' in cfg and cfg['norm_type'] == 'sync_bn' and not cfg.use_gpu:
+        cfg['norm_type'] = 'bn'
+
     if FLAGS.slim_config:
         cfg = build_slim_model(cfg, FLAGS.slim_config, mode='test')
 
diff --git a/tools/train.py b/tools/train.py
--- a/tools/train.py
+++ b/tools/train.py
@@ -123,6 +123,9 @@ def main():
 
     place = paddle.set_device('gpu' if cfg.use_gpu else 'cpu')
 
+    if 'norm_type' in cfg and cfg['norm_type'] == 'sync_bn' and not cfg.use_gpu:
+        cfg['norm_type'] = 'bn'
+
     if FLAGS.slim_config:
         cfg = build_slim_model(cfg, FLAGS.slim_config)
 


Test patch: