运行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 <module>
    from models.common import DetectMultiBackend
  File "/home/xx/code/pytorch/pineapple/yolov3/models/common.py", line 29, in <module>
    from utils.dataloaders import exif_transpose, letterbox
  File "/home/xx/code/pytorch/pineapple/yolov3/utils/dataloaders.py", line 31, in <module>
    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 <module>
    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 <module>
    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}')

  • 9
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值