Repository: open-mmlab/mmsegmentation

Issue:
“show_result()” Function error: ValueError: operands could not be broadcast together with shapes (1600,1600,3) (512,512,3)
**Describe the bug**
when i ran tools/test.py to test your trained PSPnet model with single GPU on ade20k, an error occured in show_result()

**Reproduction**
1. What command or script did you run?
```
python tools/test.py configs/pspnet/pspnet_r50-d8_512x512_80k_ade20k.py checkpoints/pspnet_r50-d8_512x512_80k_ade20k_20200615_014128-15a8b914.pth --show
```

**Error traceback**
```
Traceback (most recent call last):
  File "tools/test.py", line 142, in <module>
    main()
  File "tools/test.py", line 120, in main
    outputs = single_gpu_test(model, data_loader, args.show, args.show_dir)
  File "/root/code/mmsegmentation/mmseg/apis/test.py", line 62, in single_gpu_test
    out_file=out_file)
  File "/root/code/mmsegmentation/mmseg/models/segmentors/base.py", line 253, in show_result
    img = img * 0.5 + color_seg * 0.5
ValueError: operands could not be broadcast together with shapes (1600,1600,3) (512,512,3)
```


Discussion:

Resolving patch:
diff --git a/mmseg/datasets/cityscapes.py b/mmseg/datasets/cityscapes.py
--- a/mmseg/datasets/cityscapes.py
+++ b/mmseg/datasets/cityscapes.py
@@ -173,7 +173,7 @@ def _evaluate_cityscapes(self, results, logger, imgfile_prefix):
         try:
             import cityscapesscripts.evaluation.evalPixelLevelSemanticLabeling as CSEval  # noqa
         except ImportError:
-            raise ImportError('Please run "pip install citscapesscripts" to '
+            raise ImportError('Please run "pip install cityscapesscripts" to '
                               'install cityscapesscripts first.')
         msg = 'Evaluating in Cityscapes style'
         if logger is None:
diff --git a/mmseg/models/segmentors/encoder_decoder.py b/mmseg/models/segmentors/encoder_decoder.py
--- a/mmseg/models/segmentors/encoder_decoder.py
+++ b/mmseg/models/segmentors/encoder_decoder.py
@@ -195,8 +195,10 @@ def slide_inference(self, img, img_meta, rescale):
 
                 count_mat[:, :, y1:y2, x1:x2] += 1
         assert (count_mat == 0).sum() == 0
-        # We want to regard count_mat as a constant while exporting to ONNX
-        count_mat = torch.from_numpy(count_mat.detach().numpy())
+        if torch.onnx.is_in_onnx_export():
+            # cast count_mat to constant while exporting to ONNX
+            count_mat = torch.from_numpy(
+                count_mat.cpu().detach().numpy()).to(device=img.device)
         preds = preds / count_mat
         if rescale:
             preds = resize(
diff --git a/tools/train.py b/tools/train.py
--- a/tools/train.py
+++ b/tools/train.py
@@ -19,7 +19,7 @@
 def parse_args():
     parser = argparse.ArgumentParser(description='Train a segmentor')
     parser.add_argument('config', help='train config file path')
-    parser.add_argument('--work_dir', help='the dir to save logs and models')
+    parser.add_argument('--work-dir', help='the dir to save logs and models')
     parser.add_argument(
         '--load-from', help='the checkpoint file to load weights from')
     parser.add_argument(


Test patch:
diff --git a/mmseg/apis/test.py b/mmseg/apis/test.py
--- a/mmseg/apis/test.py
+++ b/mmseg/apis/test.py
@@ -30,7 +30,7 @@ def single_gpu_test(model, data_loader, show=False, out_dir=None):
     prog_bar = mmcv.ProgressBar(len(dataset))
     for i, data in enumerate(data_loader):
         with torch.no_grad():
-            result = model(return_loss=False, rescale=not show, **data)
+            result = model(return_loss=False, **data)
         if isinstance(results, list):
             results.extend(result)
         else: