> Windows 11 + Python 3.12 + Conda + CPU
## 1. 环境信息
| 项目 | 配置 |
|---|---|
| OS | Windows 11 |
| CPU | Intel Core i5-14400 |
| GPU | 未使用 |
| Python | 3.12.13 |
| PyTorch | 2.13.0+cpu |
| Ultralytics | 8.4.121 |
| YOLO 源码 | `D:\workspace\ultralytics-main` |
## 2. 创建 Conda 环境
```cmd
conda create -n yolo python=3.12 -y
conda activate yolo
```
检查:
```cmd
python --version
where python
```
## 3. 安装 PyTorch CPU
```cmd
python -m pip install --upgrade pip
pip install torch torchvision torchaudio
```
检查:
```cmd
python -c "import torch; print('PyTorch:', torch.version); print('CUDA:', torch.cuda.is_available())"
```
本次结果:
```text
PyTorch: 2.13.0+cpu
CUDA: False
```
## 4. 安装 Ultralytics
进入源码目录:
```cmd
cd /d D:\workspace\ultralytics-main
```
安装:
```cmd
python -m pip install -e .
```
检查:
```cmd
yolo version
```
本次结果:
```text
8.4.121
```
## 5. 检查 YOLO 环境
```cmd
yolo checks
```
本次核心结果:
```text
Ultralytics 8.4.121
Python-3.12.13
torch-2.13.0+cpu
CPU (Intel Core i5-14400)
GPU None
CUDA None
Setup complete
```
说明 YOLO 环境正常。
## 6. 最小训练测试
执行:
```cmd
yolo train model=yolo26n.pt data=coco8.yaml epochs=1 imgsz=640 device=cpu
```
该命令会自动下载 `yolo26n.pt` 和 `coco8` 测试数据集。
本次测试成功:
```text
1 epochs completed
```
验证结果:
```text
Images: 4
Instances: 17
mAP50: 0.906
mAP50-95: 0.665
```
训练结果:
```text
D:\workspace\ultralytics-main\runs\detect\train
```
模型:
```text
D:\workspace\ultralytics-main\runs\detect\train\weights\best.pt
D:\workspace\ultralytics-main\runs\detect\train\weights\last.pt
```
## 7. X-AnyLabeling 数据
原始数据:
```text
frame1_00000.jpg
frame1_00000.json
frame1_00001.jpg
frame1_00001.json
```
JSON 中包含 `label`、`points`、`imageWidth`、`imageHeight` 等信息。
## 8. YOLO 数据集目录
将 X-AnyLabeling 的 JSON 转换为 YOLO TXT,并按比例划分 train / val:
```text
D:\workspace\ultralytics-main\datasets\dms
├── images
│ ├── train
│ │ ├── frame1_00000.jpg
│ │ └── ...
│ └── val
│ ├── frame1_00100.jpg
│ └── ...
└── labels
├── train
│ ├── frame1_00000.txt
│ └── ...
└── val
├── frame1_00100.txt
└── ...
```
图片和标签必须同名:
```text
images/train/frame1_00000.jpg
labels/train/frame1_00000.txt
```
## 9. JSON 转 TXT
YOLO 训练使用 `.txt` 标签,不能直接使用 X-AnyLabeling 的 JSON。
TXT 格式:
```text
class_id center_x center_y width height
```
坐标需要转换为 YOLO 归一化坐标。
## 10. dms.yaml
在:
```text
D:\workspace\ultralytics-main
```
创建 `dms.yaml`:
```yaml
path: D:/workspace/ultralytics-main/datasets/dms
train: images/train
val: images/val
names:
0: xxx
1: xxx
2: xxx
3: xxx
```
`names` 必须与 TXT 中的类别编号对应。
## 11. 1 Epoch 最小测试训练
本次测试:
```text
训练集:40 张
验证集:10 张
模型:yolov8n.pt
imgsz:1920
batch:4
epochs:1
device:cpu
```
命令:
```bash
yolo train model=yolov8n.pt data=dms.yaml epochs=1 imgsz=1920 batch=4 device=cpu
```
如果本地没有 `yolov8n.pt`,Ultralytics 会自动下载。
## 12. 测试结果
日志确认:
```text
Overriding model.yaml nc=80 with nc=4
```
说明 4 个类别被正确读取。
训练成功完成:
```text
1 epochs completed
```
生成:
```text
D:\workspace\ultralytics-main\runs\detect\train-2\weights\best.pt
D:\workspace\ultralytics-main\runs\detect\train-2\weights\last.pt
```