创作背景:自ultralytics公司优化了YOLO系列结构以来,使得模型算法改进变成了有手就行,各种自媒体、专栏涌泉般出现,一群歪瓜裂枣四处搬运,没点创新,无非就是今天看了个卷积赶紧搭积木放进YOLO中,各种P词:自称全网首发!实测涨点明显!全网独家!万字长文!(恶心🤢)拿一篇文献,用AI翻译一下写个专栏赶紧圈钱。为了打击这群歪瓜裂枣们,本号专门把改进对外公开!永久免费学习!无需任何费用!抵制搬运!欢迎转发让更多人看见,避免被专栏坑钱。
抵制歪瓜裂枣搬运,从此做起!
请大家记住本号“YOLO歪瓜裂枣”,想要某个专栏某篇P文,评论区留言即可!
目录
这是作者在文中的实验结果图,对比实验结果图,证明提出的RepGhost模块的有效性。
RepGhost模块
网络模块结构图
其实就跟RepVGG差不多,都是借鉴了RepVGG的设计,RepVGG是清华大学提出的,没记错的话应该是CVPR2021,设计思想据说来源于TensorRT的加速设计……
对比实验部分
这是在ImageNet上的对比实验图,集速度和准确率于一体!
消融实验部分
二、改进YOLOv8 + RepGhost核心代码
C2f_RepGhost结构
首先,在ultralytics/nn/modules文件夹中,创建一个名为C2f_RepGhost.py的文件,并将以下代码添加到其中。
import copy
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
def _make_divisible(v, divisor, min_value=None):
"""
This function is taken from the original tf repo.
It ensures that all layers have a channel number that is divisible by 8 mg
It can be seen here:
https://github.com/tensorflow/models/blob/master/research/slim/nets/mobilenet/mobilenet.py
"""
if min_value is None:
min_value = divisor
new_v = max(min_value, int(v + divisor / 2) // divisor * divisor)
# Make sure that round down does not go down by more than 10%.
if new_v < 0.9 * v:
new_v += divisor
return new_v
def hard_sigmoid(x, inplace: bool = False):
if inplace:
return x.add_(3.0).clamp_(0.0, 6.0).div_(6.0)
else:
return F.relu6(x + 3.0) / 6.0
class SqueezeExcite(nn.Module):
def __init__(
self,
in_chs,
se_ratio=0.25,
reduced_base_chs=None,
act_layer=nn.ReLU,
gate_fn=hard_sigmoid,
divisor=4,
**_,
):
super(SqueezeExcite, self).__init__()
self.gate_fn = gate_fn
reduced_chs = _make_divisible(
(reduced_base_chs or in_chs) * se_ratio, divisor,
)
self.avg_pool = nn.AdaptiveAvgPool2d(1)
self.conv_reduce = nn.Conv2d(in_chs, reduced_