YOLO-V5训练自己的数据集
一、环境配置
- github上下载 yolo-5 项目代码(个人觉得大佬的代码写的太香了!)
- 按照项目中的 requirements 安装相关包,这里需要注意的一点是 由于我个人本机是3090的卡,然后cuda是11.4的版本,当我直接按照requirements中安装 torch 和 torchvision 出现与cuda版本兼容的问题(可能是我电脑的原因),于是乎,我就采取下面方式安装 torch 和torchvision。
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
二、训练模型
- 数据预处理。这里需要注意的是,如果使用coco格式的话,GT的格式就是 [ label, x_center, y_center, width, height ],其中中心点与宽高都是归一化之后的结果,然后类别数是从 0 开始。
- 更改配置文件。主要有两个:./data/coco128.yaml 以及 ./models/yolov5s.py,前一个配置文件中需要更改类别数量、类名以及训练数据的位置,后一个文件只需要更改类别数量即可。
三、转onnx
- 如果有需要转onnx,遇到过一个bug,
export failure: Exporting the operator silu to ONNX opset version 12 is not supported. Please open a bug to request ONNX export support for the missing operator.
这是因为onnx与pytorch一些方法不兼容导致的,onnx不支持silu,把**函数换一种写法即可。解决方式如下:~/miniconda3/envs/yolov5/lib/python3.8/site-packages/torch/nn/modules
(这里路径因人而异,我是建的虚拟环境)找到该路径下的activation.py
脚本,然后按照下面的方式进行修改即可。
class SiLU(Module):
__constants__ = ['inplace']
inplace: bool
def __init__(self, inplace: bool = False):
super(SiLU, self).__init__()
self.inplace = inplace
def forward(self, input: Tensor) -> Tensor:
# ------------------------------------- #
# 把F.silu替换掉,修改后如下
return input * torch.sigmoid(input)
#原来的代码
return F.silu(input, inplace=self.inplace)
另:本团队由数名top高校博硕士组成,目前正在做的项目有基于深度学习技术、三维激光点云、SLAM等在安防、自动驾驶领域的感知算法研究和落地以及工业生产智能化改造。
有项目意向的可交流沟通
QQ:812108841