在使用 PyTorch 准备环境并使用 miniconda 终端安装所需的所有软件包后,在验证安装过程的最后一步中出现错误。
我创建了一个 conda 环境并激活了它,
然后我安装了 PyTorch 以及使用 MIM 所需的所有软件包。
- MMEngine
- MMCV
- MMDetection
- MMDetection3D
我还使用以下命令成功下载了配置和检查点文件;
mim download mmdet3d --config pointpillars_hv_secfpn_8xb6-160e_kitti-3d-car --dest
但是在验证安装的最后一步我收到了错误消息。
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'
model = init_model(config_file, checkpoint_file)
inference_detector(model, 'demo/data/kitti/000008.bin')
输出
C:\Users\ANIS\miniconda3\envs\openmmlab\lib\site-packages\mmdet3d\models\dense_heads\anchor3d_head.py:92: UserWarning: dir_offset and dir_limit_offset wi 11 be depressed and be incorporated into box coder in the future
warnings.warn(
Loads checkpoint by local backend from path: hv_pointpillars_secfpn_6x8_160e_kitti-3d-car_20220331_134606-d42d15ed.pth
错误消息
如下所示以及 jupyter 笔记本的屏幕截图中。
Traceback
AttributeError Traceback (most recent call last)
Cell In[1], line 5
3 config_file = 'pointpillars_hv_secfpn_8xb6-160e_kitti-3d-car.py'
4 checkpoint_file = 'hv_pointpillars_secfpn_6x8_160e_kitti-3d-car_20220331_134606-d42d15ed.pth'
----> 5 model = init_model(config_file, checkpoint_file)
6 inference_detector(model, 'demo/data/kitti/000008.bin')
File ~\miniconda3/envs\openmmlab\lib\site-packages\mmdet3d\apis\inference.py:92, in init_model(config, checkpoint, device, cfg_options)
90 model.cfg = config # save the config in the model for convenience
91 if device != 'cpu':
---> 92 torch.cuda.set_device (device)
93 else:
94 warnings.warn('Don\'t suggest using CPU device. '
95 'Some functions are not supported for now.')
File ~\miniconda3/envs\openmmlab\lib\site-packages\torch\cuda\____init__.py:350, in set_device(device)
348 device = ___get_device_index(device)
349 if device >= 0:
--> 350 torch._C._cuda_setDevice(device)
AttributeError: module 'torch._C' has no attribute '_cuda_setDevice'
The error message "AttributeError: module 'torch._C' has no attribute '_cuda_setDevice'" typically arises when your PyTorch installation is not properly configured for CUDA or there's a mismatch between your PyTorch and CUDA versions.
Here's a breakdown of how to troubleshoot and resolve this issue:
1. Verify CUDA Availability and Compatibility
-
Check if CUDA is installed:
Open a command prompt and run
nvidia-smi
. If CUDA is installed, you'll see information about your NVIDIA GPU(s). If not, download and install the appropriate CUDA toolkit for your GPU from the NVIDIA website: https://developer.nvidia.com/cuda-downloads . - Check CUDA version compatibility: Visit the PyTorch website ( https://pytorch.org/ ) and ensure the PyTorch version you installed supports the CUDA version on your system.
2. Reinstall PyTorch with CUDA Support
-
Uninstall existing PyTorch:
bash conda activate your_environment_name conda uninstall pytorch torchvision torchaudio
-
Install PyTorch with CUDA:
Replace
cu117
with the CUDA version you want to use if it's different. You can find the appropriate CUDA specifier on the PyTorch website.bash conda activate your_environment_name conda install pytorch torchvision torchaudio cudatoolkit=11.7 -c pytorch -c nvidia
3. Environment Variable Check
-
Ensure that your
PATH
environment variable includes the path to your CUDA installation. This is usuallyC:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.7\bin
(adjust the version number if necessary).
4. Test Your Installation
-
After reinstalling PyTorch, run a simple script to verify CUDA is working:
python import torch print(torch.cuda.is_available()) # Should print True if torch.cuda.is_available(): device = torch.device('cuda') print(device) # Should print cuda:0 or similar
Additional Tips
- Use the correct environment: Double-check that you are working within the correct conda environment where you installed MMDetection 3D and its dependencies.
- Clean installation: If problems persist, create a fresh conda environment and reinstall all the required packages from scratch.
- Restart: After making changes to your environment or installation, restart your Jupyter Notebook kernel or Python IDE.
By carefully following these steps, you should be able to resolve the "AttributeError" and get your MMDetection 3D environment set up correctly for GPU acceleration with CUDA.
标签:python,pytorch,jupyter,openmmlab From: 76987253