BEVFomer环境配置教程 (基于Ubuntu20.04和CUDA11.1)
本文将详细介绍在Ubuntu20.04系统上配置BEVFomer环境的过程,特别针对CUDA11.1版本。如果你是新手,按照本教程一步步操作,也能成功搭建环境配置。本文涵盖从安装CUDA到运行BEVFomer的完整流程。
准备工作
- 操作系统:Ubuntu 20.04 LTS
- GPU:NVIDIA显卡,支持CUDA 11.1
- 已安装:NVIDIA驱动(建议版本≥455)
第一步:安装CUDA 11.1和cuDNN
如果尚未安装CUDA 11.1,请从NVIDIA官网下载runfile或deb包安装。安装后设置环境变量:
export PATH=/usr/local/cuda-11.1/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-11.1/lib64:$LD_LIBRARY_PATH
然后安装与CUDA11.1匹配的cuDNN,并复制到cuda目录。
第二步:安装Miniconda
为了隔离环境,推荐使用conda:
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh
按提示完成安装,重启终端。
第三步:创建conda环境
conda create -n bevformer python=3.8 -y
conda activate bevformer
第四步:安装PyTorch匹配CUDA11.1
访问PyTorch官网,选择适合CUDA11.1的命令:
pip install torch==1.9.1+cu111 torchvision==0.10.1+cu111 torchaudio==0.9.1 -f https://download.pytorch.org/whl/torch_stable.html
验证安装:python -c "import torch; print(torch.version)"
第五步:安装MMCV-full
根据CUDA和PyTorch版本安装mmcv-full:
pip install mmcv-full==1.4.0 -f https://download.openmmlab.com/mmcv/dist/cu111/torch2.9.0/index.html
第六步:安装BEVFomer依赖
克隆BEVFomer仓库并安装其他依赖:
git clone https://github.com/zhiqi-li/BEVFormer.git
cd BEVFormer
pip install -r requirements.txt
此外还需安装mmdet和mmseg:
pip install mmdet==2.25.1 mmsegmentation==0.25.0
第七步:编译安装BEVFomer
python setup.py develop
第八步:验证安装
运行demo或简单测试,确保BEVFomer可以导入:
python -c "from bevformer import *; print("BEVFomer installed successfully!")"
常见问题
- CUDA版本不匹配:确保安装的PyTorch和mmcv都对应CUDA11.1。
- 编译错误:可能需要安装gcc、g++等。
至此,你已经完成了在Ubuntu20.04上基于CUDA11.1的BEVFomer环境配置。如有问题,欢迎交流。