You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows11下MMDetection3D环境验证报错:torch._C无_cuda_setDevice属性

问题解决:AttributeError: module 'torch._C' has no attribute '_cuda_setDevice'

问题场景

在Windows11系统中,通过Miniconda创建并激活conda环境,使用MIM安装PyTorch及MMEngine、MMCV、MMDetection、MMDetection3D等依赖包,成功下载PointPillars的配置与权重文件后,运行验证代码时触发该错误,错误源于torch.cuda.set_device调用失败。

解决方案

1. 验证PyTorch的CUDA支持状态

先确认当前环境的PyTorch是否启用CUDA支持:

import torch
print(torch.cuda.is_available())

如果输出False,说明安装的是CPU版本PyTorch,这是导致错误的核心原因。

2. 重新安装带CUDA的PyTorch版本

根据MMDetection3D的版本要求,选择兼容的PyTorch与CUDA组合(例如PyTorch 2.0 + CUDA 11.7),使用MIM重新安装:

mim install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu117

安装完成后再次运行torch.cuda.is_available()确认是否返回True。

3. 无GPU时强制使用CPU运行

如果没有NVIDIA GPU,修改验证代码,在init_model中指定device='cpu':

from mmdet3d.apis import init_model, inference_detector

config_file = 'pointpillars_hv_secfpn_8xb6-160e_kitti-3d-car.py'
checkpoint_file = 'hv_pointpillars_secfpn_6x8_160e_kitti-3d-car_20220331_134606-d42d15ed.pth'
# 强制使用CPU
model = init_model(config_file, checkpoint_file, device='cpu')
inference_detector(model, 'demo/data/kitti/000008.bin')

注意:部分3D检测模型在CPU上可能存在功能限制或运行缓慢。

4. 检查系统CUDA环境配置

若已安装CUDA但PyTorch无法识别,检查系统环境变量:

  • 确认CUDA_PATH已指向正确的CUDA安装目录(例如C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.7)
  • 在conda终端运行nvcc -V,确认能输出CUDA版本信息,若无法输出需将CUDA的bin目录添加到系统PATH中

内容的提问来源于stack exchange,提问作者Hatem MEHAI

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 15:52:25