安装GPU版本显示cuda不可用
1 修复驱动
nvidia-smi NVIDIA-SMI has failed because it couldn't communicate with the NVIDIA driver. Make sure that the latest NVIDIA driver is installed and running.
查看 /usr/src/ 目录下已安装的 NVIDIA 驱动源码包版本号
ls -l /usr/src/ | grep nvidia
drwxr-xr-x 8 root root 4096 Sep 10 2025 nvidia-580.82.07
重安装dkms
sudo apt update
sudo apt install -y dkms build-essential linux-headers-$(uname -r)
再安装
sudo dkms install -m nvidia -v 580.82.07
2 创建软链接
查看ultralytics安装目录
pip show ultralytics
Location: /yolo26/lib/python3.12/site-packages
创建软链接
ln -s /yolo26/lib/python3.12/site-packages/ultralytics ultralytics
3 训练脚本
from ultralytics import YOLO
1. 加载你复制并重命名后的 YOLO26 模型配置文件
model = YOLO('yolo26n.yaml')
2. (可选) 如果你想从头训练,请确保注释掉下面这行
model.load('yolo26n.pt')
3. 开始训练
results = model.train(
data='datasets/yolo.yaml', # 使用相对路径,更简洁
epochs=300,
imgsz=640,
batch=16,
device=0,
name='yolo26'
)
yolo26.yaml nc类别数根据实际修改
Parameters
nc: 80 # number of classes
end2end: True # whether to use end-to-end mode
reg_max: 1 # DFL bins
scales: # model compound scaling constants, i.e. 'model=yolo26n.yaml' will call yolo26.yaml with scale 'n'
[depth, width, max_channels]
n: [0.50, 0.25, 1024] # summary: 260 layers, 2,572,280 parameters, 2,572,280 gradients, 6.1 GFLOPs
s: [0.50, 0.50, 1024] # summary: 260 layers, 10,009,784 parameters, 10,009,784 gradients, 22.8 GFLOPs
m: [0.50, 1.00, 512] # summary: 280 layers, 21,896,248 parameters, 21,896,248 gradients, 75.4 GFLOPs
l: [1.00, 1.00, 512] # summary: 392 layers, 26,299,704 parameters, 26,299,704 gradients, 93.8 GFLOPs
x: [1.00, 1.50, 512] # summary: 392 layers, 58,993,368 parameters, 58,993,368 gradients, 209.5 GFLOPs
yolo.yaml
path: /yolo26/datasets/yoloWheat # dataset root dir
train: images/train2007 # train images (relative to 'path')
val: images/val2007 # val images (relative to 'path')
test: # test images (optional)
Classes
nc: 6 # number of classes
names: ['xmhh','xmbh','xmcmb','xmsy','xmyf','xmjs']