当前位置: 首页 > 工具软件 > YOLOAir > 使用案例 >

yoloair代码库下成功运行yolov7

锺功
2023-12-01

环境搭建(TODO)

自定义数据集(TODO)

VOC数据集格式

github下载代码库

在代码仓库选择main版本的进行下载

https://github.com/iscyy/yoloair.git

yolov7权重下载

权重地址:https://github.com/WongKinYiu/yolov7 

放在yoloair的根目录下就行

原始代码存在的问题

1. 缺少timm模块

ModuleNotFoundError: No module named 'timm'

解决方案:pip安装即可

pip install timm -i https://pypi.tuna.tsinghua.edu.cn/simple

2. Dataset  'nc'  key missing

Traceback (most recent call last):
  File "train.py", line 695, in <module>
    main(opt)
  File "train.py", line 591, in main
    train(opt.hyp, opt, device, callbacks)
  File "train.py", line 112, in train
    data_dict = data_dict or check_dataset(data)  # check if None
  File "/home/nky/PycharmProjects/yoloair-main/utils/general.py", line 421, in check_dataset
    assert 'nc' in data, "Dataset 'nc' key missing."
AssertionError: Dataset 'nc' key missing.

解决方案:(代码主体跟yolov5大致相同,可以去yolov5代码中的general.py下的如下代码复制到yoloair/utils/general.py中的check_dataset函数中的#Resolve paths前面)

 # Checks
    for k in 'train', 'val', 'names':
        assert k in data, emojis(f"data.yaml '{k}:' field missing ❌")
    if isinstance(data['names'], (list, tuple)):  # old array format
        data['names'] = dict(enumerate(data['names']))  # convert to dict
    assert all(isinstance(k, int) for k in data['names'].keys()), 'data.yaml names keys must be integers, i.e. 2: car'
    data['nc'] = len(data['names'])

3. 缺少labels

Traceback (most recent call last):
  File "train.py", line 695, in <module>
    main(opt)
  File "train.py", line 591, in main
    train(opt.hyp, opt, device, callbacks)
  File "train.py", line 228, in train
    train_loader, dataset = create_dataloader(train_path, imgsz, batch_size // WORLD_SIZE, gs, single_cls,
  File "/home/nky/PycharmProjects/yoloair-main/utils/datasets.py", line 100, in create_dataloader
    dataset = LoadImagesAndLabels(path, imgsz, batch_size,
  File "/home/nky/PycharmProjects/yoloair-main/utils/datasets.py", line 433, in __init__
    assert nf > 0 or not augment, f'{prefix}No labels in {cache_path}. Can not train without labels. See {HELP_URL}'
AssertionError: train: No labels in /home/nky/VOCdevkit/VOC2007/ImageSets/Main/train.cache. Can not train without labels. 

解决方案:datasets.py的img2label_paths函数中将images改成JPEGImages即可。

 类似资料: