记录我配置YOLOX训练自己数据集的经历,已完成

本文以在colab上训练为例:

!git clone https://github.com/roboflow-ai/YOLOX.git
%cd YOLOX
!pip3 install -U pip && pip3 install -r requirements.txt
!pip3 install -v -e .  
!pip uninstall -y torch torchvision torchaudio
# May need to change in the future if Colab no longer uses CUDA 11.0
!pip install torch==1.7.1+cu110 torchvision==0.8.2+cu110 torchaudio==0.7.2 -f https://download.pytorch.org/whl/torch_stable.html

colab上cuda是11.0,但是环境中配置的是10.2的cuda,为了成功安装apex,运行yolox,必须统一版本。

apex的安装,可参考我 的文章:安装apex

数据集的准备和yolov5一样,不赘述,目录这个样子的。

data目录在你的项目目录下(也就是在你下载的YOLOX目录下)

上面数据集的划分:网上一堆代码,split_train_val.py文件,在VOC2007目录下运行。

import os
import random
 
trainval_percent = 1.0
train_percent = 0.9
xmlfilepath = 'Annotations'
total_xml = os.listdir(xmlfilepath)
num = len(total_xml)
list = range(num)
tv = int(num * trainval_percent)
tr = int(num * train_percent)
trainval = random.sample(list, tv)
train = random.sample(trainval, tr)
 
# ImageSets目录不存在,就创建
if not os.path.exists('ImageSets/'):
    os.makedirs('ImageSets/')
# ImageSets/Main目录不存在,就创建
if not os.path.exists('ImageSets/Main/'):
    os.makedirs('ImageSets/Main/')
 
ftrainval = open('ImageSets/Main/trainval.txt', 'w')
ftest = open('ImageSets/Main/test.txt', 'w')
ftrain = open('ImageSets/Main/train.txt', 'w')
fval = open('ImageSets/Main/val.txt', 'w')
 
for i in list:
    name = '/opt/PycharmProjects/yolov5/face_dataset/images/' + total_xml[i][:-4] + '.jpg' + '\n'
    if i in trainval:
        ftrainval.write(name)
        if i in train:
            ftrain.write(name)
        else:
            fval.write(name)
    else:
        ftest.write(name)
 
ftrainval.close()
ftrain.close()
fval.close()
ftest.close()

 下载YOLOx的权重文件


!wget https://github.com/Megvii-BaseDetection/storage/releases/download/0.0.1/yolox_s.pth

修改配置:修改yolox_base.py文件

 

 

 

 

 

 

 大概就改这些,具体修改文件截屏都有,不细说了,配置一个环境心累的一批。

运行

!python tools/train.py -f exps/example/yolox_voc/yolox_voc_s.py -d 1 -b 16 --fp16 -o -c yolox_s.pth

问题点:

  1. 不要把train.py文件中的--resume文件手动设置为True,第一次训练的时候会报错

按照这个来

 

版权声明:本文为CSDN博主「sustyle」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/sunchanglan151/article/details/120252306

sustyle

我还没有学会写个人说明!

暂无评论

发表评论

相关推荐

yolov5代码解读-网络架构

前言 上一篇:yolov5代码解读-dataset 下一篇:yolov5代码解读-训练 代码已上传到github,数据集和权重文件已上传到百度网盘(链接在github里)&