2021-08-17

**

基于conda环境下YOLOv5安装和运行步骤

**

作者使用的环境为ubuntu16.04
ROS版本:kinetic

一 更换阿里云源

(1)命令行输入:

sudo gedit /etc/apt/sources.list

(2)在sources.list中用aliyun替换原来的源:

deb http://mirrors.aliyun.com/ubuntu/ xenial main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main

deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main

deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates universe

deb http://mirrors.aliyun.com/ubuntu/ xenial-security main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security universe

(3)更新源:

sudo apt-get update

(4)可能会出现错误:

An error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: http://packages.ros.org/ros/ubuntu xenial InRelease: The following signatures were invalid: KEYEXPIRED 1622248854

解决办法:
首先要删除旧的密钥:
16.04以后的版本:

sudo apt-key del 421C365BD9FF1F717815A3895523BAEEB01FA116

然后添加新的密钥:

sudo -E apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654

更新:

sudo apt update

二 下载cuda、NVIDIA

(1)cuda下载

参考博客:https://blog.csdn.net/weixin_44401286/article/details/109203890
下载链接的页面中有对应的cuda版本,这里我选择的是cuda 10.2、ZEDSDK for Ubuntu 16这两个驱动版本https://developer.nvidia.com/cuda-10.2-download-archive?target_os=Linux&target_arch=x86_64&target_distro=Ubuntu&target_version=1604&target_type=deblocal
(2)根据cuda下载界面提示,采用如下方式下载:

wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/cuda-ubuntu1604.pin
sudo mv cuda-ubuntu1604.pin /etc/apt/preferences.d/cuda-repository-pin-600
wget http://developer.download.nvidia.com/compute/cuda/10.2/Prod/local_installers/cuda-repo-ubuntu1604-10-2-local-10.2.89-440.33.01_1.0-1_amd64.deb

cuda-repo-ubuntu1604-10-2-local-10.2.89-440.33.01_1.0-1_amd64.deb安装包可在百度网盘自行下载,链接:https://pan.baidu.com/s/1yVaMLR7ByI1y1vMti3xa9Q
提取码:1234

sudo dpkg -i cuda-repo-ubuntu1604-10-2-local-10.2.89-440.33.01_1.0-1_amd64.deb
sudo apt-key add /var/cuda-repo-10-2-local-10.2.89-440.33.01/7fa2af80.pub
sudo apt-get update
sudo apt-get -y install cuda #sudo apt-get install cuda-10.2

(3)安装好之后在~/.bashrc文件末尾添加如下:

export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64

(4)重启电脑

三 Anaconda3安装

(1)下载Anaconda3-2020.07-Linux-x86_64.sh

wget https://repo.anaconda.com/archive/Anaconda3-2020.07-Linux-x86_64.sh

安装包可在百度网盘自行下载,链接:https://pan.baidu.com/s/1j4NRMw_1oA27F-RneOD6yw

提取码:1234

(2)找到此安装包路径,并在当前路径下开启命令行,执行:

bash Anaconda3-2020.07-Linux-x86_64.sh

按yes;
在这里插入图片描述

指定安装路径;
在这里插入图片描述
按yes,出现下图界面,则说明安装成功;
在这里插入图片描述

(3)添加路径,在bashrc文件中输入:

sudo gedit ~/.bashrcexport PATH=$PATH:/home/software/anaconda3/bin

(4)在bashrc末尾添加:

conda deactivate

(5)重新打开新的命令行,输入,激活conda环境:

conda activate

四 YOLOv5安装

YOLOv5安装包和权重文件,自行提取
链接:https://pan.baidu.com/s/1aDn8WSfFtkSsttGFHdawrQ

提取码:1234

(1)激活conda环境;

conda activate

(2)将权重文件yolov5.pt放至weights文件夹,仔细阅读README.md;
(3)进入yolov5-3.1,可打开requirements.txt文件,查看并下载所需的软件包:

pip --default-timeout=100 install -r requirements.txt -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com --ignore-installed

(4)若出现以下类似错误,可单独下载所需的包(需要根据实际情况多次运行);
图片

pip install absl-py==0.4 -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com

(6)在bashrc文件下,指定python3.8编译;

sudo gedit ~/.bashrc

#在bashrc中添加python路径

export PYTHONPATH="/home/ubuntu16.04/anaconda3/lib/python3.8/site-packages:$PYTHONPATH"

(7)安装好需要的包之后,连接好摄像头运行:

python detect.py --weights weights/yolov5s.pt --source 0 --view-img

在这里插入图片描述

参考网址:
https://www.bilibili.com/video/BV1QT4y1J7rm/?spm_id_from=333.788.recommend_more_video.2 //目标检测YOLOv5,速度更快,最快可达140fps,体积更小,只有v4的1/9,基于pytorch框架,更易于移植

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

木子智~

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

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

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

打赏作者

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

抵扣说明:

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

余额充值