目标检测:训练YOLO系列

1. gold-yolo训练自己数据集

        1. Gold YOLO 训练自己的数据集 - 知乎

        超越YOLOv8?基于Gold YOLO的自定义数据集训练-CSDN博客

        2. 训练:

python tools/train.py --batch-size 16 --conf-file configs/gold_yolo-n.py --data-path data/dataset.yaml --fuse_ab --epochs 300 --device 0
python tools/train.py --batch 16 --conf configs/gold_yolo-n.py --data "/content/drive/MyDrive/goldyolo/Efficient-Computing/Detection/Gold-YOLO/construction-safety-2/data.yaml" --epoch 50 --fuse_ab --device 0

         3. 验证:

python tools/eval.py --data data/dataset.yaml --batch-size 16 --weights runs/train/exp2/weights/best_ckpt.pt --task test --reproduce_640_eval

         4. 推理:

python tools/infer.py --weights /runs/train/exp2/weights/best_ckpt.pt --yaml "data.yaml" --source "Gold-YOLO/ppe.mp4" --save-dir 'OutPutResults'

2. pp-yoloe训练

        1. 解决:ModuleNotFoundError: No module named ‘paddle‘

pip install paddle paddle

        2. 解决:ValueError: The device should not be ‘gpu‘, since PaddlePaddle is not compiled with CUDA问题解决

pip install paddle paddle-gpu

        3. 修改好参数后,需要进行重新运行setup.py

python setup.py install

        4. 训练train.py

python tools/train.py -c configs/ppyoloe/voc/ppyoloe_plus_crn_l_30e_voc.yml

        5. 解决:AttributeError: module 'ppdet.data.source' has no attribute 'COCODataset'

        6. 在最开始需要安装各种包

pip install -r requirements.txt

        7. 测试是否安装成功

python ppdet/modeling/tests/test_architectures.py

        8. 自己数据集处理VOC,将VOC数据集放在dataset/voc/中,然后运行代码生成对应的trainval.txt和test.txt

python dataset/voc/create_list.py -d dataset/voc/VOCdevkit/

        9. 解决:voc文件中生成的trainval.txt和test.txt为空(本人的原因:VOCdevkit/VOC_YH/....数据集命名不标准,因此需要对create_list.py进行修改)

import os.path as osp
import random


def create_list(devkit_dir, year, output_dir):
    """
    create following list:
        1. trainval.txt
        2. test.txt
    """
    trainval_list = []
    test_list = []
    trainval, test = _walk_voc_dir(devkit_dir, year, output_dir)
    trainval_list.extend(trainval)
    test_list.extend(test)

    random.shuffle(trainval_list)
    with open(osp.join(output_dir, 'trainval.txt'), 'w') as ftrainval:
        for item in trainval_list:
            ftrainval.write(item[0] + ' ' + item[1] + '\n')

    with open(osp.join(output_dir, 'test.txt'), 'w') as fval:
        ct = 0
        for item in test_list:
            ct += 1
            fval.write(item[0] + ' ' + item[1] + '\n')


def _get_voc_dir(devkit_dir, year, type):
    # return osp.join(devkit_dir, 'VOC' + year, type)
    return osp.join(devkit_dir, 'VOC_YH', type) ##### 重点是将这行中的VOC_YH改成自己数据集的名称

def _walk_voc_dir(devkit_dir, year, output_dir):
    filelist_dir = _get_voc_dir(devkit_dir, year, 'ImageSets/Main')
    annotation_dir = _get_voc_dir(devkit_dir, year, 'Annotations')
    img_dir = _get_voc_dir(devkit_dir, year, 'JPEGImages')
    print(filelist_dir, annotation_dir, img_dir)
    trainval_list = []
    test_list = []
    added = set()

    fnames = ['trainval.txt', 'test.txt']
    for fname in fnames:
        img_ann_list = []
        fpath = osp.join(filelist_dir, fname)
        for line in open(fpath):
            name_prefix = line.strip().split()[0]
            if name_prefix in added:
                continue
            added.add(name_prefix)
            ann_path = osp.join(
                osp.relpath(annotation_dir, output_dir),
                name_prefix + '.xml')
            img_path = osp.join(
                osp.relpath(img_dir, output_dir), name_prefix + '.jpg')
            img_ann_list.append((img_path, ann_path))

        if fname == 'trainval.txt':
            trainval_list = img_ann_list
        elif fname == 'test.txt':
            test_list = img_ann_list

    return trainval_list, test_list
if __name__ == '__main__':
    create_list(devkit_dir='./VOCdevkit', output_dir='./', year=2007)

        10. 修改label_list.txt文件,改为自己数据集的类别

        11. 解决问题:Could not locate zlibwapi.dll. Please make sure it is in your library path!

     解决问题:Could not locate zlibwapi.dll. Please make sure it is in your library path!-CSDN博客

        12. 解决:训练PaddlePaddle时,报错AssertionError: not found any voc record in trainval.txt

                因为没有将数据集放在dataset/voc/下,导致通过trainval.txt找不到所对应的图片。(理论上来讲,在第9步,voc下生成trainval.txt和test.txt时,数据集就应该放在voc文件夹下)

  • 8
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值