open-mmlab/mmtracking

RuntimeError: indices should be either on cpu or on the same device as the indexed tensor (cpu)

ayasaki0407 opened this issue · 1 comments

Thanks for your error report and we appreciate it a lot.

Checklist

  1. I have searched related issues but cannot get the expected help.
  2. The bug has not been fixed in the latest version.

Describe the bug
I'm trying on "demo/top_down_pose_tracking_demo_with_mmtracking.py" in MMPose. In this script, it uses MMTracking.

Reproduction

  1. What command or script did you run?
python demo/top_down_pose_tracking_demo_with_mmtracking.py demo/mmtracking_cfg/tracktor_faster-rcnn_r50_fpn_4e_mot17-private.py configs/body/2d_kpt_sview_rgb_vid/posewarper/posetrack18/hrnet_w48_posetrack18_384x288_posewarper_stage2.py https://download.openmmlab.com/mmpose/top_down/posewarper/hrnet_w48_posetrack18_384x288_posewarper_stage2-4abf88db_20211130.pth --video-path demo/resources/demo.mp4 --out-video-root vis_results --use-multi-frames --online --device=cuda:0
  1. Did you make any modifications on the code or config? Did you understand what you have modified?
    No. I tried a demo script for check the function.

  2. What dataset did you use and what task did you run?
    I am presented with a completed model. I just run demo script and command.

Environment

  1. Please run python mmtrack/utils/collect_env.py to collect necessary environment information and paste it here.
    fatal: not a git repository (or any of the parent directories): .git
    sys.platform: win32
    Python: 3.8.6 (tags/v3.8.6:db45529, Sep 23 2020, 15:52:53) [MSC v.1927 64 bit (AMD64)]
    CUDA available: True
    GPU 0: NVIDIA GeForce RTX 3070
    CUDA_HOME: C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.7
    NVCC: Cuda compilation tools, release 11.7, V11.7.64
    MSVC: Microsoft(R) C/C++ Optimizing Compiler Version 19.34.31935 for x64
    GCC: n/a
    PyTorch: 2.0.0+cu117
    PyTorch compiling details: PyTorch built with:
  • C++ Version: 199711
  • MSVC 193431937
  • Intel(R) Math Kernel Library Version 2020.0.2 Product Build 20200624 for Intel(R) 64 architecture applications
  • Intel(R) MKL-DNN v2.7.3 (Git Hash 6dbeffbae1f23cbbeae17adb7b5b13f1f37c080e)
  • OpenMP 2019
  • LAPACK is enabled (usually provided by MKL)
  • CPU capability usage: AVX2
  • CUDA Runtime 11.7
  • 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.5
  • Magma 2.5.4
  • Build settings: BLAS_INFO=mkl, BUILD_TYPE=Release, CUDA_VERSION=11.7, CUDNN_VERSION=8.5.0, CXX_COMPILER=C:/actions-runner/_work/pytorch/pytorch/builder/windows/tmp_bin/sccache-cl.exe, CXX_FLAGS=/DWIN32 /D_WINDOWS /GR /EHsc /w /bigobj /FS -DUSE_PTHREADPOOL -DNDEBUG -DUSE_KINETO -DLIBKINETO_NOCUPTI -DLIBKINETO_NOROCTRACER -DUSE_FBGEMM -DUSE_XNNPACK -DSYMBOLICATE_MOBILE_DEBUG_HANDLE, LAPACK_INFO=mkl, PERF_WITH_AVX=1, PERF_WITH_AVX2=1, PERF_WITH_AVX512=1, TORCH_DISABLE_GPU_ASSERTS=OFF, TORCH_VERSION=2.0.0, 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=OFF, USE_NNPACK=OFF, USE_OPENMP=ON, USE_ROCM=OFF,

TorchVision: 0.15.1+cu117
OpenCV: 4.7.0
MMCV: 1.6.2
MMCV Compiler: MSVC 193431935
MMCV CUDA Compiler: 11.7
MMTracking: 0.14.0+

  1. You may add addition that may be helpful for locating the problem, such as
    • How you installed PyTorch [e.g., pip, conda, source]
    • Other environment variables that may be related (such as $PATH, $LD_LIBRARY_PATH, $PYTHONPATH, etc.)
      I also install MMPose. I attach MMPose's enviroment below.

'sys.platform': 'win32', 'Python': '3.8.6 (tags/v3.8.6:db45529, Sep 23 2020, 15:52:53) [MSC v.1927 64 bit (AMD64)]', 'CUDA available': True, 'GPU 0': 'NVIDIA GeForce RTX 3070', 'CUDA_HOME': 'C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.7', 'NVCC': 'Cuda compilation tools, release 11.7, V11.7.64', 'MSVC': 'Microsoft(R) C/C++ Optimizing Compiler Version 19.34.31935 for x64', 'GCC': 'n/a', 'PyTorch': '2.0.0+cu117', 'PyTorch compiling details': 'PyTorch built with:\n - C++ Version: 199711\n - MSVC 193431937\n - Intel(R) Math Kernel Library Version 2020.0.2 Product Build 20200624 for Intel(R) 64 architecture applications\n - Intel(R) MKL-DNN v2.7.3 (Git Hash 6dbeffbae1f23cbbeae17adb7b5b13f1f37c080e)\n - OpenMP 2019\n - LAPACK is enabled (usually provided by MKL)\n - CPU capability usage: AVX2\n - CUDA Runtime 11.7\n - 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\n - CuDNN 8.5\n - Magma 2.5.4\n - Build settings: BLAS_INFO=mkl, BUILD_TYPE=Release, CUDA_VERSION=11.7, CUDNN_VERSION=8.5.0, CXX_COMPILER=C:/actions-runner/_work/pytorch/pytorch/builder/windows/tmp_bin/sccache-cl.exe, CXX_FLAGS=/DWIN32 /D_WINDOWS /GR /EHsc /w /bigobj /FS -DUSE_PTHREADPOOL -DNDEBUG -DUSE_KINETO -DLIBKINETO_NOCUPTI -DLIBKINETO_NOROCTRACER -DUSE_FBGEMM -DUSE_XNNPACK -DSYMBOLICATE_MOBILE_DEBUG_HANDLE, LAPACK_INFO=mkl, PERF_WITH_AVX=1, PERF_WITH_AVX2=1, PERF_WITH_AVX512=1, TORCH_DISABLE_GPU_ASSERTS=OFF, TORCH_VERSION=2.0.0, 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=OFF, USE_NNPACK=OFF, USE_OPENMP=ON, USE_ROCM=OFF, \n', 'TorchVision': '0.15.1+cu117', 'OpenCV': '4.7.0', 'MMCV': '1.6.2', 'MMCV Compiler': 'MSVC 193431935', 'MMCV CUDA Compiler': '11.7', 'MMPose': '0.29.0+21aeeb4'

mmcls 0.25.0
mmcv-full 1.6.2
mmdet 2.28.2
mmpose 0.29.0
mmtrack 0.14.0

Error traceback
If applicable, paste the error trackback here.

C:\Users\student\Documents\hayashima\MMPose_Tracking\venv\lib\site-packages\scipy_init_.py:146: UserWarning: A NumPy version >=1.16.5 and <1.23.0 is required for this version of SciPy (detected version 1.24.3
warnings.warn(f"A NumPy version >={np_minversion} and <{np_maxversion}"
Initializing model...
c:\users\student\documents\hayashima\mmpose_tracking\mmtracking\mmtrack\models\mot\tracktor.py:28: UserWarning: DeprecationWarning: pretrains is deprecated, please use "init_cfg" instead
warnings.warn('DeprecationWarning: pretrains is deprecated, '
2023-05-17 09:34:32,470 - mmtrack - INFO - initialize FasterRCNN with init_cfg {'type': 'Pretrained', 'checkpoint': '[https://download.openmmlab.com/mmtracking/mot/faster_rcnn/faster-rcnn_r50_fpn_4e_mot17-ffa52ae7.pth'}](https://download.openmmlab.com/mmtracking/mot/faster_rcnn/faster-rcnn_r50_fpn_4e_mot17-ffa52ae7.pth'%7D)
2023-05-17 09:34:32,470 - mmcv - INFO - load model from: https://download.openmmlab.com/mmtracking/mot/faster_rcnn/faster-rcnn_r50_fpn_4e_mot17-ffa52ae7.pth
2023-05-17 09:34:32,470 - mmcv - INFO - load checkpoint from http path: https://download.openmmlab.com/mmtracking/mot/faster_rcnn/faster-rcnn_r50_fpn_4e_mot17-ffa52ae7.pth
2023-05-17 09:34:32,564 - mmtrack - INFO - initialize BaseReID with init_cfg {'type': 'Pretrained', 'checkpoint': '[https://download.openmmlab.com/mmtracking/mot/reid/reid_r50_6e_mot17-4bf6b63d.pth'}](https://download.openmmlab.com/mmtracking/mot/reid/reid_r50_6e_mot17-4bf6b63d.pth'%7D)
2023-05-17 09:34:32,564 - mmcv - INFO - load model from: https://download.openmmlab.com/mmtracking/mot/reid/reid_r50_6e_mot17-4bf6b63d.pth
2023-05-17 09:34:32,564 - mmcv - INFO - load checkpoint from http path: https://download.openmmlab.com/mmtracking/mot/reid/reid_r50_6e_mot17-4bf6b63d.pth
Warning: The model doesn't have classes
load checkpoint from http path: https://download.openmmlab.com/mmpose/top_down/posewarper/hrnet_w48_posetrack18_384x288_posewarper_stage2-4abf88db_20211130.pth
Running inference...
[>>>>>>>>>> ] 1/5, 0.2 task/s, elapsed: 4s, ETA: 18sTraceback (most recent call last):
File "demo/top_down_pose_tracking_demo_with_mmtracking.py", line 226, in
main()
File "demo/top_down_pose_tracking_demo_with_mmtracking.py", line 177, in main
mmtracking_results = inference_mot(
File "c:\users\student\documents\hayashima\mmpose_tracking\mmtracking\mmtrack\apis\inference.py", line 122, in inference_mot
result = model(return_loss=False, rescale=True, **data)
File "C:\Users\student\Documents\hayashima\MMPose_Tracking\venv\lib\site-packages\torch\nn\modules\module.py", line 1501, in _call_impl
return forward_call(*args, **kwargs)
File "C:\Users\student\Documents\hayashima\MMPose_Tracking\venv\lib\site-packages\mmcv\runner\fp16_utils.py", line 116, in new_func
return old_func(*args, **kwargs)
File "c:\users\student\documents\hayashima\mmpose_tracking\mmtracking\mmtrack\models\mot\base.py", line 136, in forward
return self.forward_test(img, img_metas, **kwargs)
File "c:\users\student\documents\hayashima\mmpose_tracking\mmtracking\mmtrack\models\mot\base.py", line 113, in forward_test
return self.simple_test(imgs[0], img_metas[0], **kwargs)
File "c:\users\student\documents\hayashima\mmpose_tracking\mmtracking\mmtrack\models\mot\tracktor.py", line 135, in simple_test
track_bboxes, track_labels, track_ids = self.tracker.track(
File "C:\Users\student\Documents\hayashima\MMPose_Tracking\venv\lib\site-packages\mmcv\runner\fp16_utils.py", line 205, in new_func
return old_func(*args, **kwargs)
File "c:\users\student\documents\hayashima\mmpose_tracking\mmtracking\mmtrack\models\trackers\tracktor_tracker.py", line 151, in track
prop_bboxes, prop_labels, prop_ids = self.regress_tracks(
File "c:\users\student\documents\hayashima\mmpose_tracking\mmtracking\mmtrack\models\trackers\tracktor_tracker.py", line 78, in regress_tracks
ids = ids[valid_inds]
RuntimeError: indices should be either on cpu or on the same device as the indexed tensor (cpu)

Bug fix
If you have already identified the reason, you can provide the information here. If you are willing to create a PR to fix it, please also leave a comment here and that would be much appreciated!

我也遇到同样的问题,报错点也是一模一样

运行测试命令: python tools/test.py configs/mot/tracktor/tracktor_faster-rcnn_r50_fpn_4e_mot17-public-half.py --eval track

File "tools/test.py", line 236, in
main()
File "tools/test.py", line 191, in main
show_score_thr=args.show_score_thr)
File "/opt/docker/mmtracking/mmtrack/apis/test.py", line 47, in single_gpu_test
result = model(return_loss=False, rescale=True, **data)
File "/root/anaconda3/envs/open-mmlab/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1194, in _call_impl
return forward_call(*input, **kwargs)
File "/root/anaconda3/envs/open-mmlab/lib/python3.7/site-packages/mmcv/parallel/data_parallel.py", line 51, in forward
return super().forward(*inputs, **kwargs)
File "/root/anaconda3/envs/open-mmlab/lib/python3.7/site-packages/torch/nn/parallel/data_parallel.py", line 169, in forward
return self.module(*inputs[0], **kwargs[0])
File "/root/anaconda3/envs/open-mmlab/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1194, in _call_impl
return forward_call(*input, **kwargs)
File "/root/anaconda3/envs/open-mmlab/lib/python3.7/site-packages/mmcv/runner/fp16_utils.py", line 116, in new_func
return old_func(*args, **kwargs)
File "/opt/docker/mmtracking/mmtrack/models/mot/base.py", line 136, in forward
return self.forward_test(img, img_metas, **kwargs)
File "/opt/docker/mmtracking/mmtrack/models/mot/base.py", line 113, in forward_test
return self.simple_test(imgs[0], img_metas[0], **kwargs)
File "/opt/docker/mmtracking/mmtrack/models/mot/tracktor.py", line 144, in simple_test
**kwargs)
File "/root/anaconda3/envs/open-mmlab/lib/python3.7/site-packages/mmcv/runner/fp16_utils.py", line 205, in new_func
return old_func(*args, **kwargs)
File "/opt/docker/mmtracking/mmtrack/models/trackers/tracktor_tracker.py", line 152, in track
feats, img_metas, model.detector, frame_id, rescale)
File "/opt/docker/mmtracking/mmtrack/models/trackers/tracktor_tracker.py", line 78, in regress_tracks
ids = ids[valid_inds]
RuntimeError: indices should be either on cpu or on the same device as the indexed tensor (cpu)

应该是哪里配置的问题,我先这样先绕过去了,现在能运行了

diff --git a/mmtrack/models/trackers/tracktor_tracker.py b/mmtrack/models/trackers/tracktor_tracker.py
index 4ce79ae..bddea13 100644
--- a/mmtrack/models/trackers/tracktor_tracker.py
+++ b/mmtrack/models/trackers/tracktor_tracker.py
@@ -75,9 +75,11 @@ class TracktorTracker(BaseTracker):
             0,
             self.regression['nms'],
             return_inds=True)
-        ids = ids[valid_inds]

+        valid_inds = valid_inds.to(ids.device)
+        ids = ids[valid_inds]
         valid_inds = track_bboxes[:, -1] > self.regression['obj_score_thr']
+        valid_inds = valid_inds.to(ids.device)
         return track_bboxes[valid_inds], track_labels[valid_inds], ids[
             valid_inds]