运行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.py
中345行代码之后
@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}')