YOLOv9改进,YOLOv9主干网络替换为MobileNetV4(2024独家首发)

69 篇文章 ¥199.90 ¥299.90

在这里插入图片描述

摘要

MobileNetV4具有面向移动设备的通用高效架构设计。其核心是我们引入的通用倒置瓶颈(Universal Inverted Bottleneck,UIB)搜索块,这是一种统一且灵活的结构,融合了倒置瓶颈(IB)、ConvNext、前馈网络(FFN)和一种新型的额外深度卷积(ExtraDW)变体。

通用倒置瓶颈(Universal Inverted Bottleneck,UIB)块,如下图:

在这里插入图片描述
MobileNetV4系列中的三种不同尺寸的卷积模型:小型(Small)、中型(Medium)和大型(Large): [‘MobileNetV4ConvSmall’, ‘MobileNetV4ConvMedium’, ‘MobileNetV4ConvLarge’]
两种混合模型:中型混合模型(Hybrid Medium)和大型混合模型(Hybrid Large): [‘MobileNetV4HybridMedium’, ‘MobileNetV4HybridLarge’]

理论详解可以参考链接:论文地址
代码可在这个链接找到:代码地址

本文在YOLOv9中的主干网络替换成MobileNetV4,代码已经整理好了,跟着文章复制粘贴,即可直接运行


好的,这里是 MobileNetV3_Small 的代码实现: ``` import torch import torch.nn as nn class ConvBNReLU(nn.Sequential): """Convolutional layer with batch normalization and ReLU activation.""" def __init__(self, in_planes, out_planes, kernel_size=3, stride=1, groups=1): padding = (kernel_size - 1) // 2 super(ConvBNReLU, self).__init__( nn.Conv2d(in_planes, out_planes, kernel_size, stride, padding, groups=groups, bias=False), nn.BatchNorm2d(out_planes), nn.ReLU6(inplace=True) ) class InvertedResidual(nn.Module): """Inverted residual block.""" def __init__(self, inp, oup, stride, expand_ratio): super(InvertedResidual, self).__init__() hidden_dim = round(inp * expand_ratio) self.use_res_connect = stride == 1 and inp == oup layers = [] if expand_ratio != 1: # pointwise layers.append(ConvBNReLU(inp, hidden_dim, kernel_size=1)) layers.extend([ # depthwise ConvBNReLU(hidden_dim, hidden_dim, stride=stride, groups=hidden_dim), # pointwise-linear nn.Conv2d(hidden_dim, oup, 1, 1, 0, bias=False), nn.BatchNorm2d(oup), ]) self.conv = nn.Sequential(*layers) def forward(self, x): if self.use_res_connect: return x + self.conv(x) else: return self.conv(x) class MobileNetv3_small(nn.Module): """MobileNetV3_Small model.""" def __init__(self, num_classes=1000, width_mult=1.0): super(MobileNetv3_small, self).__init__() # setting of inverted residual blocks self.cfgs = [ # k, t, c, SE, s [3, 16, 16, 0, 1], [3, 72, 24, 0, 2], [3, 88, 24, 0, 1], [5, 96, 40, 1, 2], [5, 240, 40, 1, 1], [5, 240, 40, 1, 1], [5, 120, 48, 1, 1], [5, 144, 48, 1, 1], [5, 288, 96, 1, 2], [5, 576, 96, 1, 1], [5, 576, 96, 1, 1], ] # building first layer input_channel = int(16 * width_mult) last_channel = int(576 * width_mult) if width_mult > 1.0 else 576 self.features = [ConvBNReLU(3, input_channel, stride=2)] # building inverted residual blocks for k, exp_size, c, se, s in self.cfgs: output_channel = int(c * width_mult) self.features.append(InvertedResidual(input_channel, output_channel, stride=s, expand_ratio=exp_size/ input_channel)) input_channel = output_channel # building last several layers self.features.append(ConvBNReLU(input_channel, last_channel, kernel_size=1)) self.features.append(nn.AdaptiveAvgPool2d((1, 1))) self.features.append(nn.Conv2d(last_channel, 1024, kernel_size=1, stride=1, padding=0, bias=False)) self.features.append(nn.Hardswish()) self.features.append(nn.Conv2d(1024, num_classes, kernel_size=1, stride=1, padding=0, bias=True)) self.features = nn.Sequential(*self.features) def forward(self, x): x = self.features(x) x = x.view(x.size(0), -1) return x ``` 这个实现中包含了 MobileNetV3_Small 模型中使用的 Inverted Residual Block 和 ConvBNReLU 等基本组件。同时,在实现模型的过程中,作者还考虑到了模型的可配置性,可以通过调整宽度因子 `width_mult` 来控制模型的宽度。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

挂科边缘

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值