基于Nvidia Docker开发环境搭建

MirrorYuChen
MirrorYuChen
发布于 2025-01-15 / 13 阅读
0
0

基于Nvidia Docker开发环境搭建

基于Nvidia Docker开发环境搭建

1.查询Docker镜像

  • nvidia-cuda
  • 将版本需求输入 Filter tags
  • 根据提供docker拉取指令拉取docker镜像
>> sudo docker pull nvidia/cuda:11.8.0-devel-ubuntu22.04

2.启动Docker容器

>> sudo docker run -itd --name mirror_dev --ipc=host --net=host --privileged=true --gpus all nvidia/cuda:11.8.0-devel-ubuntu22.04 bash

3.配置开发环境

  • (1) 进入容器
>> sudo docker exec -it mirror_dev bash
  • (2) 更换软件源
>> sed -i s@/archive.ubuntu.com/@/mirrors.aliyun.com/@g /etc/apt/sources.list
>> sed -i s@/security.ubuntu.com/@/mirrors.aliyun.com/@g /etc/apt/sources.list
>> apt-get clean
>> apt-get update
  • (3) 安装vim工具,配置颜色及地区
>> apt-get install vim
>> vim ~/.bashrc
export LANG=C.UTF-8
PS1='[\[\e[35;1m\]\u@\[\e[33;1m\]\h\[\e[34;1m\] \W\[\e[0m\]]\$ '
>> source ~/.bashrc
  • (4) 创建工作空间和软件路径
>> cd 
>> mkdir software && mkdir workspace
  • (5) 安装miniconda
>> apt-get install curl
>> cd software
>> curl -O https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
>> bash Miniconda3-latest-Linux-x86_64.sh
...
[/root/miniconda3] >>> /root/software/miniconda3
...
You can undo this by running `conda init --reverse $SHELL`? [yes|no]
[no] >>> yes
...
  • (6) 创建开发环境,默认启动开发环境
>> conda create -n dev python=3.10.*
>> vim ~/.bashrc
conda activate dev
>> source ~/.bashrc
  • (7) 更新conda源
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --set show_channel_urls yes

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/menpo/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/

4.安装pytorch

  • (1) 网络较好,并且可以翻墙
>> conda install pytorch==1.13.1 torchvision==0.14.1 torchaudio==0.13.1 pytorch-cuda=11.7 -c pytorch -c nvidia
>> pip install torch==1.13.1+cu117 torchvision==0.14.1+cu117 torchaudio==0.13.1 --extra-index-url https://download.pytorch.org/whl/cu117
  • (2) 国内网比较差,并且不能翻墙
>> pip install torch==1.13.1+cu117 torchvision==0.14.1+cu117 torchaudio==0.13.1 -f https://mirrors.aliyun.com/pytorch-wheels/cu117/

​ 其它源:

上海交大:https://mirror.sjtu.edu.cn/pytorch-wheels/cu117

5.安装HLOC包

5.1 下载HLOC源码

>> git clone --recursive git@github.com:cvg/Hierarchical-Localization.git
>> git clone --recursive git@github.com:cvg/LightGlue.git 

5.2 源码上传服务器

>> sftp <username>@<ip>
>> cd <workspace>
>> put -r ./Hierarchical-Localization
>> put -r ./LightGlue
>> exit

5.3 库安装

  • (1) 连接服务器,进入工程路径,并修改 Hierarchical-Localization文件夹下的 requirements.txt文件
torch>=1.1
torchvision>=0.3
numpy
opencv-python
tqdm>=4.36.0
matplotlib
plotly
scipy
h5py
pycolmap>=0.6.0
kornia>=0.6.11
gdown

​ 因为服务器不能访问 git,这里删除掉 lightglue @ git+https://github.com/cvg/LightGlue,后面手动安装该依赖。

  • (2) 安装依赖库及当前库
>> cd <workspace>/Hierarchical-Localization
>> pip install -e .
>> cd <workspace>/LightGlue
>> pip install -e .

6.参考资料


评论