1,本文介绍
本文介绍了在 MobileNetV4 的 UIB 模块基础上进行的改进,即创新性地应用 C2f 模块。UIB 模块最早出现在 2024 年 5 月发布的 MobileNetV4 网络中,这是一种为移动设备高度优化的神经网络架构。其主要改进包括:引入了通用反向瓶颈(UIB)结构,以及针对移动加速器优化的全新 Mobile MQA 注意力模块。
关于UIB 的详细介绍可以看论文:[2404.10518] MobileNetV4 - Universal Models for the Mobile Ecosystem
本文将讲解如何将UIB 融合进yolov8
话不多说,上代码!
2, 将UIB融合进yolov8
2.1 步骤一
找到如下的目录'ultralytics/nn/modules',然后在这个目录下创建一个UIB.py文件,文件名字可以根据你自己的习惯起,然后将UIB的核心代码复制进去
import torch.nn as nn
from typing import Optional
import torch
__all__ = ['C2f_UIB']
def make_divisible(
value: float,
divisor: int,
min_value: Optional[float] = None,
round_down_protect: bool = True,
) -> int:
"""
This function is copied from here
"https://github.com/tensorflow/models/blob/master/official/vision/modeling/layers/nn_layers.py"
This is to ensure that all layers have channels that are divisible by 8.
Args:
value: A `float` of original value.
divisor: An `int` of the divisor that need to be checked upon.
min_value: A `float` of minimum value threshold.
round_down_protect: A `bool` indicating whether round down more than 10%
will be allowed.
Returns:
The adjusted value in `int` that is divisible against divisor.
"""
if min_value is None:
min_value = divisor
new_value = max(min_value, int(value + divisor / 2) // divisor * divisor)
# Make sure that round down does not go down by more than 10%.
if round_down_protect and new_value < 0.9 * value:
new_value += divisor
return int(new_value)
def conv_2d(inp, oup, kernel_size=3