运行yolov3报错解决

运行yolov3报错解决

# 代码的克隆地址
https://github.com/ultralytics/yolov3.git

运行自己的数据集时报了如下的错误

Traceback (most recent call last):
  File "/home/xx/code/pytorch/pineapple/yolov3/detect.py", line 45, in >
    from models.common import DetectMultiBackend
  File "/home/xx/code/pytorch/pineapple/yolov3/models/common.py", line 29, in >
    from utils.dataloaders import exif_transpose, letterbox
  File "/home/xx/code/pytorch/pineapple/yolov3/utils/dataloaders.py", line 31, in >
    from utils.augmentations import (Albumentations, augment_hsv, classify_albumentations, classify_transforms, copy_paste,
  File "/home/xx/code/pytorch/pineapple/yolov3/utils/augmentations.py", line 15, in >
    from utils.general import LOGGER, check_version, colorstr, resample_segments, segment2box, xywhn2xyxy
  File "/home/xx/code/pytorch/pineapple/yolov3/utils/general.py", line 39, in >
    from ultralytics.yolo.utils.checks import check_requirements
ModuleNotFoundError: No module named 'ultralytics'

分析上面的错误,发现是在utils/general.py文件里的39行处报错了。因为找不到check_requirements。解决办法如下。

1. 删除utils/general.py文件下39行代码,即下面的这行代码

from ultralytics.yolo.utils.checks import check_requirements

2. 拷贝下面的代码到utils/general.py345行代码之后

@TryExcept()
def check_requirements(requirements=ROOT / 'requirements.txt', exclude=(), install=True, cmds=''):
    # Check installed dependencies meet YOLOv5 requirements (pass *.txt file or list of packages or single package str)
    prefix = colorstr('red', 'bold', 'requirements:')
    check_python()  # check python version
    if isinstance(requirements, Path):  # requirements.txt file
        file = requirements.resolve()
        assert file.exists(), f'{prefix} {file} not found, check failed.'
        with file.open() as f:
            requirements = [f'{x.name}{x.specifier}' for x in pkg.parse_requirements(f) if x.name not in exclude]
    elif isinstance(requirements, str):
        requirements = [requirements]

    s = ''
    n = 0
    for r in requirements:
        try:
            pkg.require(r)
        except (pkg.VersionConflict, pkg.DistributionNotFound):  # exception if requirements not met
            s += f'"{r}" '
            n += 1

    if s and install and AUTOINSTALL:  # check environment variable
        LOGGER.info(f"{prefix} YOLOv5 requirement{'s' * (n > 1)} {s}not found, attempting AutoUpdate...")
        try:
            # assert check_online(), "AutoUpdate skipped (offline)"
            LOGGER.info(check_output(f'pip install {s} {cmds}', shell=True).decode())
            source = file if 'file' in locals() else requirements
            s = f"{prefix} {n} package{'s' * (n > 1)} updated per {source}\n" \
                f"{prefix} ⚠️ {colorstr('bold', 'Restart runtime or rerun command for updates to take effect')}\n"
            LOGGER.info(s)
        except Exception as e:
            LOGGER.warning(f'{prefix}{e}')

你可能感兴趣的:(深度学习,python,目标检测,YOLO)