YOLO+Web(基于Flask框架,实时处理相机流数据并发布到Web网页端)【完结】

简介:
新开一个需要使用YOLO做两个物体的对接,同时,要将YOLO的画面实时显示在前端。
经过两天在GitHUb中的浸泡,大概明白了前后端的区别,前端使用html语言设计网页的结构。后端(数据端)使用Flask框架做数据的交互。

10.9
看了一下现在git上面的开源项目,一共找到了11个有点少,而且大部分是做静态处理的只有少数是能够实时显示的。先找一个功能齐全能够满足要求的先跑起来看看情况
这是几个项目的情况
10.10
找了一个开源的项目,决定就先从复刻这个项目入手
开源项目地址: Personnel-Flow-Monitoring-System-based-on-YoloV5
这个项目使用本地摄像头来获取图像。

  • List item

TODO:搞清楚如何处理图像流的

首先创建一个python3.10的环境,不能使用3.11,否则torch、torchversion、torchaudio版本都会不兼容,三个依赖的版本安装:

v1.13.1
Conda
OSX
# conda
conda install pytorch==1.13.1 torchvision==0.14.1 torchaudio==0.13.1 -c pytorch
Linux and Windows
# CUDA 11.6
conda install pytorch==1.13.1 torchvision==0.14.1 torchaudio==0.13.1 pytorch-cuda=11.6 -c pytorch -c nvidia
# CUDA 11.7
conda install pytorch==1.13.1 torchvision==0.14.1 torchaudio==0.13.1 pytorch-cuda=11.7 -c pytorch -c nvidia
# CPU Only
conda install pytorch==1.13.1 torchvision==0.14.1 torchaudio==0.13.1 cpuonly -c pytorch
Wheel
OSX
pip install torch==1.13.1 torchvision==0.14.1 torchaudio==0.13.1
Linux and Windows
# ROCM 5.2 (Linux only)
pip3 install torch torchvision torchaudio --extra-index-url
pip install torch==1.13.1+rocm5.2 torchvision==0.14.1+rocm5.2 torchaudio==0.13.1 --extra-index-url https://download.pytorch.org/whl/rocm5.2
# CUDA 11.6
pip install torch==1.13.1+cu116 torchvision==0.14.1+cu116 torchaudio==0.13.1 --extra-index-url https://download.pytorch.org/whl/cu116
# CUDA 11.7
pip install torch==1.13.1+cu117 torchvision==0.14.1+cu117 torchaudio==0.13.1 --extra-index-url https://download.pytorch.org/whl/cu117
# CPU only
pip install torch==1.13.1+cpu torchvision==0.14.1+cpu torchaudio==0.13.1 --extra-index-url https://download.pytorch.org/whl/cpu
v1.13.0
Conda
OSX
# conda
conda install pytorch==1.13.0 torchvision==0.14.0 torchaudio==0.13.0 -c pytorch
Linux and Windows
# CUDA 11.6
conda install pytorch==1.13.0 torchvision==0.14.0 torchaudio==0.13.0 pytorch-cuda=11.6 -c pytorch -c nvidia
# CUDA 11.7
conda install pytorch==1.13.0 torchvision==0.14.0 torchaudio==0.13.0 pytorch-cuda=11.7 -c pytorch -c nvidia
# CPU Only
conda install pytorch==1.13.0 torchvision==0.14.0 torchaudio==0.13.0 cpuonly -c pytorch
Wheel
OSX
pip install torch==1.13.0 torchvision==0.14.0 torchaudio==0.13.0
Linux and Windows
# ROCM 5.2 (Linux only)
pip3 install torch torchvision torchaudio --extra-index-url
pip install torch==1.13.0+rocm5.2 torchvision==0.14.0+rocm5.2 torchaudio==0.13.0 --extra-index-url https://download.pytorch.org/whl/rocm5.2
# CUDA 11.6
pip install torch==1.13.0+cu116 torchvision==0.14.0+cu116 torchaudio==0.13.0 --extra-index-url https://download.pytorch.org/whl/cu116
# CUDA 11.7
pip install torch==1.13.0+cu117 torchvision==0.14.0+cu117 torchaudio==0.13.0 --extra-index-url https://download.pytorch.org/whl/cu117
# CPU only
pip install torch==1.13.0+cpu torchvision==0.14.0+cpu torchaudio==0.13.0 --extra-index-url https://download.pytorch.org/whl/cpu
v1.12.1
Conda
OSX
# conda
conda install pytorch==1.12.1 torchvision==0.13.1 torchaudio==0.12.1 -c pytorch
Linux and Windows
# CUDA 10.2
conda install pytorch==1.12.1 torchvision==0.13.1 torchaudio==0.12.1 cudatoolkit=10.2 -c pytorch
# CUDA 11.3
conda install pytorch==1.12.1 torchvision==0.13.1 torchaudio==0.12.1 cudatoolkit=11.3 -c pytorch
# CUDA 11.6
conda install pytorch==1.12.1 torchvision==0.13.1 torchaudio==0.12.1 cudatoolkit=11.6 -c pytorch -c conda-forge
# CPU Only
conda install pytorch==1.12.1 torchvision==0.13.1 torchaudio==0.12.1 cpuonly -c pytorch
Wheel
OSX
pip install torch==1.12.1 torchvision==0.13.1 torchaudio==0.12.1
Linux and Windows
# ROCM 5.1.1 (Linux only)
pip install torch==1.12.1+rocm5.1.1 torchvision==0.13.1+rocm5.1.1 torchaudio==0.12.1 --extra-index-url  https://download.pytorch.org/whl/rocm5.1.1
# CUDA 11.6
pip install torch==1.12.1+cu116 torchvision==0.13.1+cu116 torchaudio==0.12.1 --extra-index-url https://download.pytorch.org/whl/cu116
# CUDA 11.3
pip install torch==1.12.1+cu113 torchvision==0.13.1+cu113 torchaudio==0.12.1 --extra-index-url https://download.pytorch.org/whl/cu113
# CUDA 10.2
pip install torch==1.12.1+cu102 torchvision==0.13.1+cu102 torchaudio==0.12.1 --extra-index-url https://download.pytorch.org/whl/cu102
# CPU only
pip install torch==1.12.1+cpu torchvision==0.13.1+cpu torchaudio==0.12.1 --extra-index-url https://download.pytorch.org/whl/cpu
v1.12.0
Conda
OSX
# conda
conda install pytorch==1.12.0 torchvision==0.13.0 torchaudio==0.12.0 -c pytorch
Linux and Windows
# CUDA 10.2
conda install pytorch==1.12.0 torchvision==0.13.0 torchaudio==0.12.0 cudatoolkit=10.2 -c pytorch
# CUDA 11.3
conda install pytorch==1.12.0 torchvision==0.13.0 torchaudio==0.12.0 cudatoolkit=11.3 -c pytorch
# CUDA 11.6
conda install pytorch==1.12.0 torchvision==0.13.0 torchaudio==0.12.0 cudatoolkit=11.6 -c pytorch -c conda-forge
# CPU Only
conda install pytorch==1.12.0 torchvision==0.13.0 torchaudio==0.12.0 cpuonly -c pytorch
Wheel
OSX
pip install torch==1.12.0 torchvision==0.13.0 torchaudio==0.12.0
Linux and Windows
# ROCM 5.1.1 (Linux only)
pip install torch==1.12.0+rocm5.1.1 torchvision==0.13.0+rocm5.1.1 torchaudio==0.12.0 --extra-index-url  https://download.pytorch.org/whl/rocm5.1.1
# CUDA 11.6
pip install torch==1.12.0+cu116 torchvision==0.13.0+cu116 torchaudio==0.12.0 --extra-index-url https://download.pytorch.org/whl/cu116
# CUDA 11.3
pip install torch==1.12.0+cu113 torchvision==0.13.0+cu113 torchaudio==0.12.0 --extra-index-url https://download.pytorch.org/whl/cu113
# CUDA 10.2
pip install torch==1.12.0+cu102 torchvision==0.13.0+cu102 torchaudio==0.12.0 --extra-index-url https://download.pytorch.org/whl/cu102
# CPU only
pip install torch==1.12.0+cpu torchvision==0.13.0+cpu torchaudio==0.12.0 --extra-index-url https://download.pytorch.org/whl/cpu
v1.11.0
Conda
OSX
# conda
conda install pytorch==1.11.0 torchvision==0.12.0 torchaudio==0.11.0 -c pytorch
Linux and Windows
# CUDA 10.2
conda install pytorch==1.11.0 torchvision==0.12.0 torchaudio==0.11.0 cudatoolkit=10.2 -c pytorch

# CUDA 11.3
conda install pytorch==1.11.0 torchvision==0.12.0 torchaudio==0.11.0 cudatoolkit=11.3 -c pytorch

# CPU Only
conda install pytorch==1.11.0 torchvision==0.12.0 torchaudio==0.11.0 cpuonly -c pytorch
Wheel
OSX
pip install torch==1.11.0 torchvision==0.12.0 torchaudio==0.11.0
Linux and Windows
# ROCM 4.5.2 (Linux only)
pip install torch==1.11.0+rocm4.5.2 torchvision==0.12.0+rocm4.5.2 torchaudio==0.11.0 --extra-index-url  https://download.pytorch.org/whl/rocm4.5.2

# CUDA 11.3
pip install torch==1.11.0+cu113 torchvision==0.12.0+cu113 torchaudio==0.11.0 --extra-index-url https://download.pytorch.org/whl/cu113

# CUDA 10.2
pip install torch==1.11.0+cu102 torchvision==0.12.0+cu102 torchaudio==0.11.0 --extra-index-url https://download.pytorch.org/whl/cu102

# CPU only
pip install torch==1.11.0+cpu torchvision==0.12.0+cpu torchaudio==0.11.0 --extra-index-url https://download.pytorch.org/whl/cpu
v1.10.1
Conda
OSX
# conda
conda install pytorch==1.10.1 torchvision==0.11.2 torchaudio==0.10.1 -c pytorch
Linux and Windows
# CUDA 10.2
conda install pytorch==1.10.1 torchvision==0.11.2 torchaudio==0.10.1 cudatoolkit=10.2 -c pytorch

# CUDA 11.3
conda install pytorch==1.10.1 torchvision==0.11.2 torchaudio==0.10.1 cudatoolkit=11.3 -c pytorch -c conda-forge

# CPU Only
conda install pytorch==1.10.1 torchvision==0.11.2 torchaudio==0.10.1 cpuonly -c pytorch
Wheel
OSX
pip install torch==1.10.1 torchvision==0.11.2 torchaudio==0.10.1
Linux and Windows
# ROCM 4.2 (Linux only)
pip install torch==1.10.1+rocm4.2 torchvision==0.11.2+rocm4.2 torchaudio==0.10.1 -f https://download.pytorch.org/whl/rocm4.2/torch_stable.html

# ROCM 4.1 (Linux only)
pip install torch==1.10.1+rocm4.1 torchvision==0.11.2+rocm4.1 torchaudio==0.10.1 -f https://download.pytorch.org/whl/torch_stable.html

# ROCM 4.0.1 (Linux only)
pip install torch==1.10.1+rocm4.0.1 torchvision==0.10.2+rocm4.0.1 torchaudio==0.10.1 -f https://download.pytorch.org/whl/torch_stable.html

# CUDA 11.1
pip install torch==1.10.1+cu111 torchvision==0.11.2+cu111 torchaudio==0.10.1 -f https://download.pytorch.org/whl/cu111/torch_stable.html

# CUDA 10.2
pip install torch==1.10.1+cu102 torchvision==0.11.2+cu102 torchaudio==0.10.1 -f https://download.pytorch.org/whl/cu102/torch_stable.html

# CPU only
pip install torch==1.10.1+cpu torchvision==0.11.2+cpu torchaudio==0.10.1 -f https://download.pytorch.org/whl/cpu/torch_stable.html
v1.10.0
Conda
OSX
# conda
conda install pytorch==1.10.0 torchvision==0.11.0 torchaudio==0.10.0 -c pytorch
Linux and Windows
# CUDA 10.2
conda install pytorch==1.10.0 torchvision==0.11.0 torchaudio==0.10.0 cudatoolkit=10.2 -c pytorch

# CUDA 11.3
conda install pytorch==1.10.0 torchvision==0.11.0 torchaudio==0.10.0 cudatoolkit=11.3 -c pytorch -c conda-forge

# CPU Only
conda install pytorch==1.10.0 torchvision==0.11.0 torchaudio==0.10.0 cpuonly -c pytorch
Wheel
OSX
pip install torch==1.10.0 torchvision==0.11.0 torchaudio==0.10.0
Linux and Windows
# ROCM 4.2 (Linux only)
pip install torch==1.10.0+rocm4.2 torchvision==0.11.0+rocm4.2 torchaudio==0.10.0 -f https://download.pytorch.org/whl/torch_stable.html

# ROCM 4.1 (Linux only)
pip install torch==1.10.0+rocm4.1 torchvision==0.11.0+rocm4.1 torchaudio==0.10.0 -f https://download.pytorch.org/whl/torch_stable.html

# ROCM 4.0.1 (Linux only)
pip install torch==1.10.0+rocm4.0.1 torchvision==0.10.1+rocm4.0.1 torchaudio==0.10.0 -f https://download.pytorch.org/whl/torch_stable.html

# CUDA 11.1
pip install torch==1.10.0+cu111 torchvision==0.11.0+cu111 torchaudio==0.10.0 -f https://download.pytorch.org/whl/torch_stable.html

# CUDA 10.2
pip install torch==1.10.0+cu102 torchvision==0.11.0+cu102 torchaudio==0.10.0 -f https://download.pytorch.org/whl/torch_stable.html

# CPU only
pip install torch==1.10.0+cpu torchvision==0.11.0+cpu torchaudio==0.10.0 -f https://download.pytorch.org/whl/torch_stable.html
v1.9.1
Conda
OSX
# conda
conda install pytorch==1.9.1 torchvision==0.10.1 torchaudio==0.9.1 -c pytorch
Linux and Windows
# CUDA 10.2
conda install pytorch==1.9.1 torchvision==0.10.1 torchaudio==0.9.1 cudatoolkit=10.2 -c pytorch

# CUDA 11.3
conda install pytorch==1.9.1 torchvision==0.10.1 torchaudio==0.9.1 cudatoolkit=11.3 -c pytorch -c conda-forge

# CPU Only
conda install pytorch==1.9.0 torchvision==0.10.1 torchaudio==0.9.1 cpuonly -c pytorch
Wheel
OSX
pip install torch==1.9.1 torchvision==0.10.1 torchaudio==0.9.1
Linux and Windows
# ROCM 4.2 (Linux only)
pip install torch==1.9.0+rocm4.2 torchvision==0.10.1+rocm4.2 torchaudio==0.9.1 -f https://download.pytorch.org/whl/torch_stable.html

# ROCM 4.1 (Linux only)
pip install torch==1.9.0+rocm4.1 torchvision==0.10.1+rocm4.1 torchaudio==0.9.1 -f https://download.pytorch.org/whl/torch_stable.html

# ROCM 4.0.1 (Linux only)
pip install torch==1.9.1+rocm4.0.1 torchvision==0.10.1+rocm4.0.1 torchaudio==0.9.1 -f https://download.pytorch.org/whl/torch_stable.html

# CUDA 11.1
pip install torch==1.9.1+cu111 torchvision==0.10.1+cu111 torchaudio==0.9.1 -f https://download.pytorch.org/whl/torch_stable.html

# CUDA 10.2
pip install torch==1.9.1+cu102 torchvision==0.10.1+cu102 torchaudio==0.9.0 -f https://download.pytorch.org/whl/torch_stable.html

# CPU only
pip install torch==1.9.1+cpu torchvision==0.10.1+cpu torchaudio==0.9.1 -f https://download.pytorch.org/whl/torch_stable.html
v1.9.0
Conda
OSX
# conda
conda install pytorch==1.9.0 torchvision==0.10.0 torchaudio==0.9.0 -c pytorch
Linux and Windows
# CUDA 10.2
conda install pytorch==1.9.0 torchvision==0.10.0 torchaudio==0.9.0 cudatoolkit=10.2 -c pytorch

# CUDA 11.3
conda install pytorch==1.9.0 torchvision==0.10.0 torchaudio==0.9.0 cudatoolkit=11.3 -c pytorch -c conda-forge

# CPU Only
conda install pytorch==1.9.0 torchvision==0.10.0 torchaudio==0.9.0 cpuonly -c pytorch
Wheel
OSX
pip install torch==1.9.0 torchvision==0.10.0 torchaudio==0.9.0
Linux and Windows
# ROCM 4.2 (Linux only)
pip install torch==1.9.0+rocm4.2 torchvision==0.10.0+rocm4.2 torchaudio==0.9.0 -f https://download.pytorch.org/whl/torch_stable.html

# ROCM 4.1 (Linux only)
pip install torch==1.9.0+rocm4.1 torchvision==0.10.0+rocm4.1 torchaudio==0.9.0 -f https://download.pytorch.org/whl/torch_stable.html

# ROCM 4.0.1 (Linux only)
pip install torch==1.9.0+rocm4.0.1 torchvision==0.10.0+rocm4.0.1 torchaudio==0.9.0 -f https://download.pytorch.org/whl/torch_stable.html

# CUDA 11.1
pip install torch==1.9.0+cu111 torchvision==0.10.0+cu111 torchaudio==0.9.0 -f https://download.pytorch.org/whl/torch_stable.html

# CUDA 10.2
pip install torch==1.9.0+cu102 torchvision==0.10.0+cu102 torchaudio==0.9.0 -f https://download.pytorch.org/whl/torch_stable.html

# CPU only
pip install torch==1.9.0+cpu torchvision==0.10.0+cpu torchaudio==0.9.0 -f https://download.pytorch.org/whl/torch_stable.html
v1.8.2 with LTS support
Conda
OSX
macOS is currently not supported for LTS.

Linux and Windows
# CUDA 10.2
# NOTE: PyTorch LTS version 1.8.2 is only supported for Python <= 3.8.
conda install pytorch torchvision torchaudio cudatoolkit=10.2 -c pytorch-lts

# CUDA 11.1 (Linux)
# NOTE: 'nvidia' channel is required for cudatoolkit 11.1 <br> <b>NOTE:</b> Pytorch LTS version 1.8.2 is only supported for Python <= 3.8.
conda install pytorch torchvision torchaudio cudatoolkit=11.1 -c pytorch-lts -c nvidia

# CUDA 11.1 (Windows)
# 'conda-forge' channel is required for cudatoolkit 11.1 <br> <b>NOTE:</b> Pytorch LTS version 1.8.2 is only supported for Python <= 3.8.
conda install pytorch torchvision torchaudio cudatoolkit=11.1 -c pytorch-lts -c conda-forge

# CPU Only
# Pytorch LTS version 1.8.2 is only supported for Python <= 3.8.
conda install pytorch torchvision torchaudio cpuonly -c pytorch-lts

# ROCM5.x

Not supported in LTS.
Wheel
OSX
macOS is currently not supported in LTS.

Linux and Windows
# CUDA 10.2
pip3 install torch==1.8.2 torchvision==0.9.2 torchaudio==0.8.2 --extra-index-url https://download.pytorch.org/whl/lts/1.8/cu102

# CUDA 11.1
pip3 install torch==1.8.2 torchvision==0.9.2 torchaudio==0.8.2 --extra-index-url https://download.pytorch.org/whl/lts/1.8/cu111

# CPU Only
pip3 install torch==1.8.2 torchvision==0.9.2 torchaudio==0.8.2 --extra-index-url https://download.pytorch.org/whl/lts/1.8/cpu

# ROCM5.x

Not supported in LTS.
v1.8.1
Conda
OSX
# conda
conda install pytorch==1.8.1 torchvision==0.9.1 torchaudio==0.8.1 -c pytorch
Linux and Windows
# CUDA 10.2
conda install pytorch==1.8.1 torchvision==0.9.1 torchaudio==0.8.1 cudatoolkit=10.2 -c pytorch

# CUDA 11.3
conda install pytorch==1.8.1 torchvision==0.9.1 torchaudio==0.8.1 cudatoolkit=11.3 -c pytorch -c conda-forge

# CPU Only
conda install pytorch==1.8.1 torchvision==0.9.1 torchaudio==0.8.1 cpuonly -c pytorch
Wheel
OSX
pip install torch==1.8.1 torchvision==0.9.1 torchaudio==0.8.1
Linux and Windows
# ROCM 4.0.1 (Linux only)
pip install torch==1.8.1+rocm4.0.1 torchvision==0.9.1+rocm4.0.1 torchaudio==0.8.1 -f https://download.pytorch.org/whl/torch_stable.html

# ROCM 3.10 (Linux only)
pip install torch==1.8.1+rocm3.10 torchvision==0.9.1+rocm3.10 torchaudio==0.8.1 -f https://download.pytorch.org/whl/torch_stable.html

# CUDA 11.1
pip install torch==1.8.1+cu111 torchvision==0.9.1+cu111 torchaudio==0.8.1 -f https://download.pytorch.org/whl/torch_stable.html

# CUDA 10.2
pip install torch==1.8.1+cu102 torchvision==0.9.1+cu102 torchaudio==0.8.1 -f https://download.pytorch.org/whl/torch_stable.html

# CUDA 10.1
pip install torch==1.8.1+cu101 torchvision==0.9.1+cu101 torchaudio==0.8.1 -f https://download.pytorch.org/whl/torch_stable.html

# CPU only
pip install torch==1.8.1+cpu torchvision==0.9.1+cpu torchaudio==0.8.1 -f https://download.pytorch.org/whl/torch_stable.html
v1.8.0
Conda
OSX
# conda
conda install pytorch==1.8.0 torchvision==0.9.0 torchaudio==0.8.0 -c pytorch
Linux and Windows
# CUDA 10.2
conda install pytorch==1.8.0 torchvision==0.9.0 torchaudio==0.8.0 cudatoolkit=10.2 -c pytorch

# CUDA 11.1
conda install pytorch==1.8.0 torchvision==0.9.0 torchaudio==0.8.0 cudatoolkit=11.1 -c pytorch -c conda-forge

# CPU Only
conda install pytorch==1.8.0 torchvision==0.9.0 torchaudio==0.8.0 cpuonly -c pytorch
Wheel
OSX
pip install torch==1.8.0 torchvision==0.9.0 torchaudio==0.8.0
Linux and Windows
# RocM 4.0.1 (Linux only)
pip install torch -f https://download.pytorch.org/whl/rocm4.0.1/torch_stable.html
pip install ninja
pip install 'git+https://github.com/pytorch/vision.git@v0.9.0'

# CUDA 11.1
pip install torch==1.8.0+cu111 torchvision==0.9.0+cu111 torchaudio==0.8.0 -f https://download.pytorch.org/whl/torch_stable.html

# CUDA 10.2
pip install torch==1.8.0 torchvision==0.9.0 torchaudio==0.8.0

# CPU only
pip install torch==1.8.0+cpu torchvision==0.9.0+cpu torchaudio==0.8.0 -f https://download.pytorch.org/whl/torch_stable.html
v1.7.1
Conda
OSX
# conda
conda install pytorch==1.7.1 torchvision==0.8.2 torchaudio==0.7.2 -c pytorch
Linux and Windows
# CUDA 9.2
conda install pytorch==1.7.1 torchvision==0.8.2 torchaudio==0.7.2 cudatoolkit=9.2 -c pytorch

# CUDA 10.1
conda install pytorch==1.7.1 torchvision==0.8.2 torchaudio==0.7.2 cudatoolkit=10.1 -c pytorch

# CUDA 10.2
conda install pytorch==1.7.1 torchvision==0.8.2 torchaudio==0.7.2 cudatoolkit=10.2 -c pytorch

# CUDA 11.0
conda install pytorch==1.7.1 torchvision==0.8.2 torchaudio==0.7.2 cudatoolkit=11.0 -c pytorch

# CPU Only
conda install pytorch==1.7.1 torchvision==0.8.2 torchaudio==0.7.2 cpuonly -c pytorch
Wheel
OSX
pip install torch==1.7.1 torchvision==0.8.2 torchaudio==0.7.2
Linux and Windows
# CUDA 11.0
pip install torch==1.7.1+cu110 torchvision==0.8.2+cu110 torchaudio==0.7.2 -f https://download.pytorch.org/whl/torch_stable.html

# CUDA 10.2
pip install torch==1.7.1 torchvision==0.8.2 torchaudio==0.7.2

# CUDA 10.1
pip install torch==1.7.1+cu101 torchvision==0.8.2+cu101 torchaudio==0.7.2 -f https://download.pytorch.org/whl/torch_stable.html

# CUDA 9.2
pip install torch==1.7.1+cu92 torchvision==0.8.2+cu92 torchaudio==0.7.2 -f https://download.pytorch.org/whl/torch_stable.html

# CPU only
pip install torch==1.7.1+cpu torchvision==0.8.2+cpu torchaudio==0.7.2 -f https://download.pytorch.org/whl/torch_stable.html
v1.7.0
Conda
OSX
# conda
conda install pytorch==1.7.0 torchvision==0.8.0 torchaudio==0.7.0 -c pytorch
Linux and Windows
# CUDA 9.2
conda install pytorch==1.7.0 torchvision==0.8.0 torchaudio==0.7.0 cudatoolkit=9.2 -c pytorch

# CUDA 10.1
conda install pytorch==1.7.0 torchvision==0.8.0 torchaudio==0.7.0 cudatoolkit=10.1 -c pytorch

# CUDA 10.2
conda install pytorch==1.7.0 torchvision==0.8.0 torchaudio==0.7.0 cudatoolkit=10.2 -c pytorch

# CUDA 11.0
conda install pytorch==1.7.0 torchvision==0.8.0 torchaudio==0.7.0 cudatoolkit=11.0 -c pytorch

# CPU Only
conda install pytorch==1.7.0 torchvision==0.8.0 torchaudio==0.7.0 cpuonly -c pytorch
Wheel
OSX
pip install torch==1.7.0 torchvision==0.8.0 torchaudio==0.7.0
Linux and Windows
# CUDA 11.0
pip install torch==1.7.0+cu110 torchvision==0.8.0+cu110 torchaudio==0.7.0 -f https://download.pytorch.org/whl/torch_stable.html

# CUDA 10.2
pip install torch==1.7.0 torchvision==0.8.0 torchaudio==0.7.0

# CUDA 10.1
pip install torch==1.7.0+cu101 torchvision==0.8.0+cu101 torchaudio==0.7.0 -f https://download.pytorch.org/whl/torch_stable.html

# CUDA 9.2
pip install torch==1.7.0+cu92 torchvision==0.8.0+cu92 torchaudio==0.7.0 -f https://download.pytorch.org/whl/torch_stable.html

# CPU only
pip install torch==1.7.0+cpu torchvision==0.8.0+cpu torchaudio==0.7.0 -f https://download.pytorch.org/whl/torch_stable.html
v1.6.0
Conda
OSX
# conda
conda install pytorch==1.6.0 torchvision==0.7.0 -c pytorch
Linux and Windows
# CUDA 9.2
conda install pytorch==1.6.0 torchvision==0.7.0 cudatoolkit=9.2 -c pytorch

# CUDA 10.1
conda install pytorch==1.6.0 torchvision==0.7.0 cudatoolkit=10.1 -c pytorch

# CUDA 10.2
conda install pytorch==1.6.0 torchvision==0.7.0 cudatoolkit=10.2 -c pytorch

# CPU Only
conda install pytorch==1.6.0 torchvision==0.7.0 cpuonly -c pytorch
Wheel
OSX
pip install torch==1.6.0 torchvision==0.7.0
Linux and Windows
# CUDA 10.2
pip install torch==1.6.0 torchvision==0.7.0

# CUDA 10.1
pip install torch==1.6.0+cu101 torchvision==0.7.0+cu101 -f https://download.pytorch.org/whl/torch_stable.html

# CUDA 9.2
pip install torch==1.6.0+cu92 torchvision==0.7.0+cu92 -f https://download.pytorch.org/whl/torch_stable.html

# CPU only
pip install torch==1.6.0+cpu torchvision==0.7.0+cpu -f https://download.pytorch.org/whl/torch_stable.html
v1.5.1
Conda
OSX
# conda
conda install pytorch==1.5.1 torchvision==0.6.1 -c pytorch
Linux and Windows
# CUDA 9.2
conda install pytorch==1.5.1 torchvision==0.6.1 cudatoolkit=9.2 -c pytorch

# CUDA 10.1
conda install pytorch==1.5.1 torchvision==0.6.1 cudatoolkit=10.1 -c pytorch

# CUDA 10.2
conda install pytorch==1.5.1 torchvision==0.6.1 cudatoolkit=10.2 -c pytorch

# CPU Only
conda install pytorch==1.5.1 torchvision==0.6.1 cpuonly -c pytorch
Wheel
OSX
pip install torch==1.5.1 torchvision==0.6.1
Linux and Windows
# CUDA 10.2
pip install torch==1.5.1 torchvision==0.6.1

# CUDA 10.1
pip install torch==1.5.1+cu101 torchvision==0.6.1+cu101 -f https://download.pytorch.org/whl/torch_stable.html

# CUDA 9.2
pip install torch==1.5.1+cu92 torchvision==0.6.1+cu92 -f https://download.pytorch.org/whl/torch_stable.html

# CPU only
pip install torch==1.5.1+cpu torchvision==0.6.1+cpu -f https://download.pytorch.org/whl/torch_stable.html
v1.5.0
Conda
OSX
# conda
conda install pytorch==1.5.0 torchvision==0.6.0 -c pytorch
Linux and Windows
# CUDA 9.2
conda install pytorch==1.5.0 torchvision==0.6.0 cudatoolkit=9.2 -c pytorch

# CUDA 10.1
conda install pytorch==1.5.0 torchvision==0.6.0 cudatoolkit=10.1 -c pytorch

# CUDA 10.2
conda install pytorch==1.5.0 torchvision==0.6.0 cudatoolkit=10.2 -c pytorch

# CPU Only
conda install pytorch==1.5.0 torchvision==0.6.0 cpuonly -c pytorch
Wheel
OSX
pip install torch==1.5.0 torchvision==0.6.0
Linux and Windows
# CUDA 10.2
pip install torch==1.5.0 torchvision==0.6.0

# CUDA 10.1
pip install torch==1.5.0+cu101 torchvision==0.6.0+cu101 -f https://download.pytorch.org/whl/torch_stable.html

# CUDA 9.2
pip install torch==1.5.0+cu92 torchvision==0.6.0+cu92 -f https://download.pytorch.org/whl/torch_stable.html

# CPU only
pip install torch==1.5.0+cpu torchvision==0.6.0+cpu -f https://download.pytorch.org/whl/torch_stable.html
v1.4.0
Conda
OSX
# conda
conda install pytorch==1.4.0 torchvision==0.5.0 -c pytorch
Linux and Windows
# CUDA 9.2
conda install pytorch==1.4.0 torchvision==0.5.0 cudatoolkit=9.2 -c pytorch

# CUDA 10.1
conda install pytorch==1.4.0 torchvision==0.5.0 cudatoolkit=10.1 -c pytorch

# CPU Only
conda install pytorch==1.4.0 torchvision==0.5.0 cpuonly -c pytorch
Wheel
OSX
pip install torch==1.4.0 torchvision==0.5.0
Linux and Windows
# CUDA 10.1
pip install torch==1.4.0 torchvision==0.5.0

# CUDA 9.2
pip install torch==1.4.0+cu92 torchvision==0.5.0+cu92 -f https://download.pytorch.org/whl/torch_stable.html

# CPU only
pip install torch==1.4.0+cpu torchvision==0.5.0+cpu -f https://download.pytorch.org/whl/torch_stable.html
v1.2.0
Conda
OSX
# conda
conda install pytorch==1.2.0 torchvision==0.4.0 -c pytorch
Linux and Windows
# CUDA 9.2
conda install pytorch==1.2.0 torchvision==0.4.0 cudatoolkit=9.2 -c pytorch

# CUDA 10.0
conda install pytorch==1.2.0 torchvision==0.4.0 cudatoolkit=10.0 -c pytorch

# CPU Only
conda install pytorch==1.2.0 torchvision==0.4.0 cpuonly -c pytorch
Wheel
OSX
pip install torch==1.2.0 torchvision==0.4.0
Linux and Windows
# CUDA 10.0
pip install torch==1.2.0 torchvision==0.4.0

# CUDA 9.2
pip install torch==1.2.0+cu92 torchvision==0.4.0+cu92 -f https://download.pytorch.org/whl/torch_stable.html

# CPU only
pip install torch==1.2.0+cpu torchvision==0.4.0+cpu -f https://download.pytorch.org/whl/torch_stable.html
v1.1.0
Conda
OSX
# conda
conda install pytorch==1.1.0 torchvision==0.3.0 -c pytorch
Linux and Windows
# CUDA 9.0
conda install pytorch==1.1.0 torchvision==0.3.0 cudatoolkit=9.0 -c pytorch

# CUDA 10.0
conda install pytorch==1.1.0 torchvision==0.3.0 cudatoolkit=10.0 -c pytorch

# CPU Only
conda install pytorch-cpu==1.1.0 torchvision-cpu==0.3.0 cpuonly -c pytorch
Wheel
OSX
pip install torch==1.1.0 torchvision==0.3.0
Linux and Windows
# CUDA 10.0
Download and install wheel from https://download.pytorch.org/whl/cu100/torch_stable.html

# CUDA 9.0
Download and install wheel from https://download.pytorch.org/whl/cu90/torch_stable.html

# CPU only
Download and install wheel from https://download.pytorch.org/whl/cpu/torch_stable.html
v1.0.1
Conda
OSX
# conda
conda install pytorch==1.0.1 torchvision==0.2.2 -c pytorch
Linux and Windows
# CUDA 9.0
conda install pytorch==1.0.1 torchvision==0.2.2 cudatoolkit=9.0 -c pytorch

# CUDA 10.0
conda install pytorch==1.0.1 torchvision==0.2.2 cudatoolkit=10.0 -c pytorch

# CPU Only
conda install pytorch-cpu==1.0.1 torchvision-cpu==0.2.2 cpuonly -c pytorch
Wheel
OSX
pip install torch==1.0.1 torchvision==0.2.2
Linux and Windows
# CUDA 10.0
Download and install wheel from https://download.pytorch.org/whl/cu100/torch_stable.html

# CUDA 9.0
Download and install wheel from https://download.pytorch.org/whl/cu90/torch_stable.html

# CPU only
Download and install wheel from https://download.pytorch.org/whl/cpu/torch_stable.html
v1.0.0
Conda
OSX
# conda
conda install pytorch==1.0.0 torchvision==0.2.1 -c pytorch
Linux and Windows
# CUDA 10.0
conda install pytorch==1.0.0 torchvision==0.2.1 cuda100 -c pytorch

# CUDA 9.0
conda install pytorch==1.0.0 torchvision==0.2.1 cuda90 -c pytorch

# CUDA 8.0
conda install pytorch==1.0.0 torchvision==0.2.1 cuda80 -c pytorch

# CPU Only
conda install pytorch-cpu==1.0.0 torchvision-cpu==0.2.1 cpuonly -c pytorch
Wheel
OSX
pip install torch==1.0.0 torchvision==0.2.1
Linux and Windows
# CUDA 10.0
Download and install wheel from https://download.pytorch.org/whl/cu100/torch_stable.html

# CUDA 9.0
Download and install wheel from https://download.pytorch.org/whl/cu90/torch_stable.html

# CUDA 8.0
Download and install wheel from https://download.pytorch.org/whl/cu80/torch_stable.html

# CPU only
Download and install wheel from https://download.pytorch.org/whl/cpu/torch_stable.html
COMMANDS FOR VERSIONS < 1.0.0
Via conda
This should be used for most previous macOS version installs.

To install a previous version of PyTorch via Anaconda or Miniconda, replace “0.4.1in the following commands with the desired version (i.e.,0.2.0).

Installing with CUDA 9

conda install pytorch=0.4.1 cuda90 -c pytorch

or

conda install pytorch=0.4.1 cuda92 -c pytorch

Installing with CUDA 8

conda install pytorch=0.4.1 cuda80 -c pytorch

Installing with CUDA 7.5

conda install pytorch=0.4.1 cuda75 -c pytorch

Installing without CUDA

conda install pytorch=0.4.1 -c pytorch

From source
It is possible to checkout an older version of PyTorch and build it. You can list tags in PyTorch git repository with git tag and checkout a particular one (replace ‘0.1.9with the desired version) with

git checkout v0.1.9

Follow the install from source instructions in the README.md of the PyTorch checkout.

Via pip
Download the whl file with the desired version from the following html pages:

https://download.pytorch.org/whl/cpu/torch_stable.html # CPU-only build
https://download.pytorch.org/whl/cu80/torch_stable.html # CUDA 8.0 build
https://download.pytorch.org/whl/cu90/torch_stable.html # CUDA 9.0 build
https://download.pytorch.org/whl/cu92/torch_stable.html # CUDA 9.2 build
https://download.pytorch.org/whl/cu100/torch_stable.html # CUDA 10.0 build
Then, install the file with pip install [downloaded file]
Note: most pytorch versions are available only for specific CUDA versions. For example pytorch=1.0.1 is not available for CUDA 9.2
(Old) PyTorch Linux binaries compiled with CUDA 7.5
These predate the html page above and have to be manually installed by downloading the wheel file and pip install downloaded_file
Mac and misc. binaries
For recent macOS binaries, use conda:
e.g.,
conda install pytorch=0.4.1 cuda90 -c pytorch conda install pytorch=0.4.1 cuda92 -c pytorch conda install pytorch=0.4.1 cuda80 -c pytorch conda install pytorch=0.4.1 -c pytorch # No CUDA

报错:

问题描述
当使用from flask_wtf import FlaskForm 时

会出现ImportError: cannot import name 'url_encode' from 'werkzeug'的问题

问题产生原因
werkzeug 版本过高,导致问题出现

安装werkzeug的低版本即可解决问题

pip install werkzeug==0.16.0

之后又获得了一个意外的argument
在这里插入图片描述
安装的好麻烦,研究研究怎么生成requistment。exe文件

直接让chatGPT给我写了一份

absl-py==1.3.0
asttokens==2.1.0
backcall==0.2.0
cachetools==5.2.0
certifi==2022.9.24
charset-normalizer==2.1.1
click==8.1.3
colorama==0.4.6
contourpy==1.0.6
cycler==0.11.0
decorator==5.1.1
easydict==1.10
executing==1.2.0
Flask==2.2.2
Flask-Cors==3.0.10
Flask-SQLAlchemy==3.0.3
fonttools==4.38.0
google-auth==2.14.1
google-auth-oauthlib==0.4.6
greenlet==2.0.2
grpcio==1.50.0
idna==3.4
ipython==8.6.0
itsdangerous==2.1.2
jedi==0.18.1
Jinja2==3.1.2
kiwisolver==1.4.4
libffi==3.4.2
Markdown==3.4.1
MarkupSafe==2.1.1
matplotlib==3.6.2
matplotlib-inline==0.1.6
numpy==1.23.4
oauthlib==3.2.2
opencv-python==4.5.4.60
packaging==21.3
pandas==1.5.1
parso==0.8.3
pickleshare==0.7.5
Pillow==9.3.0
protobuf==3.20.1
psutil==5.9.4
pure-eval==0.2.2
pyasn1==0.4.8
pyasn1-modules==0.2.8
Pygments==2.13.0
PyMySQL==1.0.2
pyparsing==3.0.9
python-dateutil==2.8.2
pytz==2022.6
PyYAML==6.0
requests==2.28.1
requests-oauthlib==1.3.1
rsa==4.9
scipy==1.9.3
seaborn==0.12.1
SQLAlchemy==2.0.5.post1
tensorboard==2.11.0
tensorboard-data-server==0.6.1
tensorboard-plugin-wit==1.8.1
thop-0.1.1==2209072238
tqdm==4.64.1
traitlets==5.5.0
typing_extensions==4.4.0
tzdata==2022f
urllib3==1.26.12
wcwidth==0.2.5
Werkzeug==2.2.2
wheel==0.37.1
wincertstore==0.2
xz==5.2.6
zlib==1.2.13

然后直接在Anaconda prompt 中使用

pip install -r requirement.txt

下载相关依赖,其中的libffi在pip中无法下载,需要到tsinghua镜像去下载,找到对应的版本以后发现有.conda 和.tar.bz 两种格式,

  • 直接解压到根目录,看看后续会不会出问题

tho依赖安装也有问题:
(requirement.txt文件里面也改了)

pip install thop==0.1.1.post2209072238

经过一番下载,现在启动后端的效果是这样的
功能很少
前端需要用vue来启动,同时YOLO模型也没有调起来,具体怎么调出来的还需要进一步研究,先看看运行前端的效果

链接: VUE学习

10.18
目前把vue的使用方法和flask的使用方法了解了,现在着手将yolo实例化,在其他文件中调用。
直接调用detec文件不现实,每次识别一帧图片启动一次模型太浪费时间,所以我们就需要先启动yolo模型,然后将输出的图片加入到一个队列中,之后再启动一个进程,在这个线程中完成前端的响应。
第二个思路就是,使用一个进程,在一个线程中不启动detect文件了,每次相机读上来的帧数据直接发给实例化的yolo模型做检测,这样一个完成识别。

由于对进程操作不熟悉,首先使用第二个思路。先研究如何将yolov5s实例化,

好好好总算搞明白怎么加载自定义的yolo模型了,但如果是自己训练的权重文件能直接用吗?

import torch

# 从本地加载自定义的YOLOv5模型
model_path = "D:\IDE\Anaconda3\Lib\YOLOv5\AUO\yolov5-master\\"  # yolov5根目录
weight_path = model_path + "best.pt"
model = torch.hub.load(model_path, "custom", weight_path, source="local")
print('测试启动是不是慢')
imgs = [model_path + '/data/myimages/false2285.bmp']
results = model(imgs)
results.print()
results.show()  # 这两句用于看一下模型检测结果

成功加载并使用了自己的模型,注意,common.py文件中要添加自己的网络模块。
在这里插入图片描述

现在出了新的问题,我们的图像转换成bytes格式了,但是网页端显示不出来
好像是生成器这部分一旦启动,yield关键字前面的部分就不执行了,接下来测试一下。

依然执行,说明不是检测关键字直接跳步执行。现在还有个异常情况是,imshow也不显示了,
打断点查看一下从哪步开始不能显示了。
从一开始就不能imshow。
找了半天,总算找到imshow不出来的原因,因为窗口跟新太快,所有无法显示

        # cv2.waitKey(2000)  # 等待2秒

加一个等待就好了。

经过一番折腾,终于实现了。

在这里插入图片描述

这里附上我的源码,全网遥遥领先的技术,哈哈哈哈

import torch
import cv2
from  models.name import  class_labels
# 从本地加载自定义的YOLOv5模型
model_path = "D:\IDE\Anaconda3\Lib\YOLOv5\AUO\yolov5-master\\"  # yolov5根目录
weight_path = model_path + "yolov5s.pt"
model = torch.hub.load(model_path, "custom", weight_path, source="local")
# print('测试启动是不是慢')
# imgs = [model_path + '/data/myimages/false2285.bmp']
# results = model(imgs)


# results.print()
# results.show()  # 这两句用于看一下模型检测结果

from flask import Flask, render_template, Response
from camera import VideoCamera

#启动Flask应用

app = Flask(__name__)

@app.route('/')
def index():
    return render_template('index.html')

def gen(camera):
    ti = 0
    while True:
        # frame = camera.get_frame()
        ti =ti+1
        print('生成器启动次数',ti)
        video = cv2.VideoCapture(0)
        success, image = video.read()
        # cv2.imshow('Detection Results', image)
        # cv2.waitKey(2000)  # 等待2秒

        imgs = image
        results = model(imgs)
        # cv2.imshow('Detection Results', imgs)

        # results.print()
        # results.show()  # 这两句用于看一下模型检测结果
        # frame= [ 'false2285.bmp']
        #将检测结果绘制成图片
        for result in results.pred:
            print()
            for det in result:
                x1, y1, x2, y2, confidence, class_id = det[:6]
                class_id = class_id.to('cpu').item()
                print(class_id)
                # 查找类别标签
                if class_id in class_labels:
                    label = f"Class: {class_labels[class_id]}, Confidence: {confidence:.2f}"
                else:
                    label = f"Class: Unknown ({class_id}), Confidence: {confidence:.2f}"

                # 绘制边界框
                color = (0, 255, 0)  # BGR 颜色,这里是绿色
                thickness = 2  # 边界框线条的粗细
                cv2.rectangle(imgs, (int(x1), int(y1)), (int(x2), int(y2)), color, thickness)

                # 添加类别标签
                # label = f"Class: {int(class_id)}, Confidence: {confidence:.2f}"
                font = cv2.FONT_HERSHEY_SIMPLEX
                font_scale = 0.5
                font_thickness = 1
                label_size, _ = cv2.getTextSize(label, font, font_scale, font_thickness)
                class_color = (0, 0, 255)# BGR 颜色,这里是绿色
                cv2.putText(imgs, label, (int(x1), int(y1) - 10), font, font_scale, class_color, font_thickness)
        # cv2.imshow('Detection Results', imgs)
        # cv2.waitKey(2000)  # 等待2秒
        ret, jpeg = cv2.imencode('.jpg', imgs)

        # cv2.imshow('Detection Results', jpeg)
        # cv2.waitKey(2000)  # 等待2秒
        imgs = jpeg.tobytes()
        yield (b'--frame\r\n'
               b'Content-Type: image/jpeg\r\n\r\n' + imgs + b'\r\n\r\n')

@app.route('/video_feed')
def video_feed():

    return Response(gen(VideoCamera()),\
                    mimetype='multipart/x-mixed-replace; boundary=frame')


app.run(host='127.0.0.1', port=5003, debug=True)

现在的问题是显示出来的画面很卡,接下来需要对程序优化,看看是哪里执行的慢了。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值