前言
做AI做的事儿,让世界充满AI
原定目标主要是对安卓手机进行UI实时监测,思路是利用投屏原理拿到图像帧,在使用过程中进行无感知UI检测,我认为目前最大支持仅为60fps,作用能干嘛呢?作用可多了,譬如训练单图标配合无障碍点击进行智能化抢红包,刷金币,还有可能打王者,本篇为基础搭建篇。
之所以放日志是因为工作环境是内网,很多网站无法正常访问,我是在家做一遍再在公司实现,主要用来对比执行差异。
版本
Win10
Python 3.9.12
conda 22.9.0
Yolo5
全程高能注意
所有名称不得出现中文名,否则报错
目录
- 安装miniconda
- 配置conda国内下载镜像
- 安装Pytorch
- 创建conda虚拟环境
- 从git上下载Yolo5
- 图片数据标记软件
- 数据标记
- 数据筹备
- 训练筹备
- 训练可视化
- 检测目标图片
一、安装miniconda
它是Anaconda的简化版,由于Anaconda每次安装卸载太慢故用简化版,安装卸载注意:
1.注册表:\HKEY_CURRENT_USER\Software\Microsoft\Command Processor
下可能会多一个Autorun导致cmd打开就立即运行完,安装完成后删掉即可
2.安装miniconda可能会由于权限等原因导致安装的内容大量残缺,典型的属于缺失python.exe,Library文件夹,如若发生建议先在C盘先安装一遍再安装到别的盘,之后为了节约C盘空间可以将其卸载
3.配置环境变量,若在安装过程中没有勾选那个自动给配置环境变量的勾可以手动配置(事实上我勾了它也没自动配置成功),主要配置如下:
D:\Miniconda3
D:\Miniconda3\Scripts
D:\Miniconda3\Library\bin
二、配置conda国内下载镜像
由于原生下载链接有些包下载慢或下载不下来,我们在这里使用清华镜像(推荐使用豆瓣镜像,清华镜像有点小垃圾),按照官网教程做法生成.condarc文件巴拉巴拉后,发现连conda命令都无法正常使用,一直报某个python脚本的编码错误,中间碰到一堆博客说啥https改http,去除-defaults都无法正常下载,最终找到如下镜像配置替换,conda命令方既能正常使用,下载还飞起,至此镜像配置完成:
channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/win-64/
- defaults
show_channel_urls: true
channel_alias: https://mirrors.tuna.tsinghua.edu.cn/anaconda
default_channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
pytorch-lts: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
三、安装Pytorch
因工作电脑是集成显卡,未防显卡烧坏,我在Pytorch官网下载CPU版本,命令如下:
conda install pytorch torchvision torchaudio cpuonly -c pytorch
注:如若你的电脑需要cpu与gpu版本,建议在conda创建的虚拟环境中使用pip方式下载,这样下载的东西应该与虚拟环境绑定,s可以执行多个版本。
执行日志:(简书Markdown无折叠语法,真垃圾)
C:\Users\NewBeeChina>conda install pytorch torchvision torchaudio cpuonly -c pytorch
Collecting package metadata (current_repodata.json): done
Solving environment: |
Warning: >10 possible package resolutions (only showing differing packages):
- https://repo.anaconda.com/pkgs/main/noarch/noarch::colorama-0.4.4-pyhd3eb1b0_0, https://repo.anaconda.com/pkgs/main/win-64/win-64::console_shortcut-0.1.1-4, https://repo.anaconda.com/pkgs/main/win-64/win-64::powershell_shortcut-0.0.1-3, https://repo.anaconda.com/pkgs/main/win-64/win-64::win_inet_pton-1.1.0-py39haa95532_0
- defaults/noarch::colorama-0.4.4-pyhd3eb1b0_0, https://repo.anaconda.com/pkgs/main/win-64/win-64::console_shortcut-0.1.1-4, https://repo.anaconda.com/pkgs/main/win-64/win-64::powershell_shortcut-0.0.1-3, https://repo.anaconda.com/pkgs/main/win-64/win-64::win_inet_pton-1.1.0-py39haa95532_0
- defaults/win-64::console_shortcut-0.1.1-4, https://repo.anaconda.com/pkgs/main/noarch/noarch::colorama-0.4.4-pyhd3eb1b0_0, https://repo.anaconda.com/pkgs/main/win-64/win-64::powershell_shortcut-0.0.1-3, https://repo.anaconda.com/pkgs/main/win-64/win-64::win_inet_pton-1.1.0-py39haa95532_0
- defaults/noarch::colorama-0.4.4-pyhd3eb1b0_0, defaults/win-64::console_shortcut-0.1.1-4, https://repo.anaconda.com/pkgs/main/win-64/win-64::powershell_shortcut-0.0.1-3, https://repo.anaconda.com/pkgs/main/win-64/win-64::win_inet_pton-1.1.0-py39haa95532_0
- defaults/win-64::console_shortcut-0.1.1-4, defaults/win-64::powershell_shortcut-0.0.1-3, https://repo.anaconda.com/pkgs/main/noarch/noarch::colorama-0.4.4-pyhd3eb1b0_0, https://repo.anaconda.com/pkgs/main/win-64/win-64::win_inet_pton-1.1.0-py39haa95532_0
- defaults/noarch::colorama-0.4.4-pyhd3eb1b0_0, defaults/win-64::console_shortcut-0.1.1-4, defaults/win-64::powershell_shortcut-0.0.1-3, https://repo.anaconda.com/pkgs/main/win-64/win-64::win_inet_pton-1.1.0-py39haa95532_0
- defaults/win-64::powershell_shortcut-0.0.1-3, https://repo.anaconda.com/pkgs/main/noarch/noarch::colorama-0.4.4-pyhd3eb1b0_0, https://repo.anaconda.com/pkgs/main/win-64/win-64::console_shortcut-0.1.1-4, https://repo.anaconda.com/pkgs/main/win-64/win-64::win_inet_pton-1.1.0-py39haa95532_0
- defaults/noarch::colorama-0.4.4-pyhd3eb1b0_0, defaults/win-64::powershell_shortcut-0.0.1-3, https://repo.anaconda.com/pkgs/main/win-64/win-64::console_shortcut-0.1.1-4, https://repo.anaconda.com/pkgs/main/win-64/win-64::win_inet_pton-1.1.0-py39haa95532_0
- defaults/win-64::powershell_shortcut-0.0.1-3, defaults/win-64::win_inet_pton-1.1.0-py39haa95532_0, https://repo.anaconda.com/pkgs/main/noarch/noarch::colorama-0.4.4-pyhd3eb1b0_0, https://repo.anaconda.com/pkgs/main/win-64/win-64::console_shortcut-0.1.1-4
- defaults/win-64::win_inet_pton-1.1.0-py39haa95532_0, https://repo.anaconda.com/pkgs/main/noarch/noarch::colorama-0.4.4-pyhd3eb1b0_0, https://repo.anaconda.com/pkgs/main/win-64/win-64::console_shortcut-0.1.1-4, https://repo.anaconda.com/pkgs/main/win-64/win-64::powershell_shortcut-0.0.1-3
... and othedone
## Package Plan ##
environment location: D:\Miniconda3
added / updated specs:
- cpuonly
- pytorch
- torchaudio
- torchvision
The following packages will be downloaded:
package | build
---------------------------|-----------------
blas-1.0 | mkl 6 KB defaults
ca-certificates-2022.10.11 | haa95532_0 125 KB defaults
certifi-2022.9.24 | py39haa95532_0 154 KB defaults
conda-22.9.0 | py39haa95532_0 888 KB defaults
cpuonly-2.0 | 0 2 KB pytorch
freetype-2.12.1 | ha860e81_0 490 KB defaults
intel-openmp-2021.4.0 | haa95532_3556 2.2 MB defaults
jpeg-9e | h2bbff1b_0 292 KB defaults
lerc-3.0 | hd77b12b_0 120 KB defaults
libdeflate-1.8 | h2bbff1b_5 46 KB defaults
libpng-1.6.37 | h2a8f88b_0 333 KB defaults
libtiff-4.4.0 | h8a3f274_1 832 KB defaults
libuv-1.40.0 | he774522_0 255 KB defaults
libwebp-1.2.4 | h2bbff1b_0 67 KB defaults
libwebp-base-1.2.4 | h2bbff1b_0 279 KB defaults
lz4-c-1.9.3 | h2bbff1b_1 132 KB defaults
mkl-2021.4.0 | haa95532_640 114.9 MB defaults
mkl-service-2.4.0 | py39h2bbff1b_0 51 KB defaults
mkl_fft-1.3.1 | py39h277e83a_0 139 KB defaults
mkl_random-1.2.2 | py39hf11a4ad_0 225 KB defaults
numpy-1.23.3 | py39h3b20f71_0 11 KB defaults
numpy-base-1.23.3 | py39h4da318b_0 5.0 MB defaults
openssl-1.1.1s | h2bbff1b_0 5.5 MB defaults
pillow-9.2.0 | py39hdc2b20a_1 908 KB defaults
pytorch-1.13.0 | py3.9_cpu_0 138.2 MB pytorch
pytorch-mutex-1.0 | cpu 3 KB pytorch
tk-8.6.12 | h2bbff1b_0 3.1 MB defaults
toolz-0.12.0 | py39haa95532_0 106 KB defaults
torchaudio-0.13.0 | py39_cpu 4.5 MB pytorch
torchvision-0.14.0 | py39_cpu 6.3 MB pytorch
typing_extensions-4.3.0 | py39haa95532_0 42 KB defaults
xz-5.2.6 | h8cc25b3_0 240 KB defaults
zlib-1.2.13 | h8cc25b3_0 113 KB defaults
zstd-1.5.2 | h19a0ad4_0 509 KB defaults
------------------------------------------------------------
Total: 285.8 MB
The following NEW packages will be INSTALLED:
blas pkgs/main/win-64::blas-1.0-mkl
cpuonly pytorch/noarch::cpuonly-2.0-0
freetype pkgs/main/win-64::freetype-2.12.1-ha860e81_0
intel-openmp pkgs/main/win-64::intel-openmp-2021.4.0-haa95532_3556
jpeg pkgs/main/win-64::jpeg-9e-h2bbff1b_0
lerc pkgs/main/win-64::lerc-3.0-hd77b12b_0
libdeflate pkgs/main/win-64::libdeflate-1.8-h2bbff1b_5
libpng pkgs/main/win-64::libpng-1.6.37-h2a8f88b_0
libtiff pkgs/main/win-64::libtiff-4.4.0-h8a3f274_1
libuv pkgs/main/win-64::libuv-1.40.0-he774522_0
libwebp pkgs/main/win-64::libwebp-1.2.4-h2bbff1b_0
libwebp-base pkgs/main/win-64::libwebp-base-1.2.4-h2bbff1b_0
lz4-c pkgs/main/win-64::lz4-c-1.9.3-h2bbff1b_1
mkl pkgs/main/win-64::mkl-2021.4.0-haa95532_640
mkl-service pkgs/main/win-64::mkl-service-2.4.0-py39h2bbff1b_0
mkl_fft pkgs/main/win-64::mkl_fft-1.3.1-py39h277e83a_0
mkl_random pkgs/main/win-64::mkl_random-1.2.2-py39hf11a4ad_0
numpy pkgs/main/win-64::numpy-1.23.3-py39h3b20f71_0
numpy-base pkgs/main/win-64::numpy-base-1.23.3-py39h4da318b_0
pillow pkgs/main/win-64::pillow-9.2.0-py39hdc2b20a_1
pytorch pytorch/win-64::pytorch-1.13.0-py3.9_cpu_0
pytorch-mutex pytorch/noarch::pytorch-mutex-1.0-cpu
tk pkgs/main/win-64::tk-8.6.12-h2bbff1b_0
toolz pkgs/main/win-64::toolz-0.12.0-py39haa95532_0
torchaudio pytorch/win-64::torchaudio-0.13.0-py39_cpu
torchvision pytorch/win-64::torchvision-0.14.0-py39_cpu
typing_extensions pkgs/main/win-64::typing_extensions-4.3.0-py39haa95532_0
xz pkgs/main/win-64::xz-5.2.6-h8cc25b3_0
zlib pkgs/main/win-64::zlib-1.2.13-h8cc25b3_0
zstd pkgs/main/win-64::zstd-1.5.2-h19a0ad4_0
The following packages will be UPDATED:
ca-certificates 2022.3.29-haa95532_1 --> 2022.10.11-haa95532_0
certifi 2021.10.8-py39haa95532_2 --> 2022.9.24-py39haa95532_0
conda 4.12.0-py39haa95532_0 --> 22.9.0-py39haa95532_0
openssl 1.1.1n-h2bbff1b_0 --> 1.1.1s-h2bbff1b_0
Proceed ([y]/n)? y
Downloading and Extracting Packages
xz-5.2.6 | 240 KB | ############################################################################ | 100%
zlib-1.2.13 | 113 KB | ############################################################################ | 100%
zstd-1.5.2 | 509 KB | ############################################################################ | 100%
jpeg-9e | 292 KB | ############################################################################ | 100%
toolz-0.12.0 | 106 KB | ############################################################################ | 100%
torchaudio-0.13.0 | 4.5 MB | ############################################################################ | 100%
certifi-2022.9.24 | 154 KB | ############################################################################ | 100%
cpuonly-2.0 | 2 KB | ############################################################################ | 100%
torchvision-0.14.0 | 6.3 MB | ############################################################################ | 100%
conda-22.9.0 | 888 KB | ############################################################################ | 100%
pytorch-mutex-1.0 | 3 KB | ############################################################################ | 100%
libpng-1.6.37 | 333 KB | ############################################################################ | 100%
lz4-c-1.9.3 | 132 KB | ############################################################################ | 100%
libdeflate-1.8 | 46 KB | ############################################################################ | 100%
libuv-1.40.0 | 255 KB | ############################################################################ | 100%
lerc-3.0 | 120 KB | ############################################################################ | 100%
libtiff-4.4.0 | 832 KB | ############################################################################ | 100%
typing_extensions-4. | 42 KB | ############################################################################ | 100%
numpy-1.23.3 | 11 KB | ############################################################################ | 100%
ca-certificates-2022 | 125 KB | ############################################################################ | 100%
libwebp-base-1.2.4 | 279 KB | ############################################################################ | 100%
freetype-2.12.1 | 490 KB | ############################################################################ | 100%
mkl-2021.4.0 | 114.9 MB | ############################################################################ | 100%
mkl_fft-1.3.1 | 139 KB | ############################################################################ | 100%
numpy-base-1.23.3 | 5.0 MB | ############################################################################ | 100%
intel-openmp-2021.4. | 2.2 MB | ############################################################################ | 100%
mkl_random-1.2.2 | 225 KB | ############################################################################ | 100%
tk-8.6.12 | 3.1 MB | ############################################################################ | 100%
libwebp-1.2.4 | 67 KB | ############################################################################ | 100%
blas-1.0 | 6 KB | ############################################################################ | 100%
openssl-1.1.1s | 5.5 MB | ############################################################################ | 100%
pytorch-1.13.0 | 138.2 MB | ############################################################################ | 100%
mkl-service-2.4.0 | 51 KB | ############################################################################ | 100%
pillow-9.2.0 | 908 KB | ############################################################################ | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
C:\Users\NewBeeChina>
三、创建conda虚拟环境
conda的主要作用就是其可以管理不同版本的python,最典型的场景就是我同时有py2与py3项目,通过conda创建不同的环境就可以同时执行两个版本的py工程.
创建格式:conda create --name 你起的环境名 python=你想创建的py版本
conda create --name LgpLoYo5 python=3.9.12
需要联网下一点包,然后敲命令conda activate 你起的环境名
手动激活刚创建的虚拟环境,若忘了名字可以在磁盘D:\Miniconda3\envs
目录下看到你刚创建的虚拟环境,激活后就如下所示
注意:
1.激活与关闭命令也在如下所示的注释
2.若第一次搭建环境在激活虚拟环境前需关闭重开cmd窗口否则可能报错
done
#
# To activate this environment, use
#
# $ conda activate LgpLoYo5
#
# To deactivate an active environment, use
#
# $ conda deactivate
Retrieving notices: ...working... done
可能的报错:
CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
If using 'conda activate' from a batch script, change your
invocation to 'CALL conda.bat activate'.
To initialize your shell, run
$ conda init <SHELL_NAME>
Currently supported shells are:
- bash
- cmd.exe
- fish
- tcsh
- xonsh
- zsh
- powershell
See 'conda init --help' for more information and options.
IMPORTANT: You may need to close and restart your shell after running 'conda init'.
几个常用参考的命令:
查看版本号:conda -V
初始化:conda init
创建虚拟环境:conda create --name LgpYoLo5 python=3.9.12 -y
激活虚拟环境:conda activate LgpYoLo5
设置自动激活虚拟环境:conda config --set auto_activate_base true
查看所有虚拟环境:conda env list
退出虚拟环境:conda deactivate
四、从git上下载Yolo5
在刚才激活的命令行环境中cd到从git下载的Yolo5工程的目录,我一开始从别人博客复制命令pip install -r requirement.txt
报了错,后发现名称错了,真名为requirements.txt
)
若未进行文件夹的命令行切换则报错,所以在pip前一定要切换命令行的目录到工程根目录下
#未切目录执行命令报错
ERROR: Could not open requirements file: [Errno 2] No such file or directory: 'requirements.txt'
第二次从别人博客上复制的,由于博客将requirements.txt写成requirement.txt报了如下错
(LgpLoYo5) E:\AIWorkSpace\yolov5-master>cd E:\AIWorkSpace\yolov5-master
(LgpLoYo5) E:\AIWorkSpace\yolov5-master>pip install -r requirement.txt
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
ERROR: Could not open requirements file: [Errno 2] No such file or directory: 'requirement.txt'
第三次我是从文件夹里找到了这个文件,手动敲的回车键,开始下载requirements.txt里列出的包,但是报了错,
(LgpLoYo5) E:\AIWorkSpace\yolov5-master>pip install -r requirements.txt
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
Collecting ipython
Downloading ipython-8.6.0-py3-none-any.whl (761 kB)
---------------------------------------- 761.1/761.1 kB 18.4 kB/s eta 0:00:00
Collecting matplotlib>=3.2.2
Downloading matplotlib-3.6.2-cp39-cp39-win_amd64.whl (7.2 MB)
---------------------------------------- 0.1/7.2 MB 14.5 kB/s eta 0:08:14
ERROR: Exception:
Traceback (most recent call last):
File "D:\Miniconda3\envs\LgpLoYo5\lib\site-packages\pip\_vendor\urllib3\response.py", line 435, in _error_catcher
yield
File "D:\Miniconda3\envs\LgpLoYo5\lib\site-packages\pip\_vendor\urllib3\response.py", line 516, in read
data = self._fp.read(amt) if not fp_closed else b""
File "D:\Miniconda3\envs\LgpLoYo5\lib\site-packages\pip\_vendor\cachecontrol\filewrapper.py", line 90, in read
data = self.__fp.read(amt)
File "D:\Miniconda3\envs\LgpLoYo5\lib\http\client.py", line 463, in read
n = self.readinto(b)
File "D:\Miniconda3\envs\LgpLoYo5\lib\http\client.py", line 507, in readinto
n = self.fp.readinto(b)
File "D:\Miniconda3\envs\LgpLoYo5\lib\socket.py", line 704, in readinto
return self._sock.recv_into(b)
File "D:\Miniconda3\envs\LgpLoYo5\lib\ssl.py", line 1241, in recv_into
return self.read(nbytes, buffer)
File "D:\Miniconda3\envs\LgpLoYo5\lib\ssl.py", line 1099, in read
return self._sslobj.read(len, buffer)
socket.timeout: The read operation timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\Miniconda3\envs\LgpLoYo5\lib\site-packages\pip\_internal\cli\base_command.py", line 167, in exc_logging_wrapper
status = run_func(*args)
File "D:\Miniconda3\envs\LgpLoYo5\lib\site-packages\pip\_internal\cli\req_command.py", line 247, in wrapper
return func(self, options, args)
File "D:\Miniconda3\envs\LgpLoYo5\lib\site-packages\pip\_internal\commands\install.py", line 369, in run
requirement_set = resolver.resolve(
File "D:\Miniconda3\envs\LgpLoYo5\lib\site-packages\pip\_internal\resolution\resolvelib\resolver.py", line 92, in resolve
result = self._result = resolver.resolve(
File "D:\Miniconda3\envs\LgpLoYo5\lib\site-packages\pip\_vendor\resolvelib\resolvers.py", line 481, in resolve
state = resolution.resolve(requirements, max_rounds=max_rounds)
File "D:\Miniconda3\envs\LgpLoYo5\lib\site-packages\pip\_vendor\resolvelib\resolvers.py", line 348, in resolve
self._add_to_criteria(self.state.criteria, r, parent=None)
File "D:\Miniconda3\envs\LgpLoYo5\lib\site-packages\pip\_vendor\resolvelib\resolvers.py", line 172, in _add_to_criteria
if not criterion.candidates:
File "D:\Miniconda3\envs\LgpLoYo5\lib\site-packages\pip\_vendor\resolvelib\structs.py", line 151, in __bool__
return bool(self._sequence)
File "D:\Miniconda3\envs\LgpLoYo5\lib\site-packages\pip\_internal\resolution\resolvelib\found_candidates.py", line 155, in __bool__
return any(self)
File "D:\Miniconda3\envs\LgpLoYo5\lib\site-packages\pip\_internal\resolution\resolvelib\found_candidates.py", line 143, in <genexpr>
return (c for c in iterator if id(c) not in self._incompatible_ids)
File "D:\Miniconda3\envs\LgpLoYo5\lib\site-packages\pip\_internal\resolution\resolvelib\found_candidates.py", line 47, in _iter_built
candidate = func()
File "D:\Miniconda3\envs\LgpLoYo5\lib\site-packages\pip\_internal\resolution\resolvelib\factory.py", line 206, in _make_candidate_from_link
self._link_candidate_cache[link] = LinkCandidate(
File "D:\Miniconda3\envs\LgpLoYo5\lib\site-packages\pip\_internal\resolution\resolvelib\candidates.py", line 297, in __init__
super().__init__(
File "D:\Miniconda3\envs\LgpLoYo5\lib\site-packages\pip\_internal\resolution\resolvelib\candidates.py", line 162, in __init__
self.dist = self._prepare()
File "D:\Miniconda3\envs\LgpLoYo5\lib\site-packages\pip\_internal\resolution\resolvelib\candidates.py", line 231, in _prepare
dist = self._prepare_distribution()
File "D:\Miniconda3\envs\LgpLoYo5\lib\site-packages\pip\_internal\resolution\resolvelib\candidates.py", line 308, in _prepare_distribution
return preparer.prepare_linked_requirement(self._ireq, parallel_builds=True)
File "D:\Miniconda3\envs\LgpLoYo5\lib\site-packages\pip\_internal\operations\prepare.py", line 438, in prepare_linked_requirement
return self._prepare_linked_requirement(req, parallel_builds)
File "D:\Miniconda3\envs\LgpLoYo5\lib\site-packages\pip\_internal\operations\prepare.py", line 483, in _prepare_linked_requirement
local_file = unpack_url(
File "D:\Miniconda3\envs\LgpLoYo5\lib\site-packages\pip\_internal\operations\prepare.py", line 165, in unpack_url
file = get_http_url(
File "D:\Miniconda3\envs\LgpLoYo5\lib\site-packages\pip\_internal\operations\prepare.py", line 106, in get_http_url
from_path, content_type = download(link, temp_dir.path)
File "D:\Miniconda3\envs\LgpLoYo5\lib\site-packages\pip\_internal\network\download.py", line 147, in __call__
for chunk in chunks:
File "D:\Miniconda3\envs\LgpLoYo5\lib\site-packages\pip\_internal\cli\progress_bars.py", line 53, in _rich_progress_bar
for chunk in iterable:
File "D:\Miniconda3\envs\LgpLoYo5\lib\site-packages\pip\_internal\network\utils.py", line 63, in response_chunks
for chunk in response.raw.stream(
File "D:\Miniconda3\envs\LgpLoYo5\lib\site-packages\pip\_vendor\urllib3\response.py", line 573, in stream
data = self.read(amt=amt, decode_content=decode_content)
File "D:\Miniconda3\envs\LgpLoYo5\lib\site-packages\pip\_vendor\urllib3\response.py", line 538, in read
raise IncompleteRead(self._fp_bytes_read, self.length_remaining)
File "D:\Miniconda3\envs\LgpLoYo5\lib\contextlib.py", line 137, in __exit__
self.gen.throw(typ, value, traceback)
File "D:\Miniconda3\envs\LgpLoYo5\lib\site-packages\pip\_vendor\urllib3\response.py", line 440, in _error_catcher
raise ReadTimeoutError(self._pool, None, "Read timed out.")
pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.
打开requirements.txt文件查看,很明显是下载第二个包matplotlib时发生了错误
# YOLOv5 🚀 requirements
# Usage: pip install -r requirements.txt
# Base ------------------------------------------------------------------------
ipython # interactive notebook
matplotlib>=3.2.2
numpy>=1.18.5
opencv-python>=4.1.1
Pillow>=7.1.2
psutil # system resources
PyYAML>=5.3.1
requests>=2.23.0
scipy>=1.4.1
thop>=0.1.1 # FLOPs computation
torch>=1.7.0 # see https://pytorch.org/get-started/locally (recommended)
torchvision>=0.8.1
tqdm>=4.64.0
# protobuf<=3.20.1 # https://github.com/ultralytics/yolov5/issues/8012
# Logging ---------------------------------------------------------------------
tensorboard>=2.4.1
# clearml>=1.2.0
# comet
# Plotting --------------------------------------------------------------------
pandas>=1.1.4
seaborn>=0.11.0
# Export ----------------------------------------------------------------------
# coremltools>=6.0 # CoreML export
# onnx>=1.9.0 # ONNX export
# onnx-simplifier>=0.4.1 # ONNX simplifier
# nvidia-pyindex # TensorRT export
# nvidia-tensorrt # TensorRT export
# scikit-learn<=1.1.2 # CoreML quantization
# tensorflow>=2.4.1 # TF exports (-cpu, -aarch64, -macos)
# tensorflowjs>=3.9.0 # TF.js export
# openvino-dev # OpenVINO export
# Deploy ----------------------------------------------------------------------
# tritonclient[all]~=2.24.0
# Extras ----------------------------------------------------------------------
# mss # screenshots
# albumentations>=1.0.3
# pycocotools>=2.0 # COCO mAP
# roboflow
# ultralytics # HUB https://hub.ultralytics.com
不服输,又把命令敲了一次,但是又发生了报错
本次:
Collecting matplotlib>=3.2.2
Downloading matplotlib-3.6.2-cp39-cp39-win_amd64.whl (7.2 MB)
----------------------------- ---------- 5.4/7.2 MB 4.2 kB/s eta 0:07:20
上一次:
Collecting matplotlib>=3.2.2
Downloading matplotlib-3.6.2-cp39-cp39-win_amd64.whl (7.2 MB)
---------------------------------------- 0.1/7.2 MB 14.5 kB/s eta 0:08:14
巧了么不是,这TNND网络不稳定还是咋地,后来查博客发现了如下命令,它是有效的(不要试图将此链接添加至.condarc文件中使用,它就是个临时工官网详情)
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements.txt
安装日志如下:
Microsoft Windows [版本 10.0.19044.2130]
(c) Microsoft Corporation。保留所有权利。
C:\Users\NewBeeChina>e:
E:\>cd E:\AIWorkSpace\yolov5-master
E:\AIWorkSpace\yolov5-master>conda activate LgpLoYo5
(LgpLoYo5) E:\AIWorkSpace\yolov5-master>pip install -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements.txt
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting ipython
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/c7/53/072d677a16fd61f5806d80218c65202cc0ee77b831088af8f79ef59efcf2/ipython-8.6.0-py3-none-any.whl (761 kB)
---------------------------------------- 761.1/761.1 kB 1.2 MB/s eta 0:00:00
Collecting matplotlib>=3.2.2
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/78/af/4c83c99656c500ca0db7fe6f349d6309372ea8bad9c78d5c161930977bfd/matplotlib-3.6.2-cp39-cp39-win_amd64.whl (7.2 MB)
---------------------------------------- 7.2/7.2 MB 2.1 MB/s eta 0:00:00
Collecting numpy>=1.18.5
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/af/74/c02ece94ef88bed0a7f266959fd9bb2c97140345bc792f281b7db390eea9/numpy-1.23.4-cp39-cp39-win_amd64.whl (14.7 MB)
---------------------------------------- 14.7/14.7 MB 2.4 MB/s eta 0:00:00
Collecting opencv-python>=4.1.1
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/cf/09/b24c266cd61ddeed101b90c92a26f54d060b06f4a1b102eb891576d6e9e2/opencv_python-4.6.0.66-cp36-abi3-win_amd64.whl (35.6 MB)
---------------------------------------- 35.6/35.6 MB 3.0 MB/s eta 0:00:00
Collecting Pillow>=7.1.2
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/c0/8f/dfa473f3a6241bff91ae8bb905bd0afceb827f37de2917a94b5c4b1112bf/Pillow-9.3.0-cp39-cp39-win_amd64.whl (2.5 MB)
---------------------------------------- 2.5/2.5 MB 2.7 MB/s eta 0:00:00
Collecting psutil
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/25/6e/ba97809175c90cbdcd33b470e466ebf0854d15d1506e605cc0ddd284d5b6/psutil-5.9.4-cp36-abi3-win_amd64.whl (252 kB)
---------------------------------------- 252.5/252.5 kB 3.9 MB/s eta 0:00:00
Collecting PyYAML>=5.3.1
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/08/f4/ffa743f860f34a5e8c60abaaa686f82c9ac7a2b50e5a1c3b1eb564d59159/PyYAML-6.0-cp39-cp39-win_amd64.whl (151 kB)
---------------------------------------- 151.6/151.6 kB 4.4 MB/s eta 0:00:00
Collecting requests>=2.23.0
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/ca/91/6d9b8ccacd0412c08820f72cebaa4f0c0441b5cda699c90f618b6f8a1b42/requests-2.28.1-py3-none-any.whl (62 kB)
---------------------------------------- 62.8/62.8 kB ? eta 0:00:00
Collecting scipy>=1.4.1
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/d0/96/4f6eac3fea18f836a0e403539556b1684e6f3361fa39aa5d5797dedecd75/scipy-1.9.3-cp39-cp39-win_amd64.whl (40.2 MB)
---------------------------------------- 40.2/40.2 MB 2.9 MB/s eta 0:00:00
Collecting thop>=0.1.1
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/bb/0f/72beeab4ff5221dc47127c80f8834b4bcd0cb36f6ba91c0b1d04a1233403/thop-0.1.1.post2209072238-py3-none-any.whl (15 kB)
Collecting torch>=1.7.0
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/4c/d9/713853e06954bb657607d1e59d29e5896e1933e5d7fb50847a5730ad7325/torch-1.13.0-cp39-cp39-win_amd64.whl (167.2 MB)
---------------------------------------- 167.2/167.2 MB 2.3 MB/s eta 0:00:00
Collecting torchvision>=0.8.1
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/a7/f3/aaac29c2cdb84b0be1302aa17a68a7c39b05d9bca810d144e42c7131fb0d/torchvision-0.14.0-cp39-cp39-win_amd64.whl (1.1 MB)
---------------------------------------- 1.1/1.1 MB 2.4 MB/s eta 0:00:00
Collecting tqdm>=4.64.0
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/47/bb/849011636c4da2e44f1253cd927cfb20ada4374d8b3a4e425416e84900cc/tqdm-4.64.1-py2.py3-none-any.whl (78 kB)
---------------------------------------- 78.5/78.5 kB 1.5 MB/s eta 0:00:00
Collecting tensorboard>=2.4.1
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/05/70/ee7968f4a92ff9f95354d0ccaa9c0ba17b2644a33472ea845d92dd4e4821/tensorboard-2.11.0-py3-none-any.whl (6.0 MB)
---------------------------------------- 6.0/6.0 MB 1.6 MB/s eta 0:00:00
Collecting pandas>=1.1.4
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/60/53/619c0bcdc45b0a2ac94fc840c67073f8ca3f69344383c7dca0ed20e1ea73/pandas-1.5.1-cp39-cp39-win_amd64.whl (10.9 MB)
---------------------------------------- 10.9/10.9 MB 2.7 MB/s eta 0:00:00
Collecting seaborn>=0.11.0
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/77/18/7354cb68dd7906d5a3118e0ed3e30c37502f9e6253139ecfcf4fa33af210/seaborn-0.12.1-py3-none-any.whl (288 kB)
---------------------------------------- 288.2/288.2 kB 658.7 kB/s eta 0:00:00
Collecting traitlets>=5
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/ed/f9/caefd8c90955184e7426ef930e38c185e047169b520b35bdd57d341d03f4/traitlets-5.5.0-py3-none-any.whl (107 kB)
---------------------------------------- 107.4/107.4 kB 2.1 MB/s eta 0:00:00
Collecting decorator
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/d5/50/83c593b07763e1161326b3b8c6686f0f4b0f24d5526546bee538c89837d6/decorator-5.1.1-py3-none-any.whl (9.1 kB)
Collecting colorama
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/d1/d6/3965ed04c63042e047cb6a3e6ed1a63a35087b6a609aa3a15ed8ac56c221/colorama-0.4.6-py2.py3-none-any.whl (25 kB)
Collecting pygments>=2.4.0
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/4f/82/672cd382e5b39ab1cd422a672382f08a1fb3d08d9e0c0f3707f33a52063b/Pygments-2.13.0-py3-none-any.whl (1.1 MB)
---------------------------------------- 1.1/1.1 MB 725.7 kB/s eta 0:00:00
Collecting stack-data
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/0b/d3/87a41424a1d24d2cb9f5ae4ef4a97c7437ad81eb37d21049ce5decd13d70/stack_data-0.6.0-py3-none-any.whl (24 kB)
Collecting pickleshare
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/9a/41/220f49aaea88bc6fa6cba8d05ecf24676326156c23b991e80b3f2fc24c77/pickleshare-0.7.5-py2.py3-none-any.whl (6.9 kB)
Collecting backcall
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/4c/1c/ff6546b6c12603d8dd1070aa3c3d273ad4c07f5771689a7b69a550e8c951/backcall-0.2.0-py2.py3-none-any.whl (11 kB)
Collecting jedi>=0.16
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/b3/0e/836f12ec50075161e365131f13f5758451645af75c2becf61c6351ecec39/jedi-0.18.1-py2.py3-none-any.whl (1.6 MB)
---------------------------------------- 1.6/1.6 MB 748.9 kB/s eta 0:00:00
Collecting matplotlib-inline
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/f2/51/c34d7a1d528efaae3d8ddb18ef45a41f284eacf9e514523b191b7d0872cc/matplotlib_inline-0.1.6-py3-none-any.whl (9.4 kB)
Collecting prompt-toolkit<3.1.0,>3.0.1
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/03/22/784990e865d847384c28a05ff33ed09791251b320c212f957c62a11bd2ab/prompt_toolkit-3.0.32-py3-none-any.whl (382 kB)
---------------------------------------- 382.8/382.8 kB 335.9 kB/s eta 0:00:00
Collecting pyparsing>=2.2.1
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/6c/10/a7d0fa5baea8fe7b50f448ab742f26f52b80bfca85ac2be9d35cdd9a3246/pyparsing-3.0.9-py3-none-any.whl (98 kB)
---------------------------------------- 98.3/98.3 kB 704.8 kB/s eta 0:00:00
Collecting kiwisolver>=1.0.1
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/49/b9/edd9b69e1f2a8339347bcfcfbb14ce19db4a81158d01d8fd26fc3a088109/kiwisolver-1.4.4-cp39-cp39-win_amd64.whl (55 kB)
---------------------------------------- 55.4/55.4 kB ? eta 0:00:00
Collecting python-dateutil>=2.7
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/36/7a/87837f39d0296e723bb9b62bbb257d0355c7f6128853c78955f57342a56d/python_dateutil-2.8.2-py2.py3-none-any.whl (247 kB)
---------------------------------------- 247.7/247.7 kB 562.7 kB/s eta 0:00:00
Collecting packaging>=20.0
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/05/8e/8de486cbd03baba4deef4142bd643a3e7bbe954a784dc1bb17142572d127/packaging-21.3-py3-none-any.whl (40 kB)
---------------------------------------- 40.8/40.8 kB 1.9 MB/s eta 0:00:00
Collecting fonttools>=4.22.0
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/e3/d9/e9bae85e84737e76ebbcbea13607236da0c0699baed0ae4f1151b728a608/fonttools-4.38.0-py3-none-any.whl (965 kB)
---------------------------------------- 965.4/965.4 kB 955.1 kB/s eta 0:00:00
Collecting cycler>=0.10
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/5c/f9/695d6bedebd747e5eb0fe8fad57b72fdf25411273a39791cde838d5a8f51/cycler-0.11.0-py3-none-any.whl (6.4 kB)
Collecting contourpy>=1.0.1
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/a6/43/05ca3815a88650734860766e4d25a98ee7b8bf9d5f4fe280438c07ba5f4f/contourpy-1.0.6-cp39-cp39-win_amd64.whl (161 kB)
---------------------------------------- 161.3/161.3 kB 807.9 kB/s eta 0:00:00
Collecting idna<4,>=2.5
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/fc/34/3030de6f1370931b9dbb4dad48f6ab1015ab1d32447850b9fc94e60097be/idna-3.4-py3-none-any.whl (61 kB)
---------------------------------------- 61.5/61.5 kB 814.3 kB/s eta 0:00:00
Collecting charset-normalizer<3,>=2
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/db/51/a507c856293ab05cdc1db77ff4bc1268ddd39f29e7dc4919aa497f0adbec/charset_normalizer-2.1.1-py3-none-any.whl (39 kB)
Collecting urllib3<1.27,>=1.21.1
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/6f/de/5be2e3eed8426f871b170663333a0f627fc2924cc386cd41be065e7ea870/urllib3-1.26.12-py2.py3-none-any.whl (140 kB)
---------------------------------------- 140.4/140.4 kB 834.2 kB/s eta 0:00:00
Requirement already satisfied: certifi>=2017.4.17 in d:\miniconda3\envs\lgployo5\lib\site-packages (from requests>=2.23.0->-r requirements.txt (line 12)) (2022.9.24)
Collecting typing-extensions
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/0b/8e/f1a0a5a76cfef77e1eb6004cb49e5f8d72634da638420b9ea492ce8305e8/typing_extensions-4.4.0-py3-none-any.whl (26 kB)
Requirement already satisfied: wheel>=0.26 in d:\miniconda3\envs\lgployo5\lib\site-packages (from tensorboard>=2.4.1->-r requirements.txt (line 21)) (0.37.1)
Collecting tensorboard-data-server<0.7.0,>=0.6.0
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/74/69/5747a957f95e2e1d252ca41476ae40ce79d70d38151d2e494feb7722860c/tensorboard_data_server-0.6.1-py3-none-any.whl (2.4 kB)
Collecting werkzeug>=1.0.1
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/c8/27/be6ddbcf60115305205de79c29004a0c6bc53cec814f733467b1bb89386d/Werkzeug-2.2.2-py3-none-any.whl (232 kB)
---------------------------------------- 232.7/232.7 kB 158.1 kB/s eta 0:00:00
Requirement already satisfied: setuptools>=41.0.0 in d:\miniconda3\envs\lgployo5\lib\site-packages (from tensorboard>=2.4.1->-r requirements.txt (line 21)) (65.5.0)
Collecting grpcio>=1.24.3
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/e1/20/38ea842e338fb62384629d65d17f494c0f348bc3c16e81df607b31eb70ff/grpcio-1.50.0-cp39-cp39-win_amd64.whl (3.7 MB)
---------------------------------------- 3.7/3.7 MB 256.7 kB/s eta 0:00:00
Collecting google-auth<3,>=1.6.3
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/9b/9b/f40ea5c60762eabeb17cebdc05c395f44584c5c7fd7ce636a869c4f1e05d/google_auth-2.14.1-py2.py3-none-any.whl (175 kB)
---------------------------------------- 175.4/175.4 kB 330.2 kB/s eta 0:00:00
Collecting google-auth-oauthlib<0.5,>=0.4.1
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/b1/0e/0636cc1448a7abc444fb1b3a63655e294e0d2d49092dc3de05241be6d43c/google_auth_oauthlib-0.4.6-py2.py3-none-any.whl (18 kB)
Collecting tensorboard-plugin-wit>=1.6.0
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/e0/68/e8ecfac5dd594b676c23a7f07ea34c197d7d69b3313afdf8ac1b0a9905a2/tensorboard_plugin_wit-1.8.1-py3-none-any.whl (781 kB)
---------------------------------------- 781.3/781.3 kB 262.5 kB/s eta 0:00:00
Collecting protobuf<4,>=3.9.2
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/11/a5/e52b731415ad6ef3d841e9e6e337a690249e800cc7c06f0749afab26348c/protobuf-3.20.3-cp39-cp39-win_amd64.whl (904 kB)
---------------------------------------- 904.2/904.2 kB 457.7 kB/s eta 0:00:00
Collecting markdown>=2.6.8
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/86/be/ad281f7a3686b38dd8a307fa33210cdf2130404dfef668a37a4166d737ca/Markdown-3.4.1-py3-none-any.whl (93 kB)
---------------------------------------- 93.3/93.3 kB 532.4 kB/s eta 0:00:00
Collecting absl-py>=0.4
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/2c/39/ba081c6f7837366a39c9286fa1bc9dbf217249df80e133f25c62b05d1a53/absl_py-1.3.0-py3-none-any.whl (124 kB)
---------------------------------------- 124.6/124.6 kB 522.1 kB/s eta 0:00:00
Collecting pytz>=2020.1
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/85/ac/92f998fc52a70afd7f6b788142632afb27cd60c8c782d1452b7466603332/pytz-2022.6-py2.py3-none-any.whl (498 kB)
---------------------------------------- 498.1/498.1 kB 578.0 kB/s eta 0:00:00
Collecting six>=1.9.0
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/d9/5a/e7c31adbe875f2abbb91bd84cf2dc52d792b5a01506781dbcf25c91daf11/six-1.16.0-py2.py3-none-any.whl (11 kB)
Collecting rsa<5,>=3.1.4
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/49/97/fa78e3d2f65c02c8e1268b9aba606569fe97f6c8f7c2d74394553347c145/rsa-4.9-py3-none-any.whl (34 kB)
Collecting pyasn1-modules>=0.2.1
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/95/de/214830a981892a3e286c3794f41ae67a4495df1108c3da8a9f62159b9a9d/pyasn1_modules-0.2.8-py2.py3-none-any.whl (155 kB)
---------------------------------------- 155.3/155.3 kB 422.8 kB/s eta 0:00:00
Collecting cachetools<6.0,>=2.0.0
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/68/aa/5fc646cae6e997c3adf3b0a7e257cda75cff21fcba15354dffd67789b7bb/cachetools-5.2.0-py3-none-any.whl (9.3 kB)
Collecting requests-oauthlib>=0.7.0
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/6f/bb/5deac77a9af870143c684ab46a7934038a53eb4aa975bc0687ed6ca2c610/requests_oauthlib-1.3.1-py2.py3-none-any.whl (23 kB)
Collecting parso<0.9.0,>=0.8.0
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/05/63/8011bd08a4111858f79d2b09aad86638490d62fbf881c44e434a6dfca87b/parso-0.8.3-py2.py3-none-any.whl (100 kB)
---------------------------------------- 100.8/100.8 kB 131.6 kB/s eta 0:00:00
Collecting importlib-metadata>=4.4
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/b5/64/ef29a63cf08f047bb7fb22ab0f1f774b87eed0bb46d067a5a524798a4af8/importlib_metadata-5.0.0-py3-none-any.whl (21 kB)
Collecting wcwidth
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/59/7c/e39aca596badaf1b78e8f547c807b04dae603a433d3e7a7e04d67f2ef3e5/wcwidth-0.2.5-py2.py3-none-any.whl (30 kB)
Collecting MarkupSafe>=2.1.1
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/71/dc/41cbfe0d9aefdf14226dbf4eccfd0079a0e297809a17c5b902c9a7a3cc9a/MarkupSafe-2.1.1-cp39-cp39-win_amd64.whl (17 kB)
Collecting asttokens>=2.1.0
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/23/f7/19e20888d0b1e44b40c2795894a05e7be1f631c09949f7e0b177df1ab7a2/asttokens-2.1.0-py2.py3-none-any.whl (26 kB)
Collecting pure-eval
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/2b/27/77f9d5684e6bce929f5cfe18d6cfbe5133013c06cb2fbf5933670e60761d/pure_eval-0.2.2-py3-none-any.whl (11 kB)
Collecting executing>=1.2.0
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/28/3c/bc3819dd8b1a1588c9215a87271b6178cc5498acaa83885211f5d4d9e693/executing-1.2.0-py2.py3-none-any.whl (24 kB)
Collecting zipp>=0.5
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/40/8a/d63273ed0fa4a3d06f77e7b043f6577d8894e95515b0c187c52e2c0efabb/zipp-3.10.0-py3-none-any.whl (6.2 kB)
Collecting pyasn1<0.5.0,>=0.4.6
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/62/1e/a94a8d635fa3ce4cfc7f506003548d0a2447ae76fd5ca53932970fe3053f/pyasn1-0.4.8-py2.py3-none-any.whl (77 kB)
---------------------------------------- 77.1/77.1 kB 214.4 kB/s eta 0:00:00
Collecting oauthlib>=3.0.0
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/7e/80/cab10959dc1faead58dc8384a781dfbf93cb4d33d50988f7a69f1b7c9bbe/oauthlib-3.2.2-py3-none-any.whl (151 kB)
---------------------------------------- 151.7/151.7 kB 274.7 kB/s eta 0:00:00
Installing collected packages: wcwidth, tensorboard-plugin-wit, pytz, pyasn1, pure-eval, pickleshare, executing, backcall, zipp, urllib3, typing-extensions, traitlets, tensorboard-data-server, six, rsa, PyYAML, pyparsing, pygments, pyasn1-modules, psutil, protobuf, prompt-toolkit, Pillow, parso, oauthlib, numpy, MarkupSafe, kiwisolver, idna, fonttools, decorator, cycler, colorama, charset-normalizer, cachetools, absl-py, werkzeug, tqdm, torch, scipy, requests, python-dateutil, packaging, opencv-python, matplotlib-inline, jedi, importlib-metadata, grpcio, google-auth, contourpy, asttokens, torchvision, thop, stack-data, requests-oauthlib, pandas, matplotlib, markdown, seaborn, ipython, google-auth-oauthlib, tensorboard
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
Successfully installed MarkupSafe-2.1.1 Pillow-9.3.0 PyYAML-6.0 absl-py-1.3.0 asttokens-2.1.0 backcall-0.2.0 cachetools-5.2.0 charset-normalizer-2.1.1 colorama-0.4.6 contourpy-1.0.6 cycler-0.11.0 decorator-5.1.1 executing-1.2.0 fonttools-4.38.0 google-auth-2.14.1 google-auth-oauthlib-0.4.6 grpcio-1.50.0 idna-3.4 importlib-metadata-5.0.0 ipython-8.6.0 jedi-0.18.1 kiwisolver-1.4.4 markdown-3.4.1 matplotlib-3.6.2 matplotlib-inline-0.1.6 numpy-1.23.4 oauthlib-3.2.2 opencv-python-4.6.0.66 packaging-21.3 pandas-1.5.1 parso-0.8.3 pickleshare-0.7.5 prompt-toolkit-3.0.32 protobuf-3.20.3 psutil-5.9.4 pure-eval-0.2.2 pyasn1-0.4.8 pyasn1-modules-0.2.8 pygments-2.13.0 pyparsing-3.0.9 python-dateutil-2.8.2 pytz-2022.6 requests-2.28.1 requests-oauthlib-1.3.1 rsa-4.9 scipy-1.9.3 seaborn-0.12.1 six-1.16.0 stack-data-0.6.0 tensorboard-2.11.0 tensorboard-data-server-0.6.1 tensorboard-plugin-wit-1.8.1 thop-0.1.1.post2209072238 torch-1.13.0 torchvision-0.14.0 tqdm-4.64.1 traitlets-5.5.0 typing-extensions-4.4.0 urllib3-1.26.12 wcwidth-0.2.5 werkzeug-2.2.2 zipp-3.10.0
(LgpLoYo5) E:\AIWorkSpace\yolov5-master>
(LgpLoYo5) E:\AIWorkSpace\yolov5-master>
五、图片数据标记软件
数据标注软件市面上有很多,也有一些是自家开发的,此处介绍两种,转换为yolo5所需要的数据,本文使用的是精灵标注助手。
- 精灵标注助手
这款软件免费强大,可以多点标记,但目前掌握的脚本只支持4点矩形转换为Yolo的训练数据,所以画矩形,导出pascal-voc格式的数据。 - labelimg(他是pyqt5写的,支持三种框架,但只能画4个点的矩形框)
此处使用了临时镜像,原语句为pip install labelimg
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple labelimg
安装日志:
(LgpLoYo5) E:\AIWorkSpace\yolov5-master>pip install -i https://pypi.tuna.tsinghua.edu.cn/simple labelimg
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting labelimg
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/c5/fb/9947097363fbbfde3921f7cf7ce9800c89f909d26a506145aec37c75cda7/labelImg-1.8.6.tar.gz (247 kB)
---------------------------------------- 247.7/247.7 kB 892.6 kB/s eta 0:00:00
Preparing metadata (setup.py) ... done
Collecting pyqt5
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/bd/85/31a12415765acb48fddac3e207cfffcbbae826fe194cf1d92179d8872f59/PyQt5-5.15.7-cp37-abi3-win_amd64.whl (6.8 MB)
---------------------------------------- 6.8/6.8 MB 2.8 MB/s eta 0:00:00
Collecting lxml
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/17/78/7cc7e269c7c58f0b94c4abdf6cf2bcce2fb0ca58d415e6e4e1b805cd9f17/lxml-4.9.1-cp39-cp39-win_amd64.whl (3.6 MB)
---------------------------------------- 3.6/3.6 MB 2.4 MB/s eta 0:00:00
Collecting PyQt5-Qt5>=5.15.0
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/37/97/5d3b222b924fa2ed4c2488925155cd0b03fd5d09ee1cfcf7c553c11c9f66/PyQt5_Qt5-5.15.2-py3-none-win_amd64.whl (50.1 MB)
---------------------------------------- 50.1/50.1 MB 864.1 kB/s eta 0:00:00
Collecting PyQt5-sip<13,>=12.11
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/d1/85/e30b11daf7b8d4e00ed51c17204ec3df446041206d22087d2c5dc17d8543/PyQt5_sip-12.11.0-cp39-cp39-win_amd64.whl (78 kB)
---------------------------------------- 78.3/78.3 kB 1.4 MB/s eta 0:00:00
Building wheels for collected packages: labelimg
Building wheel for labelimg (setup.py) ... done
Created wheel for labelimg: filename=labelImg-1.8.6-py2.py3-none-any.whl size=261524 sha256=fbba7beb072b63726ff5f9032343755ca971f144630c1808903f87c5ff277364
Stored in directory: c:\users\newbeechina\appdata\local\pip\cache\wheels\d6\ba\ac\0b1de7ebb0074df1740d334b53680cbca868c0d4792450d895
Successfully built labelimg
Installing collected packages: PyQt5-Qt5, PyQt5-sip, lxml, pyqt5, labelimg
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
WARNING: Ignore distutils configs in setup.cfg due to encoding errors.
Successfully installed PyQt5-Qt5-5.15.2 PyQt5-sip-12.11.0 labelimg-1.8.6 lxml-4.9.1 pyqt5-5.15.7
六、数据标记
-
精灵标注助手
新建➠位置标注➠填写 项目名称、设置标注图片文件夹、设置即将标注的分类,用矩形框进行标记,你要问我能不能用多边形框进行标记,从我目前获得的脚本来看只能转换四点的bndbox无法转换cubic_bezier。 -
labelimg
image.png
在当前虚拟环境中敲击labelimg
会打开标记软件,目前它仅支持PascalVOC
、YOLO
、CreateML
三种标记,它默认是PascalVOC
所以我们需要将其切换为YOLO
点击Open Dir -> 选择需要标注的文件夹 -> ok
七、数据筹备
- 理论指引
训练集(train set):训练模型
验证集(val set):评估模型,用来调整模型参数从而选择最优模型
测试集(test set):一旦找到了最佳参数,就开始最终训练
一组数据大致分为以上三类,
在深度学习中,由于数据量本身很大,而且训练神经网络需要的数据很多,可以把更多的数据分给training,而相应减少validation和test,这三者一般的比例为training:validation:test = 2:1:1, 但是有些时候如果模型不需要很多调整只要拟合就可时,或者training本身就是training+validation (比如cross validation)时,也可以比例为training:test =7:3,这一段描述从网上找的,准确性不敢保证但好歹我现在能配置比例了。 - 实操
建立以下文件夹
1)根目录/data/Annotations
储存pascal-voc格式.xml数据。
2)根目录/data/ImageSets
存储脚本生成的train.txt
、test.txt
、val.txt
、trainval.txt
;这几个文本文件存储的待训练图片文件名称。
3)根目录/data/JPEGImages
存储所有训练图片
在根目录创建preLabelsTxt.py,运行后在 ./data/ImageSets 会生成数据集分类txt文件,内容是一批图片名
preLabelsTxt.py:
import os
import random
ROOT_PATH = 'E:/PyWorkSpace/LgpYolov53/'
trainval_percent = 0.3
train_percent = 0.7
xmlfilepath = ROOT_PATH + 'data/Annotations'
txtsavepath = ROOT_PATH + 'data/ImageSets'
total_xml = os.listdir(xmlfilepath)
num = len(total_xml)
list = range(num)
tv = int(num * trainval_percent)
tr = int(tv * train_percent)
trainval = random.sample(list, tv)
train = random.sample(trainval, tr)
ftrainval = open(ROOT_PATH + 'data/ImageSets/trainval.txt', 'w',encoding='utf-8')
ftest = open(ROOT_PATH + 'data/ImageSets/test.txt', 'w',encoding='utf-8')
ftrain = open(ROOT_PATH + 'data/ImageSets/train.txt', 'w',encoding='utf-8')
fval = open(ROOT_PATH + 'data/ImageSets/val.txt', 'w',encoding='utf-8')
for i in list:
name = total_xml[i][:-4] + '\n'
if i in trainval:
ftrainval.write(name)
if i in train:
ftest.write(name)
else:
fval.write(name)
else:
ftrain.write(name)
ftrainval.close()
ftrain.close()
fval.close()
ftest.close()
在根目录创建convertLabels.py,运行后会生成根目录/data/labels/...
在labels文件夹下就是Yolo5框架训练所需的标注数据集,并且在/data/目录下生成test.txt、train.txt、val.txt 三个带储存路径的txt图片数据集
convertLabels.py:
import xml.etree.ElementTree as ET
import pickle
import os
from os import listdir, getcwd
from os.path import join
ROOT_PATH = 'E:/PyWorkSpace/LgpYolov53/'
sets = ['train', 'test','val']
classes = ['狗']
def convert(size, box):
dw = 1. / size[0]
dh = 1. / size[1]
x = (box[0] + box[1]) / 2.0
y = (box[2] + box[3]) / 2.0
w = box[1] - box[0]
h = box[3] - box[2]
x = x * dw
w = w * dw
y = y * dh
h = h * dh
return (x, y, w, h)
def convert_annotation(image_id):
in_file = open(ROOT_PATH+'data/Annotations/%s.xml' % (image_id),'r',encoding='utf-8')
out_file = open(ROOT_PATH+'data/labels/%s.txt' % (image_id), 'w',encoding='utf-8')
tree = ET.parse(in_file)
root = tree.getroot()
size = root.find('size')
w = int(size.find('width').text)
h = int(size.find('height').text)
for obj in root.iter('object'):
difficult = obj.find('difficult').text
cls = obj.find('name').text
if cls not in classes or int(difficult) == 1:
continue
cls_id = classes.index(cls)
xmlbox = obj.find('bndbox')
b = (float(xmlbox.find('xmin').text), float(xmlbox.find('xmax').text), float(xmlbox.find('ymin').text),
float(xmlbox.find('ymax').text))
bb = convert((w, h), b)
out_file.write(str(cls_id) + " " + " ".join([str(a) for a in bb]) + '\n')
wd = getcwd()
print(wd)
for image_set in sets:
if not os.path.exists('data/labels/'):
os.makedirs('data/labels/')
image_ids = open(ROOT_PATH+'data/ImageSets/%s.txt' % (image_set),'r',encoding='utf-8').read().strip().split()
list_file = open(ROOT_PATH+'data/%s.txt' % (image_set), 'w',encoding='utf-8')
for image_id in image_ids:
list_file.write(ROOT_PATH+'data/JPEGImages/%s.png\n' % (image_id))
print("lgp:"+image_id)
convert_annotation(image_id)
list_file.close()
八、训练筹备
1.修改yolov5l.yaml 的nc值
在根目录/models/
文件夹下找到yolov5l.yaml, n、s、m、l、x几个文件因为其配置的参数不同,所以需要训练的时间依次增加,参数不要动只修改nc值,nc:【 你需要训练的类型数量】
,我训练的只有一个“狗”所以我的修改为nc:1
2.创建自己的训练文件
根目录/data/
文件夹下创建【你自己要训练的】.yaml,我的是LgpDog.yaml,我从coco.yaml复制部分内容并修改为
path: E:/PyWorkSpace/LgpYolov53/data # dataset root dir
train: train.txt # train images (relative to 'path') 118287 images
val: val.txt # train images (relative to 'path') 5000 images
test: test-dev.txt # 20288 of 40670 images, submit to https://competitions.codalab.org/competitions/20794
# Classes
nc: 1 # number of classes
names: ['狗'] # class names
文件中配置的train.txt与另两个txt文件就是convertLabels.py脚本生成的三个训练集文件,里面存储的是图片的路径。
3.修改根目录/train.py
文件
a)修改参数:
修改参数如下图,
--weights
是训练的权重文件,初始训练时是没有训练数据的,所以用官方默认的,这里第1次不用改,之后可以改成自己训练的.pt文件路径。
--cfg
就是创建的
--data
就是自己建立的训练配置,我的是LgpDos.yaml,里面配置了训练的类型,此处,以及图片源路径
--epochs
就是训练迭代次数
--device
暂时未弄清楚,貌似是后续检测脚本detect.py执行用的
--name
保存训练时.pt文件的文件夹名,改不改都行
b)ROOT可能取得C盘路径,所以直接注释掉,这样就是自己的项目路径了,这里需要注意
image.png
然后在虚拟环境中运行train.py,若是第1次执行会下载一些东西,譬如.pt文件,从官网上下载的yolos.pt会在根目录下存在,若根目录下已经存在这个文件那就不会下载,这样省流量,在执行过程中遇到过各种错误:
错1:
ModuleNotFoundError: No module named 'yaml'
Requirement already satisfied: pyyaml in d:\miniconda3\envs\lgpyolo5\lib\sit
没包一般就是环境进错了,关闭窗口使用conda命令重新进入目标虚拟环境并切换到你的工程目录,之后再执行train.py
错2:
RuntimeError: result type Float can't be cast to the desired output type __int64
这是官方文件出问题了,解决方式未打开 根目录/utils/loss.py文件
CTRL+F搜索for i in range(self.nl)
将
anchors, shape = self.anchors[i]
替换为
anchors, shape = self.anchors[i], p[i].shape
CTRL+F搜索indices.append
将
indices.append((b, a, gj.clamp_(0, gain[3] - 1), gi.clamp_(0, gain[2] - 1)))
替换为
indices.append((b, a, gj.clamp_(0, shape[2] - 1), gi.clamp_(0, shape[3] - 1))) # image, anchor, grid
错3:说报一堆文件与labels找不到的错误
貌似是训练的标注数据是通过图片路径查找的,所以将标注的一批.txt文件与图片文件放在一个文件夹里,我这里图片在JPEGImages,所以
九、训练可视化
另起一个cmd窗口,如下指令,激活虚拟环境,敲击命令tensorboard --logdir 【你的Yolo5的项目路径】\runs
,在浏览器输入http://localhost:6006
执行日志:
C:\Users\22090201>conda activate LgpYolo5
(LgpYolo5) C:\Users\22090201>tensorboard --logdir E:\PyWorkSpace\LgpYolov53\runs
TensorFlow installation not found - running with reduced feature set.
Serving TensorBoard on localhost; to expose to the network, use a proxy or pass --bind_all
TensorBoard 2.11.0 at http://localhost:6006/ (Press CTRL+C to quit)
指标含义:
LOSS
loss分为cls_loss, box_loss, obj_loss三部分。
cls_loss用于监督类别分类,计算锚框与对应的标定分类是否正确。
box_loss用于监督检测框的回归,预测框与标定框之间的误差(CIoU)。
obj_loss用于监督grid中是否存在物体,计算网络的置信度。
mAP(IoU@0.75),这是一个对检测能力要求更高的标准。
mAP(IoU@0.5),跟Pascal VOC mAP标准计算方式一致;
mAP(IoU@[0.5:0.05:0.95]),需要计算10个IoU阈值下的mAP,然后计算平均值。这个评估指标比仅考虑通用IoU阈值(0.5)评估指标更能体现出模型的精度。
参考资料:https://blog.csdn.net/u011994454/article/details/119564834
https://pytorch.apachecn.org/#/docs/1.7/19
十、检测目标图片
训练完后会在根目录\runs\train\exp11\weights\ 文件夹下生成best.pt、last.pt两个文件 我们使用best.pt权重文件
在虚拟环境中cd 到Yolo5所在目录,敲击命令
python detect.py --weights 【权重文件路径】 --source 【目标检测文件夹】 --device 【训练显卡或cpu】 --save-txt
示例:
python detect.py --weights runs/train/exp11/weights/best.pt --source ./data/JPEGImages --device cpu --save-txt
敲完之后会自动在runs/detect/exp生成文件夹,里面存放着你目标检测文件,如下图上面有相似度,样本+训练资源+训练时长+训练参数+训练框架=不同的效果,这张图的相似度很低,因为我训练1.5h且使用1个cpu,资源量很低,另一方面我训练的是狗但我检测的是狼,我突然想这两物种连人都很难分辨,AI检测啥样子,从效果来看这块确实是人工智障,拆解成元素来看狼狗分辨主要是情感,尾巴下垂 ,但据说哈士奇尾巴是可下可上的,这个就难搞,这点我还没有想到有啥解,这个问题解决需要对两者进行解构,咱毕竟掌握信息元素不够。
网友评论