yolo系列的网络作为单阶段目标检测网络中的佼佼者,在目标检测方面发挥着很大的作用,而yolov5是其中较好的一代网络,yolov8是其中最新的一代网络。但是作为我们学习和使用来说,原始的yolov5或者yolov8网络并不一定就是最合适的,基于此,在yolov5的基础上,针对主干网络进行了替换,替换成EfficientNetv2网络,yolov8的替换方式也是类似的。主要步骤如下:
首先,我们需要在common.py文件中添加如下代码段:(建议添加在common.py文件的最后
class stem(nn.Module):
def __init__(self, c1, c2, kernel_size=3, stride=1, groups=1):
super(stem, self).__init__()
padding = (kernel_size-1) // 2
self.conv = nn.Conv2d(c1, c2, kernel_size, stride, padding=padding, groups=groups, bias=False)
self.bn = nn.BatchNorm2d(c2, eps=1e-3, momentum=0.1)
self.act = nn.SiLU(True)
def forward(self, x):
#print(x.shape)
x = self.conv(x)
x = self.bn(x)
x = self.act(x)
return x
de