YOLOV5:训练自己数据集
YOLOV5:Mosaic数据增强
YOLOV5 :网络结构 yaml 文件参数理解
前言
【个人学习笔记记录,如有错误,欢迎指正】
YOLO-V5 代码仓库地址:https://github.com/ultralytics/yolov5
一、Conv 模块
介绍各个模块前,需要介绍 YOLOV5 中的最基础 Conv 模块。
class Conv(nn.Module):
def __init__(self, c1, c2, k=1, s=1, p=None, g=1, act=True):
# ch_in, ch_out, kernel, stride, padding, groups
super(Conv, self).__init__()
self.conv = nn.Conv2d(c1, c2, k, s, autopad(k, p), groups=g, bias=False)
self.bn = nn.BatchNorm2d(c2)
self.act = nn.Hardswish() if act else nn.Identity()
def forward(self, x):
return self.act(self.bn(self.conv(x)))
def fuseforward(self, x):
return self.act(self.conv(x))
这里的 Conv 模块就是 【卷积】+【BN】+【激活】的组合。激活函数使用 【Hardswish】,【nn.Identity】 简单理解为一个返回输入的占位符。
其中,【autopad(k,p)】就是一个 自动 padding 函数,
def autopad(k, p=None): # kernel, padding
# Pad to 'same'
if p is None:
p = k // 2 if isinstance(k, int) else [x // 2 for x in k] # auto-pad
return p
Conv 就是如下所示操作: