Repository: open-mmlab/mmdetection

Issue:
Error during testing on MS-RCNN on single-machine-multiple-gpu
**Describe the bug**
I'm performing test on MS-RCNN model, but during the single-machine test. I'm facing the following issue.

**Reproduction**
1. What command or script did you run?

```
python tools/test.py configs/ms_rcnn/ms_rcnn_x101_32x4d_fpn_1x_coco.py \
    /ssd_scratch/cvit/dksingh/mmdetection_logs/ms_rcnn_x101_32x4d_fpn_1x_coco/epoch_4.pth \
    --show-dir=./ms_rcnn_results/
```
2. Did you make any modifications on the code or config? Did you understand what you have modified?
No
3. What dataset did you use?
COCO-2017
**Environment**
```
sys.platform: linux
Python: 3.7.7 (default, May  7 2020, 21:25:33) [GCC 7.3.0]
CUDA available: True
CUDA_HOME: /usr/local/cuda
NVCC: Cuda compilation tools, release 10.2, V10.2.89
GPU 0,1,2,3: GeForce GTX 1080 Ti
GCC: gcc (Ubuntu 5.5.0-12ubuntu1~16.04) 5.5.0 20171010
PyTorch: 1.5.0
PyTorch compiling details: PyTorch built with:
  - GCC 7.3
  - C++ Version: 201402
  - Intel(R) Math Kernel Library Version 2020.0.1 Product Build 20200208 for Intel(R) 64 architecture applications
  - Intel(R) MKL-DNN v0.21.1 (Git Hash 7d2fd500bc78936d1d648ca713b901012f470dbc)
  - OpenMP 201511 (a.k.a. OpenMP 4.5)
  - NNPACK is enabled
  - CPU capability usage: AVX2
  - CUDA Runtime 10.2
  - NVCC architecture flags: -gencode;arch=compute_37,code=sm_37;-gencode;arch=compute_50,code=sm_50;-gencode;arch=compute_60,code=sm_60;-gencode;arch=compute_61,code=sm_61;-gencode;arch=compute_70,code=sm_70;-gencode;arch=compute_75,code=sm_75;-gencode;arch=compute_37,code=compute_37
  - CuDNN 7.6.5
  - Magma 2.5.2
  - Build settings: BLAS=MKL, BUILD_TYPE=Release, CXX_FLAGS= -Wno-deprecated -fvisibility-inlines-hidden -fopenmp -DNDEBUG -DUSE_FBGEMM -DUSE_QNNPACK -DUSE_PYTORCH_QNNPACK -DUSE_XNNPACK -DUSE_INTERNAL_THREADPOOL_IMPL -O2 -fPIC -Wno-narrowing -Wall -Wextra -Werror=return-type -Wno-missing-field-initializers -Wno-type-limits -Wno-array-bounds -Wno-unknown-pragmas -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wno-unused-function -Wno-unused-result -Wno-strict-overflow -Wno-strict-aliasing -Wno-error=deprecated-declarations -Wno-stringop-overflow -Wno-error=pedantic -Wno-error=redundant-decls -Wno-error=old-style-cast -fdiagnostics-color=always -faligned-new -Wno-unused-but-set-variable -Wno-maybe-uninitialized -fno-math-errno -fno-trapping-math -Werror=format -Wno-stringop-overflow, PERF_WITH_AVX=1, PERF_WITH_AVX2=1, PERF_WITH_AVX512=1, USE_CUDA=ON, USE_EXCEPTION_PTR=1, USE_GFLAGS=OFF, USE_GLOG=OFF, USE_MKL=ON, USE_MKLDNN=ON, USE_MPI=OFF, USE_NCCL=ON, USE_NNPACK=ON, USE_OPENMP=ON, USE_STATIC_DISPATCH=OFF, 

TorchVision: 0.6.0a0+82fd1c8
OpenCV: 4.2.0
MMCV: 0.5.1
MMDetection: 2.0.0+c802b17
MMDetection Compiler: GCC 5.5
MMDetection CUDA Compiler: 10.2

```

**Error traceback**

```
python tools/test.py configs/ms_rcnn/ms_rcnn_x101_32x4d_fpn_1x_coco.py \
>     /ssd_scratch/cvit/dksingh/mmdetection_logs/ms_rcnn_x101_32x4d_fpn_1x_coco/epoch_4.pth \
>     --show-dir=./msrcnn_test_results/
loading annotations into memory...
Done (t=0.45s)
creating index...
index created!
[                                                  ] 0/5000, elapsed: 0s, ETA:Traceback (most recent call last):
  File "tools/test.py", line 149, in <module>
    main()
  File "tools/test.py", line 127, in main
    args.show_score_thr)
  File "/home/dksingh/sandbox/mmdetection/mmdet/apis/test.py", line 79, in single_gpu_test
    score_thr=show_score_thr)
  File "/home/dksingh/sandbox/mmdetection/mmdet/models/detectors/base.py", line 212, in show_result
    img[mask] = img[mask] * 0.5 + color_mask * 0.5
IndexError: boolean index did not match indexed array along dimension 2; dimension is 3 but corresponding boolean dimension is 2
```


Discussion:
I think the command 
```
python tools/test.py configs/ms_rcnn/ms_rcnn_x101_32x4d_fpn_1x_coco.py \
    /ssd_scratch/cvit/dksingh/mmdetection_logs/ms_rcnn_x101_32x4d_fpn_1x_coco/epoch_4.pth \
    --show-dir
```
evaluates for object detection models only.

When i run:
```
./tools/dist_test.sh configs/ms_rcnn/ms_rcnn_x101_32x4d_fpn_1x_coco.py /ssd_scratch/cvit/dksingh/mmdetection_logs/ms_rcnn_x101_32x4d_fpn_1x_coco/epoch_4.pth 4 --eval bbox segm
```
It works without any problem.

Should i close the issue?

Resolving patch:
diff --git a/mmdet/models/detectors/base.py b/mmdet/models/detectors/base.py
--- a/mmdet/models/detectors/base.py
+++ b/mmdet/models/detectors/base.py
@@ -188,6 +188,8 @@ def show_result(self,
         img = img.copy()
         if isinstance(result, tuple):
             bbox_result, segm_result = result
+            if isinstance(segm_result, tuple):
+                segm_result = segm_result[0]  # ms rcnn
         else:
             bbox_result, segm_result = result, None
         bboxes = np.vstack(bbox_result)
@@ -197,7 +199,7 @@ def show_result(self,
         ]
         labels = np.concatenate(labels)
         # draw segmentation masks
-        if segm_result is not None:
+        if segm_result is not None and len(labels) > 0:  # non empty
             segms = mmcv.concat_list(segm_result)
             inds = np.where(bboxes[:, -1] > score_thr)[0]
             np.random.seed(42)


Test patch: