Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 

Repository files navigation


深度学习环境配置与操作速查表

1. Docker 容器管理

用途 命令 / 说明
构建/启动容器 (RTX 4090) docker run -it --name lsnet -p 8888:22 -p 6666:6006 --gpus all -v "G:\:/g_drive" --ipc=host cuda_12.8:3.0 bash
连接已有容器 docker exec -it lsnet bash
查看本地镜像 docker images
查看所有容器 docker ps -a
容器保存为镜像 docker commit -a="作者名" -m="提交描述" <容器ID> <目标镜像名>:<TAG>
导出镜像为文件 docker save -o my-image.tar my-image:latest
导入镜像文件 docker load -i my_image.tar
容器与本地文件复制 docker cp <container_name_or_id>:<container_path> /path/to/local/directory

2. 系统配置 (Ubuntu & SSH)

APT 换源 (清华源 - Ubuntu 24.04 Noble)

步骤:

  1. 进入目录:cd /etc/apt/sources.list.d
  2. 备份原文件:cp ubuntu.sources ubuntu.sources.bak
  3. 编辑文件:vim /etc/apt/sources.list.d/ubuntu.sources
  4. 写入以下内容
Types: deb
URIs: http://mirrors.tuna.tsinghua.edu.cn/ubuntu/
Suites: noble noble-updates noble-security
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
  1. 更新源:apt-get update

SSH 服务配置

步骤:

  1. 安装 SSH:apt-get install openssh-server
  2. 设置 Root 密码:passwd root
  3. 修改配置允许 Root 登录:
    • 编辑:vim /etc/ssh/sshd_config
    • 添加/修改:PermitRootLogin yes
  4. 启动服务:/etc/init.d/ssh start

3. Python 环境 (Conda & Pip)

用途 命令 / 说明
Miniconda 安装 apt-get install wget
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
sh Miniconda3-latest-Linux-x86_64.sh
/root/miniconda3/bin/conda init bash
删除虚拟环境 conda env remove -n 你的环境名
Pip 清华源 https://pypi.tuna.tsinghua.edu.cn/simple
Conda 问题排查 参考链接

PyTorch / CUDA 环境检测脚本

可直接保存为 .py 文件运行或在终端使用 python -c 运行。

详细检测脚本:

import torch

# 检查 CUDA 是否可用
print(f"CUDA available: {torch.cuda.is_available()}")

# 如果 CUDA 可用,打印当前设备名称
if torch.cuda.is_available():
    print(f"Current device: {torch.cuda.get_device_name(0)}")

# 获取 CUDA 版本
cuda_version = torch.version.cuda
print(f"CUDA Version: {cuda_version}")

# 获取 cuDNN 版本
cudnn_version = torch.backends.cudnn.version()
print(f"cuDNN Version: {cudnn_version}")

一行命令快速检测:

python -c "import torch; print(torch.__version__); print(torch.version.cuda); print(torch.cuda.get_arch_list())"

4. 工具配置 (Git, WandB, Kaggle)

工具 配置项/Token 操作命令
Git Token: <你的Token> apt-get install git
WandB API Key: <你的Token> (通常在 wandb login 时使用)
Kaggle Key: <你的Token> (通常配置在 ~/.kaggle/kaggle.json)

5. 常用监控与文件操作

用途 命令
显卡监控 watch -n 1 nvidia-smi
压缩文件夹 zip -r work_dirs.zip work_dirs
删除文件 (参考) rm -rf <文件名>

6.Colab 数据集加载流程解析

这段代码主要用于将存储在 Google Drive 中的压缩包,转移到 Colab 虚拟机的本地磁盘并解压,以便进行高速训练。

from google.colab import drive
drive.mount('/content/drive')
!cp "/content/drive/MyDrive/My_ImageNet_Project/imagenet-object-localization-challenge.zip" .
!unzip -q imagenet-object-localization-challenge.zip -d ./data

About

docker常用命令

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors