实习·操作一些神秘的服务器和训练

8 阅读2分钟

2026-07-30 训练日志 — SeaShips + RF-DETR

注意:本人学习记录,目前还没输出什么有价值的观点。

但我相信:日拱一卒,功不唐捐。

1. Q:GitLab 克隆数据集到服务器

两个 IP 在 <gitlab-host>.0/24 同一子网,网络通。

GitLab 禁止密码登录,只允许 Personal Access Token。去 <gitlab-host>/-/profile/personal_access_tokens 创建 token,勾 read_repository

# token 直接嵌 URL,绕过 VS Code credential helper 的 socket 问题
git -c credential.helper= clone 'http://用户名:token@<gitlab-host>/datasets/seaships_7000.git'

安全清理:

# 1. 清 shell 历史
history | grep 'token'
history -d <行号>

# 2. 改 git remote(去掉 URL 里的 token)
cd seaships_7000 && git remote -v
git remote set-url origin http://<gitlab-host>/datasets/seaships_7000.git

2. 数据集格式转换 — VOC → YOLO

SeaShips(7000) 是 Pascal VOC 格式,RF-DETR 需要 YOLO 格式。

转换公式(VOC → YOLO):

x_center = (xmin + xmax) / 2 / 图片宽
y_center = (ymin + ymax) / 2 / 图片高
width    = (xmax - xmin) / 图片宽
height   = (ymax - ymin) / 图片高

YOLO txt 每行:class_id x_center y_center width height(归一化到 0-1)

目录结构:

seaships_yolo/
├── data.yaml
├── train/images/ + labels/
├── valid/images/ + labels/    ← 注意 RF-DETR 要求 "valid" 不是 "val"
└── test/images/ + labels/

验证转换: 抽同一个 xml 和 txt,手算验算。


3. 训练

from rfdetr import RFDETRMedium

model = RFDETRMedium()  # 权重自动下载到 ~/.roboflow/models/
model.train(
    dataset_dir="/opt/datasets/seaships_yolo",
    epochs=100,
    batch_size=4,
)
model.save("/opt/datasets/seaships_rfdetr_medium.pt")

监控:

nvidia-smi | grep python           # 进程在不在
tail -3 /opt/rf-detr/output/metrics.csv  # 看 mAP

训练慢的原因: DETR 比 YOLO 慢 3-5 倍(Transformer + 匈牙利匹配),加上 vLLM/Ollama 占显存。


4. 续训

每个 epoch 自动保存 checkpoint 到 output/checkpoint_N.ckpt

model.train(
    dataset_dir="/opt/datasets/seaships_yolo",
    epochs=100,
    batch_size=4,
    resume="/opt/rf-detr/output/checkpoint_19.ckpt",  # 改成最新编号
)

参数名是 resume,不是 ckpt_path

5. AI辅助经验

基本全是问一句AI下一步做什么然后照做...经验就是,1问有危险吗,怎么解决(token,历史);2关键点自己check(对比txt,xml);3训练前先问整体流程而不是盲目跟着下一步