🔥博客主页: A_SHOWY
🎥系列专栏:力扣刷题总结录 数据结构 云计算 数字图像处理 力扣每日一题_
随着YOLOv8的版本不断更新,最新的几个版本会发现没有requirements.txt和setup.py,在安装包的依赖的时候,直接pip install ultralytics,再装个GPU版本的torch三件套就开始用,倘若直接用源码跑还好,如果想要改进yolov8代码,那就倒霉了。
问题
比如有些朋友会想加一个CBAM注意力机制,或者是改一下conv,发现加上去以后,keyerror:“CBAM”等等keyerror的问题。
解决
比较好用的解决办法就是 如果你以前已经装了ultralytics了,直接
pip uninstall ultralytics
requirements.txt
然后根据我提供的两个文件,第一个是requirements.txt,里面是我们需要跑代码的版本要求,注意文件名要和我给的一模一样
#pip install -r requirements.txt
# Ultralytics requirements
# Usage: pip install -r requirements.txt# Base ----------------------------------------
hydra-core>=1.2.0
matplotlib>=3.2.2
numpy>=1.18.5
opencv-python>=4.1.1
Pillow>=7.1.2
PyYAML>=5.3.1
requests>=2.23.0
scipy>=1.4.1
torch>=1.7.0
torchvision>=0.8.1
tqdm>=4.64.0# Logging -------------------------------------
tensorboard>=2.4.1
# clearml
# comet# Plotting ------------------------------------
pandas>=1.1.4
seaborn>=0.11.0# Export --------------------------------------
# coremltools>=6.0 # CoreML export
# onnx>=1.12.0 # ONNX export
# onnx-simplifier>=0.4.1 # ONNX simplifier
# nvidia-pyindex # TensorRT export
# nvidia-tensorrt # TensorRT export
# scikit-learn==0.19.2 # CoreML quantization
# tensorflow>=2.4.1 # TF exports (-cpu, -aarch64, -macos)
# tensorflowjs>=3.9.0 # TF.js export
# openvino-dev # OpenVINO export# Extras --------------------------------------
ipython # interactive notebook
psutil # system utilization
thop>=0.1.1 # FLOPs computation
# albumentations>=1.0.3
# pycocotools>=2.0.6 # COCO mAP
# roboflow# HUB -----------------------------------------
GitPython>=3.1.24
setup.py
这个是一个脚本文件,直接在根目录创建复制进去就行
# Ultralytics YOLO 🚀, GPL-3.0 licenseimport re
from pathlib import Pathimport pkg_resources as pkg
from setuptools import find_packages, setup# Settings
FILE = Path(__file__).resolve()
ROOT = FILE.parent # root directory
README = (ROOT / "README.md").read_text(encoding="utf-8")
REQUIREMENTS = [f'{x.name}{x.specifier}' for x in pkg.parse_requirements((ROOT / 'requirements.txt').read_text())]def get_version():file = ROOT / 'ultralytics/__init__.py'return re.search(r'^__version__ = [\'"]([^\'"]*)[\'"]', file.read_text(), re.M)[1]setup(name="ultralytics", # name of pypi packageversion=get_version(), # version of pypi packagepython_requires=">=3.7.0",license='GPL-3.0',description='Ultralytics YOLOv8 and HUB',long_description=README,long_description_content_type="text/markdown",url="https://github.com/ultralytics/ultralytics",project_urls={'Bug Reports': 'https://github.com/ultralytics/ultralytics/issues','Funding': 'https://ultralytics.com','Source': 'https://github.com/ultralytics/ultralytics',},author="Ultralytics",author_email='hello@ultralytics.com',packages=find_packages(), # requiredinclude_package_data=True,install_requires=REQUIREMENTS,extras_require={'dev':['check-manifest', 'pytest', 'pytest-cov', 'coverage', 'mkdocs', 'mkdocstrings[python]', 'mkdocs-material'],},classifiers=["Intended Audience :: Developers", "Intended Audience :: Science/Research","License :: OSI Approved :: GNU General Public License v3 (GPLv3)", "Programming Language :: Python :: 3","Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8","Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10","Topic :: Software Development", "Topic :: Scientific/Engineering","Topic :: Scientific/Engineering :: Artificial Intelligence","Topic :: Scientific/Engineering :: Image Recognition", "Operating System :: POSIX :: Linux","Operating System :: MacOS", "Operating System :: Microsoft :: Windows"],keywords="machine-learning, deep-learning, vision, ML, DL, AI, YOLO, YOLOv3, YOLOv5, YOLOv8, HUB, Ultralytics",entry_points={'console_scripts': ['yolo = ultralytics.yolo.cli:cli', 'ultralytics = ultralytics.yolo.cli:cli'],})
终端执行命令
python setup.py install
结束以后输入yolo,显示如下成功
anaconda prompt执行命令
然后打开anaconda prompt,进入你配置的环境,看一下安装列表
conda activate ***
pip list
去torch官网下载自己合适的cuda版本
pip list以后发现torchvision版本不对应,我这个是2.22版本+cu118 去官网查一下对应版本,先把老版本卸载,再装新的,大概2.7G左右
pip uninstall torchvision
pip install torchvision==0.17.1+cu118 -f https://download.pytorch.org/whl/torch_stable.html
三件套安装成功且版本对应
直接回去可以改框架跑自己的数据集了