yolov5训练测试与源码解读

源码地址https://github.com/ultralytics/yolov5
可以通过git clone 或者下载压缩包到本地项目文件夹

关于yolov5其优势以及源码解读可以查看其它优秀文章,这里只是对于初次接触yolov5,且想在本地运行测试的同学借鉴

这里提供运行代码需要避免的问题
1.要求python>=3.7,相对应安装相匹配的opencv-python,要求opencv-python>=4.1.1,可以考虑建一个虚拟环境。
清华镜像opencv-python地址
https://pypi.tuna.tsinghua.edu.cn/simple/opencv-python/
清华镜像opencv-contrib-python地址https://pypi.tuna.tsinghua.edu.cn/simple/opencv-contrib-python/

官网opencv下载地址
清华镜像官网

或者直接利用以下命令在线安装

pip install opencv-python==4.1.1 -i https://pypi.tuna.tsinghua.edu.cn/simple 
pip install opencv-contrib-python==4.1.1 -i https://pypi.tuna.tsinghua.edu.cn/simple

如果以上在线安装慢,可以更换镜像源

国内镜像安装opencv(python)(国内pip镜像源)

2.torch>=1.7与对应的torchvision包,如果需要使用GPU的话,这里要考虑cuda版本,由于现在cuda10.0对应的Torch最高版本只到1.4,所以可以安装cuda10.1和对应的cudnn,相关安装方法可以参考其它 博客。建议安装多个版本的cuda,切换也比较方便。
在这里插入图片描述

这里是torch与torchvision的国内安装镜像网址
https://download.pytorch.org/whl/torch_stable.html

3.其它包,可以先运行以下detect.py文件,缺少什么包,直接安装即可,也可以按照里面的requirements.txt进行安装

python生成requirements.txt环境打包,利用requirements.txt安装Python环境

# Base ----------------------------------------
matplotlib>=3.2.2
numpy>=1.18.5
opencv-python>=4.1.1
Pillow>=7.1.2
PyYAML>=5.3.1
requests>=2.23.0
scipy>=1.4.1  # Google Colab version
torch>=1.7.0
torchvision>=0.8.1
tqdm>=4.41.0

# Logging -------------------------------------
tensorboard>=2.4.1
# wandb

# Plotting ------------------------------------
pandas>=1.1.4
seaborn>=0.11.0

# Export --------------------------------------
# coremltools>=4.1  # CoreML export
# onnx>=1.9.0  # ONNX export
# onnx-simplifier>=0.3.6  # ONNX simplifier
# scikit-learn==0.19.2  # CoreML quantization
# tensorflow>=2.4.1  # TFLite export
# tensorflowjs>=3.9.0  # TF.js export
# openvino-dev  # OpenVINO export

# Extras --------------------------------------
# albumentations>=1.0.3
# Cython  # for pycocotools https://github.com/cocodataset/cocoapi/issues/172
# pycocotools>=2.0  # COCO mAP
# roboflow
thop  # FLOPs computation

配置好环境之后,可以尝试添加自己图片放入data\images中,运行detect.py文件,可以在runs文件夹中得到检测的图片结果
在这里插入图片描述
不过可能结果并不是很准确,因为这依然是参照作者的训练结果,可以尝试制作自己的训练集进行训练,得到的结果就会更准确。

下面是对应的源码解读部分,可以参考,可能不全,不过大部分都有解释
【YOLOV5-5.x 源码解读】general.py

下面是训练自己的数据集

YOLOv5训练自己的数据集

猜你喜欢

转载自blog.csdn.net/m0_47709941/article/details/124696970