Repository: open-mmlab/mmaction2

Issue:
ssn_head.py device unaligned
**Describe the bug**

I trained a SSN successfully on a new dataset. But when I test the checkpoint, an error raised. And I think it's a inner bug.


**Reproduction**

1. What command or script did you run?

```
PYTHONPATH=$PWD:$PYTHONPATH mim test mmaction configs/localization/ssn/ssn_r50_450e_dfmad_rgb_test.py --checkpoint work_dirs/ssn_r50_450e_dfmad_rgb/latest.pth --gpus 1 --eval mAP
```


**Environment**
```
sys.platform: linux
Python: 3.9.7 (default, Sep 16 2021, 13:09:58) [GCC 7.5.0]
CUDA available: True
GPU 0,1: NVIDIA GeForce RTX 2080 Ti
CUDA_HOME: /usr/local/cuda
NVCC: Build cuda_11.5.r11.5/compiler.30672275_0
GCC: gcc (Ubuntu 8.4.0-3ubuntu2) 8.4.0
PyTorch: 1.10.1
PyTorch compiling details: PyTorch built with:
  - GCC 7.3
  - C++ Version: 201402
  - Intel(R) oneAPI Math Kernel Library Version 2021.4-Product Build 20210904 for Intel(R) 64 architecture applications
  - Intel(R) MKL-DNN v2.2.3 (Git Hash 7336ca9f055cf1bfa13efb658fe15dc9b41f0740)
  - OpenMP 201511 (a.k.a. OpenMP 4.5)
  - LAPACK is enabled (usually provided by MKL)
  - NNPACK is enabled
  - CPU capability usage: AVX2
  - CUDA Runtime 11.3
  - 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_80,code=sm_80;-gencode;arch=compute_86,code=sm_86;-gencode;arch=compute_37,code=compute_37
  - CuDNN 8.2
  - Magma 2.5.2
  - Build settings: BLAS_INFO=mkl, BUILD_TYPE=Release, CUDA_VERSION=11.3, CUDNN_VERSION=8.2.0, CXX_COMPILER=/opt/rh/devtoolset-7/root/usr/bin/c++, CXX_FLAGS= -Wno-deprecated -fvisibility-inlines-hidden -DUSE_PTHREADPOOL -fopenmp -DNDEBUG -DUSE_KINETO -DUSE_FBGEMM -DUSE_QNNPACK -DUSE_PYTORCH_QNNPACK -DUSE_XNNPACK -DSYMBOLICATE_MOBILE_DEBUG_HANDLE -DEDGE_PROFILER_USE_KINETO -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-unused-local-typedefs -Wno-strict-overflow -Wno-strict-aliasing -Wno-error=deprecated-declarations -Wno-stringop-overflow -Wno-psabi -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, LAPACK_INFO=mkl, PERF_WITH_AVX=1, PERF_WITH_AVX2=1, PERF_WITH_AVX512=1, TORCH_VERSION=1.10.1, USE_CUDA=ON, USE_CUDNN=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, 

TorchVision: 0.11.2
OpenCV: 4.5.4
MMCV: 1.4.1
MMCV Compiler: GCC 7.3
MMCV CUDA Compiler: 11.3
MMAction2: 0.20.0+3758171
```

**Error traceback**
```shell
Testing command is python /home/louis/miniconda3/envs/open-mmlab/lib/python3.9/site-packages/mmaction/.mim/tools/test.py configs/localization/ssn/ssn_r50_450e_dfmad_rgb_test.py work_dirs/ssn_r50_450e_dfmad_rgb/latest.pth --launcher none --eval mAP. 
2021-12-24 12:03:40,264 - mmaction - INFO - 13 out of 13 videos are valid.
2021-12-24 12:03:40,290 - mmaction - INFO - SSNDataset: proposal file my_data/dfmad70/proposals/dfmad_bmn_test_100_proposal_list.txt parsed.
load checkpoint from local path: work_dirs/ssn_r50_450e_dfmad_rgb/latest.pth
[                                                  ] 0/13, elapsed: 0s, ETA:Traceback (most recent call last):
  File "/home/louis/miniconda3/envs/open-mmlab/lib/python3.9/site-packages/mmaction/.mim/tools/test.py", line 365, in <module>
    main()
  File "/home/louis/miniconda3/envs/open-mmlab/lib/python3.9/site-packages/mmaction/.mim/tools/test.py", line 350, in main
    outputs = inference_pytorch(args, cfg, distributed, data_loader)
  File "/home/louis/miniconda3/envs/open-mmlab/lib/python3.9/site-packages/mmaction/.mim/tools/test.py", line 161, in inference_pytorch
    outputs = single_gpu_test(model, data_loader)
  File "/home/louis/miniconda3/envs/open-mmlab/lib/python3.9/site-packages/mmcv/engine/test.py", line 33, in single_gpu_test
    result = model(return_loss=False, **data)
  File "/home/louis/miniconda3/envs/open-mmlab/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1102, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/louis/miniconda3/envs/open-mmlab/lib/python3.9/site-packages/mmcv/parallel/data_parallel.py", line 50, in forward
    return super().forward(*inputs, **kwargs)
  File "/home/louis/miniconda3/envs/open-mmlab/lib/python3.9/site-packages/torch/nn/parallel/data_parallel.py", line 166, in forward
    return self.module(*inputs[0], **kwargs[0])
  File "/home/louis/miniconda3/envs/open-mmlab/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1102, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/louis/miniconda3/envs/open-mmlab/lib/python3.9/site-packages/mmaction/models/localizers/base.py", line 166, in forward
    return self.forward_test(*args, **kwargs)
  File "/home/louis/miniconda3/envs/open-mmlab/lib/python3.9/site-packages/mmaction/models/localizers/ssn.py", line 120, in forward_test
    bbox_preds[:, :, 0] * reg_norm_consts[1, 0] +
RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!
```

**Bug fix**
the bug come from here:
https://github.com/open-mmlab/mmaction2/blob/6f98109b682c5689dc0548a98b89ed1c3b956ddb/mmaction/models/localizers/ssn.py#L114-L121
We can see that all tensor are transformed to ``cpu().numpy()`` except the ``reg_norm_consts``.
Adding the below line solved the error:
```python
reg_norm_consts = reg_norm_consts.cpu().numpy()
```
I'd like to create a PR if need.


Discussion:
welcome for PR to fix it

Resolving patch:
diff --git a/mmaction/models/localizers/ssn.py b/mmaction/models/localizers/ssn.py
--- a/mmaction/models/localizers/ssn.py
+++ b/mmaction/models/localizers/ssn.py
@@ -114,6 +114,7 @@ def forward_test(self, imgs, relative_proposal_list, scale_factor_list,
         relative_proposal_list = relative_proposal_list.cpu().numpy()
         activity_scores = activity_scores.cpu().numpy()
         completeness_scores = completeness_scores.cpu().numpy()
+        reg_norm_consts = reg_norm_consts.cpu().numpy()
         if bbox_preds is not None:
             bbox_preds = bbox_preds.view(-1, self.cls_head.num_classes, 2)
             bbox_preds[:, :, 0] = (


Test patch: