1.下载源码,自行下载
2.打开项目
打开pycharm,选择自己的项目,建议使用Recent Project,每次用Open都会卡很久,不道为撒。。。
3.cmd 新建虚拟环境,需要输入y/n输入y就行
#创建一个名为YOLOv5的环境并指定python版本为3.9
conda create -n YOLOv5 python=3.9
4.激活虚拟环境,切换到项目文件夹下
activate YOLOv5
5.添加python解释器。
打开pycharm,点settings
点add interpreter
找到你新建的虚拟环境,选择python.exe
6.下载所需包
回到刚刚的cmd窗口,输入如下代码
pip install -r requirements.txt
7.下载完成
8.修改yolov5m.yaml文件
将nc改为本数据集目标数
9.修改myvoc.yaml
写好数据集地址(文件名字不重要,看你train里面填写的数据集yaml文件是什么就改哪个文件
激动人心的Debug过程。。。(每个人遇到的问题可能都千奇百怪,善用ai与搜索
10.运行train.py,出现报错
No module named 'ultralytics.yolo'
在v8和v5的配置中均遇到该问题
首先
pip install ultralytics.yolo
在v8中由于有ultralytic文件夹,在要运行的代码开头加上如下语句
import sys
sys.path.append("/home/shares/myproj/other_tasks/yolov8/")
# 即 ultralytics文件夹 所在绝对路径
v5中无该文件夹,故打开报错py文件utils/general.py
删除该行
from ultralytics.yolo.utils.yolo.checks import check_requirements
在大约350行之后(反正在其他函数结束后,添加如下代码
@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}')
参考链接:
运行yolov3报错解决_from ultralytics.yolo.utils.checks import check_re-优快云博客
9.不报错了,可以跑train了,但是还是有点小毛病
检查了一下自己的包版本,pillow版本10.2.0,但该版本中已删除getsize功能,故需手动降级至9.5
安装语句
pip install Pillow==9.5
10.正常运行了
11.总结
写在最后,环境的配置确实很麻烦,会遇到很多很多的问题,但个人觉得无非是如下几种
①各种包的版本不同,函数可能在升级过程中没有了,更换下包版本即可
②代码和主机有些编码不一致,修改下某些代码即可
③缺包,下就好了,但有些包名可能和报错中的不同,上网搜搜
④文件路径不对
⑤你自己的数据集格式不对
可能每个问题都会让我们抓耳挠腮很久
但不积跬步,无以至千里
一步一步去解决,一步一步走
积累无数debug经验
终能从小白变成技术大牛~(*•̀ᴗ•́*)و ̑̑
记得之前看过清华一位学长在其捐赠的教室里写了这么一句话
“我可以告诉你,当年我也一样郁闷吗?”
也送给你们。