【YOLOX】 相关问题总结

本文总结了YOLOX在训练过程中遇到的问题及解决方案,包括无法指定GPU、类别错误、负样本生成、漏检样本查找、训练验证划分以及模型的计算量和参数量计算。针对标签错误,注意处理空格导致的类别混乱;对于计算模型指标,理解FPS、GFLOPs和Params在评估模型性能中的作用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.YOLOX无法指定gpu,只能指定gpu个数

YOLOX-main/yolox/utils/dist.py在此路径下注释和添加代码:
在这里插入图片描述

def get_local_rank() -> int:     ###############ori
    """
    Returns:
        The rank of the current process within the local (per-machine) process group.
    """
    if not dist.is_available():
        return 0
    if not dist.is_initialized():
        return 0
    assert _LOCAL_PROCESS_GROUP is not None
    return dist.get_rank(group=_LOCAL_PROCESS_GROUP)   ###############ori

def get_local_rank() -> int:              ##########add
    """
    Returns:
        The rank of the current process within the local (per-machine) process group.
    """
    if not dist.is_available():
        return select_device('2')
    if not dist.is_initialized():
        return select_device('2')
    assert _LOCAL_PROCESS_GROUP is not None
    return dist.get_rank(group=_LOCAL_PROCESS_GROUP)


def select_device(device=''):
    # device = 'cpu' or '0' or '0,1,2,3'
    cpu_request = device.lower() == 'cpu'
    if device and not cpu_request:  # if device requested other than 'cpu'
        os.environ['CUDA_VISIBLE_DEVICES'] = device  # set environment variable
        assert torch.cuda.is_available(), 'CUDA unavailable, invalid device %s requested' % device  # check availablity

    cuda = False if cpu_request else torch.cuda.is_available()

    return 0 if cuda else 'cpu'         ##########add

2.训练时候突然多出其他类别

yolox训练时候突然多出两类,莫名其妙??
在这里插入图片描述
检查标签发现貌似没问题,一共7类
在这里插入图片描述
后面查看json文件发现中间的标签,由于中间有空格,所以一类变成三类,突然多出两类
在这里插入图片描述
后面修正一下标签如下,加下划线_
在这里插入图片描述

3. 负样本生成txt

当加入负样本时候,生成空的txt,放进去训练

import os.path
import cv2
from tqdm import tqdm

path = r"F:\1213bag\bag_all_yolox\add_new_6666\images"  #负样本图片文件夹
save_path=r"F:\1213bag\bag_all_yolox\add_new_6666\labels" #生成空的txt文件夹
files = os.listdir(path)
print(files)
for pic in tqdm(files):
    # # basename = os.path.basename(image_name)
    before_name = os.path.splitext(pic)[0]
    txt_name = os.path.splitext(before_name)[0] + ".txt"
    txt_name = os.path.join(save_path,txt_name)
    if os.path.exists(txt_name) == False:
        f = open(txt_name, "w")

4.找出漏检样本

demo.py检测完,会有漏检生成空的txt,查找漏检图片放进另一个文件夹

# 导入os
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值