wsl部署Ubuntu20.04配置YOLOV5算法相关环境

wsl2 部署可以参考我的上一篇文章http://t.csdnimg.cn/zkRiS

首先下载对应的Anaconda版本,通过输入查询

uname -a

在上官网下载对应的文件

Index of / (anaconda.com)

随后输入以下代码进行安装

bash Anaconda3-2022.05-Linux-x86_64.sh

一直点击enter直到出现选择yes

最终会出现以下画面表示成功安装

首先激活一下环境

source ~/.bashrc 

接下来创建虚拟环境:

conda create -n yolo python=3.8

可能会出现下面的问题

  • 在终端输入conda info --envs检验anaconda是否安装成功,发现报错:conda: command not found 原因是因为~/.bashrc文件没有配置好
  • 简单来说,就是找不到ananconda的位置,需要添加一下
  • 如图所示,我的位置需要在bashrc中加入以下内容
  • vim ~/.bashrc
    
  • export PATH=$PATH:/root/anaconda3/bin
    

  • 创建完成之后,输入命令激活环境:

  • conda activate yolo

  • 下载源代码:sticker_阮 / YOLOV5源码 · GitCode

  • 随后修改requirements.txt文件:

  • 下载好的yolov5-master文件夹下找到requirements.txt文件,修改成以下形式:

在yolov5-master文件夹下打开终端输入以下命令安装对应依赖

pip3 install -U -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple

在下载过程中可能会出现一些报错。

解决方法:按照错误提示,安装相应版本的包

出现如下画面就是安装成功了

随后在yolov5-master目录下的终端运行测试代码

python detect.py --source data/images/zidane.jpg

随后我出现了以下报错

按照报错文件位置,找到对应行次,点击i进入编辑模式进行删除,再将下面的代码拷贝到utils/general.py中345行代码之后,随后点击esc,输入:wq 在点击enter保存并退出

@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}')


参考链接:http://t.csdnimg.cn/WsrYP

切记:不要打乱代码布局否则可能出现报错:

Traceback (most recent call last):
  File "detect.py", line 45, in <module>
    from models.common import DetectMultiBackend
  File "/root/yolov5-master/models/common.py", line 28, in <module>
    from utils.dataloaders import exif_transpose, letterbox
  File "/root/yolov5-master/utils/dataloaders.py", line 31, in <module>
    from utils.augmentations import (Albumentations, augment_hsv, classify_albumentations, classify_transforms, copy_paste,
  File "/root/yolov5-master/utils/augmentations.py", line 15, in <module>
    from utils.general import LOGGER, check_version, colorstr, resample_segments, segment2box, xywhn2xyxy
  File "/root/yolov5-master/utils/general.py", line 345
    local_branch = check_output('git rev-parse --abbrev-ref HEAD', shell=True).decode().strip()  # checked out
                                                                                                             ^
IndentationError: unindent does not match any outer indentation level

最终显示如图则表示成功

这时候,最后的效果会保存在runs/detect/下,我的是exp4

最后找到detect.py文件,修改以下代码中的source:改成0则为调用电脑自带的摄像头。

parser.add_argument('--source', type=str, default='0', help='file/dir/URL/glob/screen/0(webcam)')

最后通过终端进入我们创建的yolo环境,输入python detect.py即可运行实现笔记本自带摄像头识别。

  • 18
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ROS研究员

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值