YoLo5 AI機器學習識別從入門到捶門

前言

做AI做的事兒锹杈,讓世界充滿AI
原定目標主要是對安卓手機進行UI實時監(jiān)測,思路是利用投屏原理拿到圖像幀迈着,在使用過程中進行無感知UI檢測竭望,我認為目前最大支持僅為60fps,作用能干嘛呢裕菠?作用可多了咬清,譬如訓練單圖標配合無障礙點擊進行智能化搶紅包,刷金幣奴潘,還有可能打王者旧烧,本篇為基礎搭建篇。
之所以放日志是因為工作環(huán)境是內網画髓,很多網站無法正常訪問掘剪,我是在家做一遍再在公司實現,主要用來對比執(zhí)行差異奈虾。

版本

Win10
Python 3.9.12
conda 22.9.0
Yolo5

全程高能注意

所有名稱不得出現中文名夺谁,否則報錯

目錄
  • 安裝miniconda
  • 配置conda國內下載鏡像
  • 安裝Pytorch
  • 創(chuàng)建conda虛擬環(huán)境
  • 從git上下載Yolo5
  • 圖片數據標記軟件
  • 數據標記
  • 數據籌備
  • 訓練籌備
  • 訓練可視化
  • 檢測目標圖片

一、安裝miniconda

它是Anaconda的簡化版肉微,由于Anaconda每次安裝卸載太慢故用簡化版匾鸥,安裝卸載注意:
1.注冊表:\HKEY_CURRENT_USER\Software\Microsoft\Command Processor
下可能會多一個Autorun導致cmd打開就立即運行完,安裝完成后刪掉即可
2.安裝miniconda可能會由于權限等原因導致安裝的內容大量殘缺碉纳,典型的屬于缺失python.exe勿负,Library文件夾,如若發(fā)生建議先在C盤先安裝一遍再安裝到別的盤村象,之后為了節(jié)約C盤空間可以將其卸載
3.配置環(huán)境變量笆环,若在安裝過程中沒有勾選那個自動給配置環(huán)境變量的勾可以手動配置(事實上我勾了它也沒自動配置成功),主要配置如下:

D:\Miniconda3
D:\Miniconda3\Scripts
D:\Miniconda3\Library\bin

二、配置conda國內下載鏡像

由于原生下載鏈接有些包下載慢或下載不下來厚者,我們在這里使用清華鏡像(推薦使用豆瓣鏡像躁劣,清華鏡像有點小垃圾),按照官網教程做法生成.condarc文件巴拉巴拉后库菲,發(fā)現連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創(chuàng)建的虛擬環(huán)境中使用pip方式下載播赁,這樣下載的東西應該與虛擬環(huán)境綁定先舷,s可以執(zhí)行多個版本撵溃。
執(zhí)行日志:(簡書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>

三浮庐、創(chuàng)建conda虛擬環(huán)境

conda的主要作用就是其可以管理不同版本的python,最典型的場景就是我同時有py2與py3項目裂逐,通過conda創(chuàng)建不同的環(huán)境就可以同時執(zhí)行兩個版本的py工程.
創(chuàng)建格式:conda create --name 你起的環(huán)境名 python=你想創(chuàng)建的py版本

conda create --name LgpLoYo5 python=3.9.12

需要聯網下一點包输涕,然后敲命令conda activate 你起的環(huán)境名手動激活剛創(chuàng)建的虛擬環(huán)境展东,若忘了名字可以在磁盤D:\Miniconda3\envs目錄下看到你剛創(chuàng)建的虛擬環(huán)境,激活后就如下所示
注意:
1.激活與關閉命令也在如下所示的注釋
2.若第一次搭建環(huán)境在激活虛擬環(huán)境前需關閉重開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
創(chuàng)建虛擬環(huán)境:conda create --name LgpYoLo5 python=3.9.12 -y
激活虛擬環(huán)境:conda activate LgpYoLo5
設置自動激活虛擬環(huán)境:conda config --set auto_activate_base true
查看所有虛擬環(huán)境:conda env list
退出虛擬環(huán)境:conda deactivate

四蜒滩、從git上下載Yolo5

在剛才激活的命令行環(huán)境中cd到從git下載的Yolo5工程的目錄,我一開始從別人博客復制命令pip install -r requirement.txt報了錯,后發(fā)現名稱錯了,真名為requirements.txt
若未進行文件夾的命令行切換則報錯,所以在pip前一定要切換命令行的目錄到工程根目錄下

#未切目錄執(zhí)行命令報錯
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時發(fā)生了錯誤

# 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

不服輸,又把命令敲了一次,但是又發(fā)生了報錯
本次:

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網絡不穩(wěn)定還是咋地膜蛔,后來查博客發(fā)現了如下命令,它是有效的(不要試圖將此鏈接添加至.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>

五命黔、圖片數據標記軟件

數據標注軟件市面上有很多呜呐,也有一些是自家開發(fā)的,此處介紹兩種悍募,轉換為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
    在當前虛擬環(huán)境中敲擊labelimg會打開標記軟件,目前它僅支持PascalVOC匙隔、YOLO疑苫、CreateML三種標記,它默認是PascalVOC所以我們需要將其切換為YOLO

    image.png

    點擊Open Dir -> 選擇需要標注的文件夾 -> ok

七纷责、數據籌備

  • 理論指引
    訓練集(train set):訓練模型
    驗證集(val set):評估模型捍掺,用來調整模型參數從而選擇最優(yōu)模型
    測試集(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.txttrainval.txt ;這幾個文本文件存儲的待訓練圖片文件名稱栏渺。
    3)根目錄/data/JPEGImages存儲所有訓練圖片
    在根目錄創(chuàng)建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()

在根目錄創(chuàng)建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/文件夾下找到y(tǒng)olov5l.yaml, n融痛、s壶笼、m、l雁刷、x幾個文件因為其配置的參數不同覆劈,所以需要訓練的時間依次增加,參數不要動只修改nc值沛励,nc:【 你需要訓練的類型數量】责语,我訓練的只有一個“狗”所以我的修改為nc:1
2.創(chuàng)建自己的訓練文件
根目錄/data/文件夾下創(chuàng)建【你自己要訓練的】.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就是創(chuàng)建的
--data 就是自己建立的訓練配置,我的是LgpDos.yaml送漠,里面配置了訓練的類型顽照,此處,以及圖片源路徑
--epochs就是訓練迭代次數
--device暫時未弄清楚闽寡,貌似是后續(xù)檢測腳本detect.py執(zhí)行用的
--name保存訓練時.pt文件的文件夾名代兵,改不改都行

image.png

b)ROOT可能取得C盤路徑,所以直接注釋掉爷狈,這樣就是自己的項目路徑了奢人,這里需要注意
image.png

然后在虛擬環(huán)境中運行train.py,若是第1次執(zhí)行會下載一些東西淆院,譬如.pt文件,從官網上下載的yolos.pt會在根目錄下存在句惯,若根目錄下已經存在這個文件那就不會下載土辩,這樣省流量,在執(zhí)行過程中遇到過各種錯誤:
錯1:

ModuleNotFoundError: No module named 'yaml'
Requirement already satisfied: pyyaml in d:\miniconda3\envs\lgpyolo5\lib\sit

沒包一般就是環(huán)境進錯了抢野,關閉窗口使用conda命令重新進入目標虛擬環(huán)境并切換到你的工程目錄拷淘,之后再執(zhí)行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窗口,如下指令结洼,激活虛擬環(huán)境黎做,敲擊命令tensorboard --logdir 【你的Yolo5的項目路徑】\runs松忍,在瀏覽器輸入http://localhost:6006
執(zhí)行日志:

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用于監(jiān)督類別分類,計算錨框與對應的標定分類是否正確鸣峭。
box_loss用于監(jiān)督檢測框的回歸宏所,預測框與標定框之間的誤差(CIoU)。
obj_loss用于監(jiān)督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權重文件
在虛擬環(huán)境中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檢測啥樣子殉摔,從效果來看這塊確實是人工智障,拆解成元素來看狼狗分辨主要是情感记焊,尾巴下垂 逸月,但據說哈士奇尾巴是可下可上的,這個就難搞遍膜,這點我還沒有想到有啥解碗硬,這個問題解決需要對兩者進行解構瓤湘,咱畢竟掌握信息元素不夠。

image.png

參考文章
參考文章2

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
  • 序言:七十年代末恩尾,一起剝皮案震驚了整個濱河市弛说,隨后出現的幾起案子,更是在濱河造成了極大的恐慌特笋,老刑警劉巖剃浇,帶你破解...
    沈念sama閱讀 219,427評論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現場離奇詭異猎物,居然都是意外死亡虎囚,警方通過查閱死者的電腦和手機,發(fā)現死者居然都...
    沈念sama閱讀 93,551評論 3 395
  • 文/潘曉璐 我一進店門蔫磨,熙熙樓的掌柜王于貴愁眉苦臉地迎上來淘讥,“玉大人,你說我怎么就攤上這事堤如∑蚜校” “怎么了?”我有些...
    開封第一講書人閱讀 165,747評論 0 356
  • 文/不壞的土叔 我叫張陵搀罢,是天一觀的道長蝗岖。 經常有香客問我,道長榔至,這世上最難降的妖魔是什么抵赢? 我笑而不...
    開封第一講書人閱讀 58,939評論 1 295
  • 正文 為了忘掉前任,我火速辦了婚禮唧取,結果婚禮上铅鲤,老公的妹妹穿的比我還像新娘。我一直安慰自己枫弟,他們只是感情好邢享,可當我...
    茶點故事閱讀 67,955評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著淡诗,像睡著了一般骇塘。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上韩容,一...
    開封第一講書人閱讀 51,737評論 1 305
  • 那天绪爸,我揣著相機與錄音,去河邊找鬼宙攻。 笑死,一個胖子當著我的面吹牛介褥,可吹牛的內容都是我干的座掘。 我是一名探鬼主播递惋,決...
    沈念sama閱讀 40,448評論 3 420
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼溢陪!你這毒婦竟也來了萍虽?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 39,352評論 0 276
  • 序言:老撾萬榮一對情侶失蹤形真,失蹤者是張志新(化名)和其女友劉穎杉编,沒想到半個月后,有當地人在樹林里發(fā)現了一具尸體咆霜,經...
    沈念sama閱讀 45,834評論 1 317
  • 正文 獨居荒郊野嶺守林人離奇死亡邓馒,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 37,992評論 3 338
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現自己被綠了蛾坯。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片光酣。...
    茶點故事閱讀 40,133評論 1 351
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖脉课,靈堂內的尸體忽然破棺而出救军,到底是詐尸還是另有隱情,我是刑警寧澤倘零,帶...
    沈念sama閱讀 35,815評論 5 346
  • 正文 年R本政府宣布唱遭,位于F島的核電站,受9級特大地震影響呈驶,放射性物質發(fā)生泄漏拷泽。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,477評論 3 331
  • 文/蒙蒙 一俐东、第九天 我趴在偏房一處隱蔽的房頂上張望跌穗。 院中可真熱鬧,春花似錦虏辫、人聲如沸蚌吸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,022評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽羹唠。三九已至,卻和暖如春娄昆,著一層夾襖步出監(jiān)牢的瞬間佩微,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,147評論 1 272
  • 我被黑心中介騙來泰國打工萌焰, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留哺眯,地道東北人。 一個月前我還...
    沈念sama閱讀 48,398評論 3 373
  • 正文 我出身青樓扒俯,卻偏偏與公主長得像奶卓,于是被迫代替她去往敵國和親一疯。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 45,077評論 2 355

推薦閱讀更多精彩內容