深度学习之YOLOV10训练自己的数据集二之训练前检查篇(5)

 前面这篇博客写了训练数据集的基本准备操作:

深度学习之YOLOV10训练自己的数据集一(4)-CSDN博客

在实际训练过程中,问题还是很多的,我忽略了输入一个显示训练时间的指令,所以我也不知道训练到哪一轮,而且在训练时出现了很多大量的 False 值,并且在训练过程中没有实时模型训练进度输出显示。

在检查之前可以先把先前训练过的数据删除,在runs文件夹里面,可以根据生成日期去查找缓存文件。

 一、在训练前检查配置环境

1.检查数据集标签

 确保标签文件中的类别编号从 0 开始,而不是 1 或其他值。可以使用以下脚本遍历所有标签文件,检查并修正类别编号:

import os

def check_and_fix_labels(root_dir):
    for root, _, files in os.walk(root_dir):
        for file in files:
            if file.endswith('.txt'):
                file_path = os.path.join(root, file)
                with open(file_path, 'r') as f:
                    lines = f.readlines()
                
                new_lines = []
                for line in lines:
                    parts = line.strip().split()
                    if len(parts) > 0:
                        class_id = int(parts[0])
                        if class_id > 0:
                            class_id -= 1
                        parts[0] = str(class_id)
                        new_lines.append(' '.join(parts))
                
                with open(file_path, 'w') as f:
                    f.write('\n'.join(new_lines) + '\n')

# 运行脚本,修正标签文件
check_and_fix_labels('/path/to/labels')

2.检查配置文件

 确保 data.yamlyolov10n.yaml 中的类别数配置正确。

 data.yaml 文件示例:

train: /path/to/train/images
val: /path/to/val/images
nc: 1  # 根据你的数据集调整
names: ['class_name']  # 根据你的数据集调整

yolov10n.yaml 文件示例:

nc: 1  # 根据你的数据集调整
...

 3.检查硬件问题

确保系统有足够的内存和硬盘空间。如果使用 GPU,确保 GPU 驱动和 CUDA 环境配置正确。

(1) 检查 NVIDIA 驱动程序

 首先,确保你安装了 nvidia-smi 工具。你可以通过以下命令检查 NVIDIA 驱动程序的版本和 GPU 使用情况:

nvidia-smi

 运行该命令后,你应该能看到类似如下的信息:

+-----------------------------------------------------------------------------+
| NVIDIA-SMI 460.32.03    Driver Version: 460.32.03    CUDA Version: 11.2     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  GeForce GTX 1080    Off  | 00000000:01:00.0  On |                  N/A |
|  0%   32C    P8     8W / 180W |    430MiB /  8116MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+

(yolov10)**@**-Tower-Workstation:~$ 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.

nvidia-smi 命令输出的错误信息说明你的系统无法与 NVIDIA 驱动程序通信。这通常意味着 NVIDIA 驱动程序未正确安装或未正确运行。要解决这个问题,请按照以下步骤检查和修复 NVIDIA 驱动程序的安装。电脑上还有一些老版本的环境,不太敢随便换nvidia的版本。


(yolov10) ***-Tower-Workstation:~$ python -c "import torch; print(torch.cuda.is_available())"

False

 返回了 False,这表明 PyTorch 无法检测到 GPU。

首先,确保你的 NVIDIA 驱动程序已经正确安装,并且 CUDA 驱动程序也在运行。你可以使用以下命令检查 NVIDIA 驱动程序的状态:

sudo systemctl status nvidia

 Loaded: not-found (Reason: No such file or directory) Active: inactive (dead)

 从输出结果来看,nvidia 服务没有找到,这表明 NVIDIA 驱动程序可能没有正确安装或没有启动。接下来,我们需要重新安装 NVIDIA 驱动程序并确保其正确配置。

  • 确保系统包和依赖项是最新的:
sudo apt-get update
sudo apt-get upgrade

 第二步执行比较费时间。

如果没有找到NVIDIA版本的,就需要重新下载了。我环境中使用的是cuda-11.8,需要高版本的驱动程序,电脑上的版本只到384,带动不了程序运行。

详细操作可以参考这篇:深度学习之NVIDIA驱动程序550的手动安装和配置-CSDN博客

 (2)检查 CUDA 版本

为了运行深度学习任务,CUDA 驱动也是必需的。你可以使用以下命令检查安装的 CUDA 版本:

nvcc --version

 你应该能看到类似如下的信息:

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2020 NVIDIA Corporation
Built on Fri_Sep_11_22:25:59_PDT_2020
Cuda compilation tools, release 11.2, V11.2.152
Build cuda_11.2.r11.2/compiler.2919052_0
 (3)检查 PyTorch 是否检测到 GPU

你还可以使用 PyTorch 检查是否能够检测到 GPU,并确认 CUDA 是否可用。运行以下 Python 脚本:

import torch
print("CUDA available:", torch.cuda.is_available())
print("CUDA device count:", torch.cuda.device_count())
print("CUDA device name:", torch.cuda.get_device_name(0))

 如果安装正确,你应该能看到类似如下的信息:

CUDA available: True
CUDA device count: 1
CUDA device name: GeForce GTX 1080

 

  • 21
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值